1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Refactoring of hoverText from objects:

- removed hoverText field
- split getHoverText() method into 3:
- - getObjectName() for generic name
- - getHoverText(Player) for player-specific text
- - getHoverText(Hero) for hero-specific strings
This commit is contained in:
Ivan Savenko 2014-06-24 20:39:36 +03:00
parent ad632d1e8a
commit a0689fa377
37 changed files with 212 additions and 251 deletions

View File

@ -66,7 +66,7 @@ std::string Goals::AbstractGoal::name() const //TODO: virtualize
{ {
auto obj = cb->getObjInstance(ObjectInstanceID(objid)); auto obj = cb->getObjInstance(ObjectInstanceID(objid));
if (obj) if (obj)
desc = "GET OBJ " + obj->getHoverText(); desc = "GET OBJ " + obj->getObjectName();
} }
case FIND_OBJ: case FIND_OBJ:
desc = "FIND OBJ " + boost::lexical_cast<std::string>(objid); desc = "FIND OBJ " + boost::lexical_cast<std::string>(objid);
@ -75,7 +75,7 @@ std::string Goals::AbstractGoal::name() const //TODO: virtualize
{ {
auto obj = cb->getObjInstance(ObjectInstanceID(objid)); auto obj = cb->getObjInstance(ObjectInstanceID(objid));
if (obj) if (obj)
desc = "VISIT HERO " + obj->getHoverText(); desc = "VISIT HERO " + obj->getObjectName();
} }
break; break;
case GET_ART_TYPE: case GET_ART_TYPE:
@ -493,7 +493,7 @@ TGoalVec ClearWayTo::getAllPossibleSubgoals()
if (topObj->ID == Obj::HERO && cb->getPlayerRelations(h->tempOwner, topObj->tempOwner) != PlayerRelations::ENEMIES) if (topObj->ID == Obj::HERO && cb->getPlayerRelations(h->tempOwner, topObj->tempOwner) != PlayerRelations::ENEMIES)
if (topObj != hero.get(true)) //the hero we want to free if (topObj != hero.get(true)) //the hero we want to free
logAi->errorStream() << boost::format("%s stands in the way of %s") % topObj->getHoverText() % h->getHoverText(); logAi->errorStream() << boost::format("%s stands in the way of %s") % topObj->getObjectName() % h->getObjectName();
if (topObj->ID == Obj::QUEST_GUARD || topObj->ID == Obj::BORDERGUARD) if (topObj->ID == Obj::QUEST_GUARD || topObj->ID == Obj::BORDERGUARD)
{ {
if (shouldVisit(h, topObj)) if (shouldVisit(h, topObj))

View File

@ -81,7 +81,7 @@ struct ObjInfo
ObjInfo(){} ObjInfo(){}
ObjInfo(const CGObjectInstance *obj): ObjInfo(const CGObjectInstance *obj):
pos(obj->pos), pos(obj->pos),
name(obj->getHoverText()) name(obj->getObjectName())
{ {
} }
}; };
@ -241,7 +241,7 @@ void VCAI::artifactDisassembled(const ArtifactLocation &al)
void VCAI::heroVisit(const CGHeroInstance *visitor, const CGObjectInstance *visitedObj, bool start) void VCAI::heroVisit(const CGHeroInstance *visitor, const CGObjectInstance *visitedObj, bool start)
{ {
LOG_TRACE_PARAMS(logAi, "start '%i'; obj '%s'", start % (visitedObj ? visitedObj->hoverName : std::string("n/a"))); LOG_TRACE_PARAMS(logAi, "start '%i'; obj '%s'", start % (visitedObj ? visitedObj->getObjectName() : std::string("n/a")));
NET_EVENT_HANDLER; NET_EVENT_HANDLER;
if(start) if(start)
{ {
@ -780,13 +780,13 @@ void VCAI::makeTurnInternal()
bool VCAI::goVisitObj(const CGObjectInstance * obj, HeroPtr h) bool VCAI::goVisitObj(const CGObjectInstance * obj, HeroPtr h)
{ {
int3 dst = obj->visitablePos(); int3 dst = obj->visitablePos();
logAi->debugStream() << boost::format("%s will try to visit %s at (%s)") % h->name % obj->getHoverText() % strFromInt3(dst); logAi->debugStream() << boost::format("%s will try to visit %s at (%s)") % h->name % obj->getObjectName() % strFromInt3(dst);
return moveHeroToTile(dst, h); return moveHeroToTile(dst, h);
} }
void VCAI::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h) void VCAI::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h)
{ {
LOG_TRACE_PARAMS(logAi, "Hero %s and object %s at %s", h->name % obj->getHoverText() % obj->pos); LOG_TRACE_PARAMS(logAi, "Hero %s and object %s at %s", h->name % obj->getObjectName() % obj->pos);
switch (obj->ID) switch (obj->ID)
{ {
case Obj::CREATURE_GENERATOR1: case Obj::CREATURE_GENERATOR1:
@ -1434,7 +1434,7 @@ void VCAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int
assert(playerID > PlayerColor::PLAYER_LIMIT || status.getBattle() == UPCOMING_BATTLE); assert(playerID > PlayerColor::PLAYER_LIMIT || status.getBattle() == UPCOMING_BATTLE);
status.setBattle(ONGOING_BATTLE); status.setBattle(ONGOING_BATTLE);
const CGObjectInstance *presumedEnemy = backOrNull(cb->getVisitableObjs(tile)); //may be nullptr in some very are cases -> eg. visited monolith and fighting with an enemy at the FoW covered exit const CGObjectInstance *presumedEnemy = backOrNull(cb->getVisitableObjs(tile)); //may be nullptr in some very are cases -> eg. visited monolith and fighting with an enemy at the FoW covered exit
battlename = boost::str(boost::format("Starting battle of %s attacking %s at %s") % (hero1 ? hero1->name : "a army") % (presumedEnemy ? presumedEnemy->hoverName : "unknown enemy") % tile); battlename = boost::str(boost::format("Starting battle of %s attacking %s at %s") % (hero1 ? hero1->name : "a army") % (presumedEnemy ? presumedEnemy->getObjectName() : "unknown enemy") % tile);
CAdventureAI::battleStart(army1, army2, tile, hero1, hero2, side); CAdventureAI::battleStart(army1, army2, tile, hero1, hero2, side);
} }
@ -1468,7 +1468,7 @@ void VCAI::reserveObject(HeroPtr h, const CGObjectInstance *obj)
{ {
reservedObjs.insert(obj); reservedObjs.insert(obj);
reservedHeroesMap[h].insert(obj); reservedHeroesMap[h].insert(obj);
logAi->debugStream() << "reserved object id=" << obj->id << "; address=" << (intptr_t)obj << "; name=" << obj->getHoverText(); logAi->debugStream() << "reserved object id=" << obj->id << "; address=" << (intptr_t)obj << "; name=" << obj->getObjectName();
} }
void VCAI::unreserveObject(HeroPtr h, const CGObjectInstance *obj) void VCAI::unreserveObject(HeroPtr h, const CGObjectInstance *obj)

View File

@ -317,7 +317,7 @@ void CTownList::CTownItem::showTooltip()
std::string CTownList::CTownItem::getHoverText() std::string CTownList::CTownItem::getHoverText()
{ {
return town->hoverName; return town->getObjectName();
} }
CTownList::CTownList(int size, Point position, std::string btnUp, std::string btnDown): CTownList::CTownList(int size, Point position, std::string btnUp, std::string btnDown):

View File

@ -1234,10 +1234,9 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
} }
const CGObjectInstance *objAtTile = getBlockingObject(mapPos); const CGObjectInstance *objAtTile = getBlockingObject(mapPos);
//std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(mapPos);
if (objAtTile) if (objAtTile)
{ {
std::string text = objAtTile->getHoverText(); std::string text = curHero() ? objAtTile->getHoverText(curHero()) : objAtTile->getHoverText(LOCPLINT->playerID);
boost::replace_all(text,"\n"," "); boost::replace_all(text,"\n"," ");
statusbar.setText(text); statusbar.setText(text);
} }

View File

@ -500,7 +500,7 @@ void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInst
OwnedObjectInfo &info = visibleObjects[object->subID]; OwnedObjectInfo &info = visibleObjects[object->subID];
if (info.count++ == 0) if (info.count++ == 0)
{ {
info.hoverText = object->getHoverText(); info.hoverText = object->getObjectName();
info.imageID = object->subID; info.imageID = object->subID;
} }
} }
@ -511,7 +511,7 @@ void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInst
OwnedObjectInfo &info = visibleObjects[iter->second]; OwnedObjectInfo &info = visibleObjects[iter->second];
if (info.count++ == 0) if (info.count++ == 0)
{ {
info.hoverText = object->hoverName; info.hoverText = object->getObjectName();
info.imageID = iter->second; info.imageID = iter->second;
} }
} }

View File

@ -589,7 +589,7 @@ void processCommand(const std::string &message)
} }
else if(cn == "bonuses") else if(cn == "bonuses")
{ {
std::cout << "Bonuses of " << adventureInt->selection->getHoverText() << std::endl std::cout << "Bonuses of " << adventureInt->selection->getObjectName() << std::endl
<< adventureInt->selection->getBonusList() << std::endl; << adventureInt->selection->getBonusList() << std::endl;
std::cout << "\nInherited bonuses:\n"; std::cout << "\nInherited bonuses:\n";

View File

@ -140,7 +140,7 @@ void CQuestLog::init()
MetaString text; MetaString text;
quests[i].quest->getRolloverText (text, false); quests[i].quest->getRolloverText (text, false);
if (quests[i].obj) if (quests[i].obj)
text.addReplacement (quests[i].obj->getHoverText()); //get name of the object text.addReplacement (quests[i].obj->getObjectName()); //get name of the object
CQuestLabel * label = new CQuestLabel (Rect(28, 199 + i * 24, 172,30), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString()); CQuestLabel * label = new CQuestLabel (Rect(28, 199 + i * 24, 172,30), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
label->callback = boost::bind(&CQuestLog::selectQuest, this, i); label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
labels.push_back(label); labels.push_back(label);

View File

@ -170,7 +170,6 @@ public:
bool removeObject(const CGObjectInstance * obj) override {return false;}; bool removeObject(const CGObjectInstance * obj) override {return false;};
void setBlockVis(ObjectInstanceID objid, bool bv) override {}; void setBlockVis(ObjectInstanceID objid, bool bv) override {};
void setOwner(const CGObjectInstance * obj, PlayerColor owner) override {}; void setOwner(const CGObjectInstance * obj, PlayerColor owner) override {};
void setHoverName(const CGObjectInstance * obj, MetaString * name) override {};
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) override {}; void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) override {};
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override {}; void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override {};

View File

@ -1848,7 +1848,7 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> &_items, CIntObject
items.reserve(_items.size()); items.reserve(_items.size());
for(int id : _items) for(int id : _items)
{ {
items.push_back(std::make_pair(id, CGI->mh->map->objects[id]->hoverName)); items.push_back(std::make_pair(id, CGI->mh->map->objects[id]->getObjectName()));
} }
init(titlePic, _title, _descr); init(titlePic, _title, _descr);
@ -2614,7 +2614,7 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan
break; case Obj::BLACK_MARKET: title = CGI->generaltexth->allTexts[349]; break; case Obj::BLACK_MARKET: title = CGI->generaltexth->allTexts[349];
break; case Obj::TRADING_POST: title = CGI->generaltexth->allTexts[159]; break; case Obj::TRADING_POST: title = CGI->generaltexth->allTexts[159];
break; case Obj::TRADING_POST_SNOW: title = CGI->generaltexth->allTexts[159]; break; case Obj::TRADING_POST_SNOW: title = CGI->generaltexth->allTexts[159];
break; default: title = market->o->getHoverText(); break; default: title = market->o->getObjectName();
} }
} }
@ -4571,7 +4571,7 @@ void CHeroArea::clickRight(tribool down, bool previousState)
void CHeroArea::hover(bool on) void CHeroArea::hover(bool on)
{ {
if (on && hero) if (on && hero)
GH.statusbar->setText(hero->hoverName); GH.statusbar->setText(hero->getObjectName());
else else
GH.statusbar->clear(); GH.statusbar->clear();
} }
@ -5634,7 +5634,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn
slotsCount=7; slotsCount=7;
resources = CDefHandler::giveDefEss("SMALRES.DEF"); resources = CDefHandler::giveDefEss("SMALRES.DEF");
new CLabel(325, 32, FONT_BIG, CENTER, Colors::YELLOW, fort->hoverName);//Hill Fort new CLabel(325, 32, FONT_BIG, CENTER, Colors::YELLOW, fort->getObjectName());//Hill Fort
heroPic = new CHeroArea(30, 60, hero); heroPic = new CHeroArea(30, 60, hero);
@ -6181,7 +6181,7 @@ void CRClickPopup::createAndPush(const CGObjectInstance *obj, const Point &p, EA
if(iWin) if(iWin)
GH.pushInt(iWin); GH.pushInt(iWin);
else else
CRClickPopup::createAndPush(obj->getHoverText()); CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->playerID));
} }
CRClickPopup::CRClickPopup() CRClickPopup::CRClickPopup()

View File

@ -1054,7 +1054,7 @@ void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terN
{ {
if(elem.first->ID == Obj::HOLE) //Hole if(elem.first->ID == Obj::HOLE) //Hole
{ {
out = elem.first->hoverName; out = elem.first->getObjectName();
return; return;
} }
} }

View File

@ -108,7 +108,6 @@ public:
std::pair<SDL_Surface *, bool> getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector<ui8> > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary std::pair<SDL_Surface *, bool> getVisBitmap(const int3 & pos, const std::vector< std::vector< std::vector<ui8> > > & visibilityMap) const; //returns appropriate bitmap and info if alpha blitting is necessary
ui8 getPhaseShift(const CGObjectInstance *object) const; ui8 getPhaseShift(const CGObjectInstance *object) const;
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map

View File

@ -224,6 +224,7 @@ ui64 CCreatureSet::getPower (SlotID slot) const
{ {
return getStack(slot).getPower(); return getStack(slot).getPower();
} }
std::string CCreatureSet::getRoughAmount (SlotID slot) const std::string CCreatureSet::getRoughAmount (SlotID slot) const
{ {
int quantity = CCreature::getQuantityID(getStackCount(slot)); int quantity = CCreature::getQuantityID(getStackCount(slot));

View File

@ -260,18 +260,6 @@ int CGameInfoCallback::getDate(Date::EDateType mode) const
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->getDate(mode); return gs->getDate(mode);
} }
std::vector < std::string > CGameInfoCallback::getObjDescriptions(int3 pos) const
{
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
std::vector<std::string> ret;
const TerrainTile *t = getTile(pos);
ERROR_RET_VAL_IF(!t, "Not a valid tile given!", ret);
for(const CGObjectInstance * obj : t->blockingObjects)
ret.push_back(obj->getHoverText());
return ret;
}
bool CGameInfoCallback::isVisible(int3 pos, boost::optional<PlayerColor> Player) const bool CGameInfoCallback::isVisible(int3 pos, boost::optional<PlayerColor> Player) const
{ {

View File

@ -83,7 +83,6 @@ public:
std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true)const; std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true)const;
std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const; std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
const CGObjectInstance * getTopObj (int3 pos) const; const CGObjectInstance * getTopObj (int3 pos) const;
std::vector <std::string > getObjDescriptions(int3 pos)const; //returns descriptions of objects at pos in order from the lowest to the highest
PlayerColor getOwner(ObjectInstanceID heroID) const; PlayerColor getOwner(ObjectInstanceID heroID) const;
const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed) const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed)

View File

@ -1053,7 +1053,6 @@ void CGameState::randomizeMapObjects()
if(!obj) continue; if(!obj) continue;
randomizeObject(obj); randomizeObject(obj);
obj->hoverName = VLC->objtypeh->getObjectName(obj->ID);
//handle Favouring Winds - mark tiles under it //handle Favouring Winds - mark tiles under it
if(obj->ID == Obj::FAVORABLE_WINDS) if(obj->ID == Obj::FAVORABLE_WINDS)
@ -2980,7 +2979,7 @@ void InfoAboutArmy::initFromArmy(const CArmedInstance *Army, bool detailed)
{ {
army = ArmyDescriptor(Army, detailed); army = ArmyDescriptor(Army, detailed);
owner = Army->tempOwner; owner = Army->tempOwner;
name = Army->getHoverText(); name = Army->getObjectName();
} }
void InfoAboutHero::assign(const InfoAboutHero & iah) void InfoAboutHero::assign(const InfoAboutHero & iah)

View File

@ -48,7 +48,6 @@ public:
virtual bool removeObject(const CGObjectInstance * obj)=0; virtual bool removeObject(const CGObjectInstance * obj)=0;
virtual void setBlockVis(ObjectInstanceID objid, bool bv)=0; virtual void setBlockVis(ObjectInstanceID objid, bool bv)=0;
virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0; virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
virtual void setHoverName(const CGObjectInstance * obj, MetaString * name)=0;
virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0; virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0; virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;
virtual void showBlockingDialog(BlockingDialog *iw) =0; virtual void showBlockingDialog(BlockingDialog *iw) =0;

View File

@ -1045,21 +1045,6 @@ struct SetObjectProperty : public CPackForClient//1001
} }
}; };
struct SetHoverName : public CPackForClient//1002
{
DLL_LINKAGE void applyGs(CGameState *gs);
ObjectInstanceID id;
MetaString name;
SetHoverName(){type = 1002;}
SetHoverName(ObjectInstanceID ID, MetaString& Name):id(ID),name(Name){type = 1002;}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & name;
}
};
struct ChangeObjectVisitors : public CPackForClient // 1003 struct ChangeObjectVisitors : public CPackForClient // 1003
{ {
enum VisitMode enum VisitMode

View File

@ -302,7 +302,7 @@ DLL_LINKAGE void RemoveObject::applyGs( CGameState *gs )
{ {
CGObjectInstance *obj = gs->getObjInstance(id); CGObjectInstance *obj = gs->getObjInstance(id);
logGlobal->debugStream() << "removing object id=" << id << "; address=" << (intptr_t)obj << "; name=" << obj->getHoverText(); logGlobal->debugStream() << "removing object id=" << id << "; address=" << (intptr_t)obj << "; name=" << obj->getObjectName();
//unblock tiles //unblock tiles
gs->map->removeBlockVisTiles(obj); gs->map->removeBlockVisTiles(obj);
@ -608,14 +608,13 @@ DLL_LINKAGE void NewObject::applyGs( CGameState *gs )
const TerrainTile &t = gs->map->getTile(pos); const TerrainTile &t = gs->map->getTile(pos);
o->appearance = VLC->objtypeh->getHandlerFor(o->ID, o->subID)->getTemplates(t.terType).front(); o->appearance = VLC->objtypeh->getHandlerFor(o->ID, o->subID)->getTemplates(t.terType).front();
id = o->id = ObjectInstanceID(gs->map->objects.size()); id = o->id = ObjectInstanceID(gs->map->objects.size());
o->hoverName = VLC->objtypeh->getObjectName(ID);
gs->map->objects.push_back(o); gs->map->objects.push_back(o);
gs->map->addBlockVisTiles(o); gs->map->addBlockVisTiles(o);
o->initObj(); o->initObj();
gs->map->calculateGuardingGreaturePositions(); gs->map->calculateGuardingGreaturePositions();
logGlobal->debugStream() << "added object id=" << id << "; address=" << (intptr_t)o << "; name=" << o->getHoverText(); logGlobal->debugStream() << "added object id=" << id << "; address=" << (intptr_t)o << "; name=" << o->getObjectName();
} }
DLL_LINKAGE void NewArtifact::applyGs( CGameState *gs ) DLL_LINKAGE void NewArtifact::applyGs( CGameState *gs )
@ -1012,11 +1011,6 @@ DLL_LINKAGE void SetObjectProperty::applyGs( CGameState *gs )
} }
} }
DLL_LINKAGE void SetHoverName::applyGs( CGameState *gs )
{
name.toString(gs->getObj(id)->hoverName);
}
DLL_LINKAGE void HeroLevelUp::applyGs( CGameState *gs ) DLL_LINKAGE void HeroLevelUp::applyGs( CGameState *gs )
{ {
CGHeroInstance * h = gs->getHero(hero->id); CGHeroInstance * h = gs->getHero(hero->id);

View File

@ -41,11 +41,12 @@ void CBank::initObj()
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, cb->gameState()->getRandomGenerator()); VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, cb->gameState()->getRandomGenerator());
} }
const std::string & CBank::getHoverText() const std::string CBank::getHoverText(PlayerColor player) const
{ {
// TODO: USE BANK_SPECIFIC NAMES
// TODO: record visited players
bool visited = (bc == nullptr); bool visited = (bc == nullptr);
hoverName = visitedTxt(visited); // FIXME: USE BANK_SPECIFIC NAMES return visitedTxt(visited);
return hoverName;
} }
void CBank::setConfig(const BankConfig & config) void CBank::setConfig(const BankConfig & config)

View File

@ -32,7 +32,7 @@ public:
void setConfig(const BankConfig & bc); void setConfig(const BankConfig & bc);
void initObj() override; void initObj() override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
void newTurn() const override; void newTurn() const override;
bool wasVisited (PlayerColor player) const override; bool wasVisited (PlayerColor player) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;

View File

@ -418,19 +418,17 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
} }
} }
const std::string & CGHeroInstance::getHoverText() const std::string CGHeroInstance::getObjectName() const
{ {
if(ID != Obj::PRISON) if(ID != Obj::PRISON)
{ {
hoverName = VLC->generaltexth->allTexts[15]; std::string hoverName = VLC->generaltexth->allTexts[15];
boost::algorithm::replace_first(hoverName,"%s",name); boost::algorithm::replace_first(hoverName,"%s",name);
boost::algorithm::replace_first(hoverName,"%s", type->heroClass->name); boost::algorithm::replace_first(hoverName,"%s", type->heroClass->name);
return hoverName; return hoverName;
} }
else else
hoverName = VLC->objtypeh->getObjectName(ID); return CGObjectInstance::getObjectName();
return hoverName;
} }
const std::string & CGHeroInstance::getBiography() const const std::string & CGHeroInstance::getBiography() const

View File

@ -205,7 +205,7 @@ public:
void initObj() override; void initObj() override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
const std::string & getHoverText() const override; std::string getObjectName() const override;
protected: protected:
void setPropertyDer(ui8 what, ui32 val) override;//synchr void setPropertyDer(ui8 what, ui32 val) override;//synchr

View File

@ -55,7 +55,7 @@ void CGDwelling::initObj()
} }
} }
void CGDwelling::setProperty(ui8 what, ui32 val) void CGDwelling::setPropertyDer(ui8 what, ui32 val)
{ {
switch (what) switch (what)
{ {
@ -77,8 +77,8 @@ void CGDwelling::setProperty(ui8 what, ui32 val)
creatures[0].second[0] = CreatureID(val); creatures[0].second[0] = CreatureID(val);
break; break;
} }
CGObjectInstance::setProperty(what,val);
} }
void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
{ {
if(ID == Obj::REFUGEE_CAMP && !creatures[0].first) //Refugee Camp, no available cres if(ID == Obj::REFUGEE_CAMP && !creatures[0].first) //Refugee Camp, no available cres
@ -523,11 +523,15 @@ void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
cb->stopHeroVisitCastle(this, h); cb->stopHeroVisitCastle(this, h);
} }
std::string CGTownInstance::getObjectName() const
{
return name + ", " + town->faction->name;
}
void CGTownInstance::initObj() void CGTownInstance::initObj()
///initialize town structures ///initialize town structures
{ {
blockVisit = true; blockVisit = true;
hoverName = name + ", " + town->faction->name;
if (subID == ETownType::DUNGEON) if (subID == ETownType::DUNGEON)
creatures.resize(GameConstants::CREATURES_PER_TOWN+1);//extra dwelling for Dungeon creatures.resize(GameConstants::CREATURES_PER_TOWN+1);//extra dwelling for Dungeon

View File

@ -59,7 +59,7 @@ public:
void initObj() override; void initObj() override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void newTurn() const override; void newTurn() const override;
void setProperty(ui8 what, ui32 val) override; void setPropertyDer(ui8 what, ui32 val) override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
@ -243,6 +243,7 @@ public:
void onHeroLeave(const CGHeroInstance * h) const override; void onHeroLeave(const CGHeroInstance * h) const override;
void initObj() override; void initObj() override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
std::string getObjectName() const override;
protected: protected:
void setPropertyDer(ui8 what, ui32 val) override; void setPropertyDer(ui8 what, ui32 val) override;
}; };

View File

@ -53,12 +53,6 @@ static void showInfoDialog(const CGHeroInstance* h, const ui32 txtID, const ui16
showInfoDialog(playerID,txtID,soundID); showInfoDialog(playerID,txtID,soundID);
} }
static std::string & visitedTxt(const bool visited)
{
int id = visited ? 352 : 353;
return VLC->generaltexth->allTexts[id];
}
///IObjectInterface ///IObjectInterface
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
{} {}
@ -139,10 +133,6 @@ CGObjectInstance::~CGObjectInstance()
{ {
} }
const std::string & CGObjectInstance::getHoverText() const
{
return hoverName;
}
void CGObjectInstance::setOwner(PlayerColor ow) void CGObjectInstance::setOwner(PlayerColor ow)
{ {
tempOwner = ow; tempOwner = ow;
@ -223,6 +213,8 @@ void CGObjectInstance::initObj()
void CGObjectInstance::setProperty( ui8 what, ui32 val ) void CGObjectInstance::setProperty( ui8 what, ui32 val )
{ {
setPropertyDer(what, val); // call this before any actual changes (needed at least for dwellings)
switch(what) switch(what)
{ {
case ObjProperty::OWNER: case ObjProperty::OWNER:
@ -238,7 +230,6 @@ void CGObjectInstance::setProperty( ui8 what, ui32 val )
subID = val; subID = val;
break; break;
} }
setPropertyDer(what, val);
} }
void CGObjectInstance::setPropertyDer( ui8 what, ui32 val ) void CGObjectInstance::setPropertyDer( ui8 what, ui32 val )
@ -265,17 +256,6 @@ int3 CGObjectInstance::getVisitableOffset() const
return int3(0,0,0); return int3(0,0,0);
} }
void CGObjectInstance::getNameVis( std::string &hname ) const
{
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
hname = VLC->objtypeh->getObjectName(ID);
if(h)
{
const bool visited = h->hasBonusFrom(Bonus::OBJECT,ID);
hname + " " + visitedTxt(visited);
}
}
void CGObjectInstance::giveDummyBonus(ObjectInstanceID heroID, ui8 duration) const void CGObjectInstance::giveDummyBonus(ObjectInstanceID heroID, ui8 duration) const
{ {
GiveBonus gbonus; GiveBonus gbonus;
@ -287,6 +267,21 @@ void CGObjectInstance::giveDummyBonus(ObjectInstanceID heroID, ui8 duration) con
cb->giveHeroBonus(&gbonus); cb->giveHeroBonus(&gbonus);
} }
std::string CGObjectInstance::getObjectName() const
{
return VLC->objtypeh->getObjectName(ID);
}
std::string CGObjectInstance::getHoverText(PlayerColor player) const
{
return getObjectName();
}
std::string CGObjectInstance::getHoverText(const CGHeroInstance * hero) const
{
return getHoverText(hero->tempOwner);
}
void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const
{ {
switch(ID) switch(ID)

View File

@ -95,8 +95,6 @@ public:
class DLL_LINKAGE CGObjectInstance : public IObjectInterface class DLL_LINKAGE CGObjectInstance : public IObjectInterface
{ {
public: public:
mutable std::string hoverName;
/// Position of bottom-right corner of object on map /// Position of bottom-right corner of object on map
int3 pos; int3 pos;
/// Type of object, e.g. town, hero, creature. /// Type of object, e.g. town, hero, creature.
@ -141,33 +139,37 @@ public:
virtual int getSightRadious() const; virtual int getSightRadious() const;
/// returns (x,y,0) offset to a visitable tile of object /// returns (x,y,0) offset to a visitable tile of object
virtual int3 getVisitableOffset() const; virtual int3 getVisitableOffset() const;
/// returns text visible in status bar
/// TODO: should accept selected hero as parameter and possibly - moved into object handler
virtual const std::string & getHoverText() const;
/// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman") /// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman")
virtual void setType(si32 ID, si32 subID); virtual void setType(si32 ID, si32 subID);
/// returns text visible in status bar with specific hero/player active.
/// Returns generic name of object, without any player-specific info
virtual std::string getObjectName() const;
/// Returns hover name for situation when there are no selected heroes. Default = object name
virtual std::string getHoverText(PlayerColor player) const;
/// Returns hero-specific hover name, including visited/not visited info. Default = player-specific name
virtual std::string getHoverText(const CGHeroInstance * hero) const;
/** OVERRIDES OF IObjectInterface **/ /** OVERRIDES OF IObjectInterface **/
void initObj() override; void initObj() override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
/// method for synchronous update. Note: For new properties classes should override setPropertyDer instead /// method for synchronous update. Note: For new properties classes should override setPropertyDer instead
void setProperty(ui8 what, ui32 val) override; void setProperty(ui8 what, ui32 val) override final;
//friend class CGameHandler; //friend class CGameHandler;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & hoverName & pos & ID & subID & id & tempOwner & blockVisit & appearance; h & pos & ID & subID & id & tempOwner & blockVisit & appearance;
//definfo is handled by map serializer //definfo is handled by map serializer
} }
protected: protected:
/// virtual method that allows synchronously update object state on server and all clients /// virtual method that allows synchronously update object state on server and all clients
virtual void setPropertyDer(ui8 what, ui32 val); virtual void setPropertyDer(ui8 what, ui32 val);
/// Adds (visited) text if selected hero has visited object
/// TODO: remove?
void getNameVis(std::string &hname) const;
/// Gives dummy bonus from this object to hero. Can be used to track visited state /// Gives dummy bonus from this object to hero. Can be used to track visited state
void giveDummyBonus(ObjectInstanceID heroID, ui8 duration = Bonus::ONE_DAY) const; void giveDummyBonus(ObjectInstanceID heroID, ui8 duration = Bonus::ONE_DAY) const;
}; };

View File

@ -434,25 +434,15 @@ void CGSeerHut::getRolloverText (MetaString &text, bool onHover) const
text.addReplacement(seerName); text.addReplacement(seerName);
} }
const std::string & CGSeerHut::getHoverText() const std::string CGSeerHut::getHoverText(PlayerColor player) const
{ {
switch (ID) std::string hoverName = getObjectName();
if (ID == Obj::SEER_HUT && quest->progress != CQuest::NOT_ACTIVE)
{ {
case Obj::SEER_HUT: hoverName = VLC->generaltexth->allTexts[347];
if (quest->progress != CQuest::NOT_ACTIVE) boost::algorithm::replace_first(hoverName,"%s", seerName);
{
hoverName = VLC->generaltexth->allTexts[347];
boost::algorithm::replace_first(hoverName,"%s", seerName);
}
else //just seer hut
hoverName = VLC->objtypeh->getObjectName(ID);
break;
case Obj::QUEST_GUARD:
hoverName = VLC->objtypeh->getObjectName(ID);
break;
default:
logGlobal->debugStream() << "unrecognized quest object";
} }
if (quest->progress & quest->missionType) //rollover when the quest is active if (quest->progress & quest->missionType) //rollover when the quest is active
{ {
MetaString ms; MetaString ms;
@ -757,19 +747,14 @@ bool CGKeys::wasMyColorVisited (PlayerColor player) const
return false; return false;
} }
const std::string& CGKeys::getHoverText() const std::string CGKeys::getHoverText(PlayerColor player) const
{ {
bool visited = wasMyColorVisited (cb->getLocalPlayer()); return getObjectName() + "\n" + visitedTxt(wasMyColorVisited(player));
hoverName = getName() + "\n" + visitedTxt(visited);
return hoverName;
} }
std::string CGKeys::getObjectName() const
const std::string CGKeys::getName() const
{ {
std::string name; return VLC->generaltexth->tentColors[subID] + " " + CGObjectInstance::getObjectName();
name = VLC->generaltexth->tentColors[subID] + " " + VLC->objtypeh->getObjectName(ID);
return name;
} }
bool CGKeymasterTent::wasVisited (PlayerColor player) const bool CGKeymasterTent::wasVisited (PlayerColor player) const

View File

@ -95,7 +95,7 @@ public:
CGSeerHut() : IQuestObject(){}; CGSeerHut() : IQuestObject(){};
void initObj() override; void initObj() override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
void newTurn() const override; void newTurn() const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
@ -138,10 +138,10 @@ public:
static std::map <PlayerColor, std::set <ui8> > playerKeyMap; //[players][keysowned] static std::map <PlayerColor, std::set <ui8> > playerKeyMap; //[players][keysowned]
//SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
const std::string getName() const; //depending on color
bool wasMyColorVisited (PlayerColor player) const; bool wasMyColorVisited (PlayerColor player) const;
const std::string & getHoverText() const override; std::string getObjectName() const override; //depending on color
std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -375,19 +375,18 @@ static std::string & visitedTxt(const bool visited)
return VLC->generaltexth->allTexts[id]; return VLC->generaltexth->allTexts[id];
} }
const std::string & CRewardableObject::getHoverText() const std::string CRewardableObject::getHoverText(PlayerColor player) const
{ {
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
hoverName = VLC->objtypeh->getObjectName(ID);
if(visitMode != VISIT_UNLIMITED) if(visitMode != VISIT_UNLIMITED)
{ return getObjectName() + " " + visitedTxt(wasVisited(player));
bool visited = wasVisited(cb->getCurrentPlayer()); return getObjectName();
if (h) }
visited |= wasVisited(h);
hoverName += " " + visitedTxt(visited); std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) const
} {
return hoverName; if(visitMode != VISIT_UNLIMITED)
return getObjectName() + " " + visitedTxt(wasVisited(hero));
return getObjectName();
} }
void CRewardableObject::setPropertyDer(ui8 what, ui32 val) void CRewardableObject::setPropertyDer(ui8 what, ui32 val)

View File

@ -209,7 +209,8 @@ protected:
public: public:
void setPropertyDer(ui8 what, ui32 val) override; void setPropertyDer(ui8 what, ui32 val) override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;
/// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player) /// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
bool wasVisited (PlayerColor player) const override; bool wasVisited (PlayerColor player) const override;

View File

@ -78,17 +78,16 @@ bool CPlayersVisited::wasVisited( TeamID team ) const
return false; return false;
} }
const std::string & CGCreature::getHoverText() const std::string CGCreature::getHoverText(PlayerColor player) const
{ {
if(stacks.empty()) if(stacks.empty())
{ {
static const std::string errorValue("!!!INVALID_STACK!!!");
//should not happen... //should not happen...
logGlobal->errorStream() << "Invalid stack at tile " << pos << ": subID=" << subID << "; id=" << id; logGlobal->errorStream() << "Invalid stack at tile " << pos << ": subID=" << subID << "; id=" << id;
return errorValue; // references to temporary are illegal - use pre-constructed string return "!!!INVALID_STACK!!!";
} }
std::string hoverName;
MetaString ms; MetaString ms;
int pom = stacks.begin()->second->getQuantityID(); int pom = stacks.begin()->second->getQuantityID();
pom = 172 + 3*pom; pom = 172 + 3*pom;
@ -96,30 +95,34 @@ const std::string & CGCreature::getHoverText() const
ms << " " ; ms << " " ;
ms.addTxt(MetaString::CRE_PL_NAMES,subID); ms.addTxt(MetaString::CRE_PL_NAMES,subID);
ms.toString(hoverName); ms.toString(hoverName);
if(const CGHeroInstance *selHero = cb->getSelectedHero(cb->getCurrentPlayer()))
{
const JsonNode & texts = VLC->generaltexth->localizedTexts["adventureMap"]["monsterThreat"];
hoverName += texts["title"].String();
int choice;
double ratio = ((double)getArmyStrength() / selHero->getTotalStrength());
if (ratio < 0.1) choice = 0;
else if (ratio < 0.25) choice = 1;
else if (ratio < 0.6) choice = 2;
else if (ratio < 0.9) choice = 3;
else if (ratio < 1.1) choice = 4;
else if (ratio < 1.3) choice = 5;
else if (ratio < 1.8) choice = 6;
else if (ratio < 2.5) choice = 7;
else if (ratio < 4) choice = 8;
else if (ratio < 8) choice = 9;
else if (ratio < 20) choice = 10;
else choice = 11;
hoverName += texts["levels"].Vector()[choice].String();
}
return hoverName; return hoverName;
} }
std::string CGCreature::getHoverText(const CGHeroInstance * hero) const
{
std::string hoverName = getHoverText(hero->tempOwner);
const JsonNode & texts = VLC->generaltexth->localizedTexts["adventureMap"]["monsterThreat"];
hoverName += texts["title"].String();
int choice;
double ratio = ((double)getArmyStrength() / hero->getTotalStrength());
if (ratio < 0.1) choice = 0;
else if (ratio < 0.25) choice = 1;
else if (ratio < 0.6) choice = 2;
else if (ratio < 0.9) choice = 3;
else if (ratio < 1.1) choice = 4;
else if (ratio < 1.3) choice = 5;
else if (ratio < 1.8) choice = 6;
else if (ratio < 2.5) choice = 7;
else if (ratio < 4) choice = 8;
else if (ratio < 8) choice = 9;
else if (ratio < 20) choice = 10;
else choice = 11;
hoverName += texts["levels"].Vector()[choice].String();
return hoverName;
}
void CGCreature::onHeroVisit( const CGHeroInstance * h ) const void CGCreature::onHeroVisit( const CGHeroInstance * h ) const
{ {
int action = takenAction(h); int action = takenAction(h);
@ -443,21 +446,6 @@ void CGCreature::battleFinished(const CGHeroInstance *hero, const BattleResult &
} }
else else
{ {
//int killedAmount=0;
//for(std::set<std::pair<ui32,si32> >::iterator i=result->casualties[1].begin(); i!=result->casualties[1].end(); i++)
// if(i->first == subID)
// killedAmount += i->second;
//cb->setAmount(id, slots.find(0)->second.second - killedAmount);
/*
MetaString ms;
int pom = slots.find(0)->second.getQuantityID();
pom = 174 + 3*pom + 1;
ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,subID);
cb->setHoverName(id,&ms);
cb->setObjProperty(id, 11, slots.begin()->second.count * 1000);
*/
//merge stacks into one //merge stacks into one
TSlots::const_iterator i; TSlots::const_iterator i;
CCreature * cre = VLC->creh->creatures[formation.basicType]; CCreature * cre = VLC->creh->creatures[formation.basicType];
@ -554,38 +542,48 @@ void CGMine::initObj()
assert(!possibleResources.empty()); assert(!possibleResources.empty());
producedResource = *RandomGeneratorUtil::nextItem(possibleResources, cb->gameState()->getRandomGenerator()); producedResource = *RandomGeneratorUtil::nextItem(possibleResources, cb->gameState()->getRandomGenerator());
tempOwner = PlayerColor::NEUTRAL; tempOwner = PlayerColor::NEUTRAL;
hoverName = VLC->generaltexth->mines[7].first + "\n" + VLC->generaltexth->allTexts[202] + " " + troglodytes->getQuantityTXT(false) + " " + troglodytes->type->namePl;
} }
else else
{ {
producedResource = static_cast<Res::ERes>(subID); producedResource = static_cast<Res::ERes>(subID);
MetaString ms;
ms << std::pair<ui8,ui32>(9,producedResource);
if(tempOwner >= PlayerColor::PLAYER_LIMIT) if(tempOwner >= PlayerColor::PLAYER_LIMIT)
tempOwner = PlayerColor::NEUTRAL; tempOwner = PlayerColor::NEUTRAL;
else
ms << " (" << std::pair<ui8,ui32>(6,23+tempOwner.getNum()) << ")";
ms.toString(hoverName);
} }
producedQuantity = defaultResProduction(); producedQuantity = defaultResProduction();
} }
std::string CGMine::getObjectName() const
{
return VLC->generaltexth->mines.at(subID).first;
}
std::string CGMine::getHoverText(PlayerColor player) const
{
std::string hoverName = getObjectName(); // Sawmill
if (tempOwner != PlayerColor::NEUTRAL)
{
hoverName += "\n";
hoverName += VLC->generaltexth->arraytxt[23 + tempOwner.getNum()]; // owned by Red Player
hoverName += "\n(" + VLC->generaltexth->restypes[producedResource] + ")";
}
for (auto & slot : Slots()) // guarded by a few Pikeman
{
hoverName += "\n";
hoverName += getRoughAmount(slot.first);
hoverName += getCreature(slot.first)->namePl;
}
return hoverName;
}
void CGMine::flagMine(PlayerColor player) const void CGMine::flagMine(PlayerColor player) const
{ {
assert(tempOwner != player); assert(tempOwner != player);
cb->setOwner(this, player); //not ours? flag it! cb->setOwner(this, player); //not ours? flag it!
MetaString ms;
ms << std::pair<ui8,ui32>(9,subID) << "\n(" << std::pair<ui8,ui32>(6,23+player.getNum()) << ")";
if(subID == 7)
{
ms << "(%s)";
ms.addReplacement(MetaString::RES_NAMES, producedResource);
}
cb->setHoverName(this,&ms);
InfoWindow iw; InfoWindow iw;
iw.soundID = soundBase::FLAGMINE; iw.soundID = soundBase::FLAGMINE;
iw.text.addTxt(MetaString::MINE_EVNTS,producedResource); //not use subID, abandoned mines uses default mine texts iw.text.addTxt(MetaString::MINE_EVNTS,producedResource); //not use subID, abandoned mines uses default mine texts
@ -626,10 +624,14 @@ void CGMine::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) con
cb->startBattleI(hero, this); cb->startBattleI(hero, this);
} }
std::string CGResource::getHoverText(PlayerColor player) const
{
return VLC->generaltexth->restypes[subID];
}
void CGResource::initObj() void CGResource::initObj()
{ {
blockVisit = true; blockVisit = true;
hoverName = VLC->generaltexth->restypes[subID];
if(!amount) if(!amount)
{ {
@ -866,7 +868,6 @@ void CGArtifact::initObj()
blockVisit = true; blockVisit = true;
if(ID == Obj::ARTIFACT) if(ID == Obj::ARTIFACT)
{ {
hoverName = VLC->arth->artifacts[subID]->Name();
if(!storedArtifact->artType) if(!storedArtifact->artType)
storedArtifact->setType(VLC->arth->artifacts[subID]); storedArtifact->setType(VLC->arth->artifacts[subID]);
} }
@ -879,6 +880,11 @@ void CGArtifact::initObj()
//assert(storedArtifact->artType->id == subID); //this does not stop desync //assert(storedArtifact->artType->id == subID); //this does not stop desync
} }
std::string CGArtifact::getObjectName() const
{
return VLC->arth->artifacts[subID]->Name();
}
void CGArtifact::onHeroVisit( const CGHeroInstance * h ) const void CGArtifact::onHeroVisit( const CGHeroInstance * h ) const
{ {
if(!stacksCount()) if(!stacksCount())
@ -985,20 +991,25 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
} }
const std::string & CGWitchHut::getHoverText() const std::string CGWitchHut::getHoverText(PlayerColor player) const
{ {
hoverName = VLC->objtypeh->getObjectName(ID); std::string hoverName = getObjectName();
if(wasVisited(cb->getLocalPlayer())) if(wasVisited(player))
{ {
hoverName += "\n" + VLC->generaltexth->allTexts[356]; // + (learn %s) hoverName += "\n" + VLC->generaltexth->allTexts[356]; // + (learn %s)
boost::algorithm::replace_first(hoverName,"%s",VLC->generaltexth->skillName[ability]); boost::algorithm::replace_first(hoverName,"%s",VLC->generaltexth->skillName[ability]);
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
if(h && h->getSecSkillLevel(SecondarySkill(ability))) //hero knows that ability
hoverName += "\n\n" + VLC->generaltexth->allTexts[357]; // (Already learned)
} }
return hoverName; return hoverName;
} }
std::string CGWitchHut::getHoverText(const CGHeroInstance * hero) const
{
std::string hoverName = getHoverText(hero->tempOwner);
if(hero->getSecSkillLevel(SecondarySkill(ability))) //hero knows that ability
hoverName += "\n\n" + VLC->generaltexth->allTexts[357]; // (Already learned)
return hoverName;
}
void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const
{ {
int message; int message;
@ -1020,10 +1031,9 @@ void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const
showInfoDialog(h,message,soundBase::faerie); showInfoDialog(h,message,soundBase::faerie);
} }
const std::string & CGMagicWell::getHoverText() const std::string CGMagicWell::getHoverText(const CGHeroInstance * hero) const
{ {
getNameVis(hoverName); return getObjectName() + " " + visitedTxt(hero->hasBonusFrom(Bonus::OBJECT,ID));
return hoverName;
} }
void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
@ -1120,20 +1130,25 @@ void CGShrine::initObj()
} }
} }
const std::string & CGShrine::getHoverText() const std::string CGShrine::getHoverText(PlayerColor player) const
{ {
hoverName = VLC->objtypeh->getObjectName(ID); std::string hoverName = getObjectName();
if(wasVisited(cb->getCurrentPlayer())) //TODO: use local player, not current if(wasVisited(player))
{ {
hoverName += "\n" + VLC->generaltexth->allTexts[355]; // + (learn %s) hoverName += "\n" + VLC->generaltexth->allTexts[355]; // + (learn %s)
boost::algorithm::replace_first(hoverName,"%s", spell.toSpell()->name); boost::algorithm::replace_first(hoverName,"%s", spell.toSpell()->name);
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
if(h && vstd::contains(h->spells,spell)) //hero knows that ability
hoverName += "\n\n" + VLC->generaltexth->allTexts[354]; // (Already learned)
} }
return hoverName; return hoverName;
} }
std::string CGShrine::getHoverText(const CGHeroInstance * hero) const
{
std::string hoverName = getHoverText(hero->tempOwner);
if(vstd::contains(hero->spells, spell)) //hero knows that spell
hoverName += "\n\n" + VLC->generaltexth->allTexts[354]; // (Already learned)
return hoverName;
}
void CGSignBottle::initObj() void CGSignBottle::initObj()
{ {
//if no text is set than we pick random from the predefined ones //if no text is set than we pick random from the predefined ones
@ -1329,10 +1344,9 @@ void CGSirens::initObj()
blockVisit = true; blockVisit = true;
} }
const std::string & CGSirens::getHoverText() const std::string CGSirens::getHoverText(const CGHeroInstance * hero) const
{ {
getNameVis(hoverName); return getObjectName() + " " + visitedTxt(hero->hasBonusFrom(Bonus::OBJECT,ID));
return hoverName;
} }
void CGSirens::onHeroVisit( const CGHeroInstance * h ) const void CGSirens::onHeroVisit( const CGHeroInstance * h ) const
@ -1503,11 +1517,9 @@ void CGObelisk::initObj()
obeliskCount++; obeliskCount++;
} }
const std::string & CGObelisk::getHoverText() const std::string CGObelisk::getHoverText(PlayerColor player) const
{ {
bool visited = wasVisited(cb->getLocalPlayer()); return getObjectName() + " " + visitedTxt(wasVisited(player));
hoverName = VLC->objtypeh->getObjectName(ID) + " " + visitedTxt(visited);
return hoverName;
} }
void CGObelisk::setPropertyDer( ui8 what, ui32 val ) void CGObelisk::setPropertyDer( ui8 what, ui32 val )
@ -1557,11 +1569,10 @@ void CGLighthouse::initObj()
} }
} }
const std::string & CGLighthouse::getHoverText() const std::string CGLighthouse::getHoverText(PlayerColor player) const
{ {
hoverName = VLC->objtypeh->getObjectName(ID);
//TODO: owned by %s player //TODO: owned by %s player
return hoverName; return getObjectName();
} }
void CGLighthouse::giveBonusTo( PlayerColor player ) const void CGLighthouse::giveBonusTo( PlayerColor player ) const

View File

@ -48,7 +48,8 @@ public:
bool refusedJoining; bool refusedJoining;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;
void initObj() override; void initObj() override;
void newTurn() const override; void newTurn() const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
@ -106,7 +107,8 @@ public:
std::vector<si32> allowedAbilities; std::vector<si32> allowedAbilities;
ui32 ability; ui32 ability;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj() override; void initObj() override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
@ -159,6 +161,8 @@ public:
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
std::string getObjectName() const override;
void pick( const CGHeroInstance * h ) const; void pick( const CGHeroInstance * h ) const;
void initObj() override; void initObj() override;
@ -179,6 +183,7 @@ public:
void initObj() override; void initObj() override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
std::string getHoverText(PlayerColor player) const override;
void collectRes(PlayerColor player) const; void collectRes(PlayerColor player) const;
@ -195,7 +200,8 @@ public:
SpellID spell; //id of spell or NONE if random SpellID spell; //id of spell or NONE if random
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj() override; void initObj() override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -217,6 +223,10 @@ public:
void flagMine(PlayerColor player) const; void flagMine(PlayerColor player) const;
void newTurn() const override; void newTurn() const override;
void initObj() override; void initObj() override;
std::string getObjectName() const override;
std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & static_cast<CArmedInstance&>(*this); h & static_cast<CArmedInstance&>(*this);
@ -245,7 +255,7 @@ class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses
{ {
public: public:
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
const std::string & getHoverText() const override; std::string getHoverText(const CGHeroInstance * hero) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -257,7 +267,7 @@ class DLL_LINKAGE CGSirens : public CGObjectInstance
{ {
public: public:
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
const std::string & getHoverText() const override; std::string getHoverText(const CGHeroInstance * hero) const override;
void initObj() override; void initObj() override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
@ -352,7 +362,7 @@ public:
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj() override; void initObj() override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -367,7 +377,7 @@ class DLL_LINKAGE CGLighthouse : public CGObjectInstance
public: public:
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj() override; void initObj() override;
const std::string & getHoverText() const override; std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -432,7 +432,7 @@ const CGObjectInstance * CMap::getObjectiveObjectFrom(int3 pos, Obj::EObj type)
} }
assert(bestMatch != nullptr); // if this happens - victory conditions or map itself is very, very broken assert(bestMatch != nullptr); // if this happens - victory conditions or map itself is very, very broken
logGlobal->errorStream() << "Will use " << bestMatch->getHoverText() << " from " << bestMatch->pos; logGlobal->errorStream() << "Will use " << bestMatch->getObjectName() << " from " << bestMatch->pos;
return bestMatch; return bestMatch;
} }

View File

@ -234,7 +234,6 @@ void registerTypesClientPacks1(Serializer &s)
s.template registerType<CPackForClient, NewTurn>(); s.template registerType<CPackForClient, NewTurn>();
s.template registerType<CPackForClient, InfoWindow>(); s.template registerType<CPackForClient, InfoWindow>();
s.template registerType<CPackForClient, SetObjectProperty>(); s.template registerType<CPackForClient, SetObjectProperty>();
s.template registerType<CPackForClient, SetHoverName>();
s.template registerType<CPackForClient, ShowInInfobox>(); s.template registerType<CPackForClient, ShowInInfobox>();
s.template registerType<CPackForClient, AdvmapSpellCast>(); s.template registerType<CPackForClient, AdvmapSpellCast>();
s.template registerType<CPackForClient, OpenWindow>(); s.template registerType<CPackForClient, OpenWindow>();

View File

@ -1849,12 +1849,6 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, PlayerColor owner)
} }
} }
void CGameHandler::setHoverName(const CGObjectInstance * obj, MetaString* name)
{
SetHoverName shn(obj->id, *name);
sendAndApply(&shn);
}
void CGameHandler::showBlockingDialog( BlockingDialog *iw ) void CGameHandler::showBlockingDialog( BlockingDialog *iw )
{ {
auto dialogQuery = make_shared<CBlockingDialogQuery>(*iw); auto dialogQuery = make_shared<CBlockingDialogQuery>(*iw);
@ -4992,7 +4986,7 @@ bool CGameHandler::isAllowedExchange( ObjectInstanceID id1, ObjectInstanceID id2
void CGameHandler::objectVisited( const CGObjectInstance * obj, const CGHeroInstance * h ) void CGameHandler::objectVisited( const CGObjectInstance * obj, const CGHeroInstance * h )
{ {
logGlobal->traceStream() << h->nodeName() << " visits " << obj->getHoverText(); logGlobal->traceStream() << h->nodeName() << " visits " << obj->getObjectName();
auto visitQuery = make_shared<CObjectVisitQuery>(obj, h, obj->visitablePos()); auto visitQuery = make_shared<CObjectVisitQuery>(obj, h, obj->visitablePos());
queries.addQuery(visitQuery); //TODO real visit pos queries.addQuery(visitQuery); //TODO real visit pos

View File

@ -127,7 +127,6 @@ public:
bool removeObject(const CGObjectInstance * obj) override; bool removeObject(const CGObjectInstance * obj) override;
void setBlockVis(ObjectInstanceID objid, bool bv) override; void setBlockVis(ObjectInstanceID objid, bool bv) override;
void setOwner(const CGObjectInstance * obj, PlayerColor owner) override; void setOwner(const CGObjectInstance * obj, PlayerColor owner) override;
void setHoverName(const CGObjectInstance * objid, MetaString * name) override;
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) override; void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) override;
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override; void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override;
//void showInfoDialog(InfoWindow *iw) override; //void showInfoDialog(InfoWindow *iw) override;

View File

@ -322,7 +322,7 @@ CHeroLevelUpDialogQuery::CHeroLevelUpDialogQuery(const HeroLevelUp &Hlu)
void CHeroLevelUpDialogQuery::onRemoval(CGameHandler *gh, PlayerColor color) void CHeroLevelUpDialogQuery::onRemoval(CGameHandler *gh, PlayerColor color)
{ {
assert(answer); assert(answer);
logGlobal->traceStream() << "Completing hero level-up query. " << hlu.hero->getHoverText() << " gains skill " << *answer; logGlobal->traceStream() << "Completing hero level-up query. " << hlu.hero->getObjectName() << " gains skill " << *answer;
gh->levelUpHero(hlu.hero, hlu.skills[*answer]); gh->levelUpHero(hlu.hero, hlu.skills[*answer]);
} }
@ -340,7 +340,7 @@ CCommanderLevelUpDialogQuery::CCommanderLevelUpDialogQuery(const CommanderLevelU
void CCommanderLevelUpDialogQuery::onRemoval(CGameHandler *gh, PlayerColor color) void CCommanderLevelUpDialogQuery::onRemoval(CGameHandler *gh, PlayerColor color)
{ {
assert(answer); assert(answer);
logGlobal->traceStream() << "Completing commander level-up query. Commander of hero " << clu.hero->getHoverText() << " gains skill " << *answer; logGlobal->traceStream() << "Completing commander level-up query. Commander of hero " << clu.hero->getObjectName() << " gains skill " << *answer;
gh->levelUpCommander(clu.hero->commander, clu.skills[*answer]); gh->levelUpCommander(clu.hero->commander, clu.skills[*answer]);
} }