mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
code review
This commit is contained in:
parent
344e845684
commit
11eaed9fef
@ -467,29 +467,19 @@ void AdventureMapShortcuts::search(bool next)
|
|||||||
{
|
{
|
||||||
// get all relevant objects
|
// get all relevant objects
|
||||||
std::vector<ObjectInstanceID> visitableObjInstances;
|
std::vector<ObjectInstanceID> visitableObjInstances;
|
||||||
int3 mapSizes = LOCPLINT->cb->getMapSize();
|
for(auto & obj : LOCPLINT->cb->getAllVisitableObjs())
|
||||||
for(int x = 0; x < mapSizes.x; x++)
|
if(obj->ID != MapObjectID::MONSTER && obj->ID != MapObjectID::HERO && obj->ID != MapObjectID::TOWN)
|
||||||
for(int y = 0; y < mapSizes.y; y++)
|
visitableObjInstances.push_back(obj->id);
|
||||||
for(int z = 0; z < mapSizes.z; z++)
|
|
||||||
for(auto & obj : LOCPLINT->cb->getVisitableObjs(int3(x, y, z), false))
|
|
||||||
if(obj->ID != MapObjectID::MONSTER && obj->ID != MapObjectID::EVENT && obj->ID != MapObjectID::HERO)
|
|
||||||
visitableObjInstances.push_back(obj->id);
|
|
||||||
|
|
||||||
// count of elements for each group
|
// count of elements for each group (map is already sorted)
|
||||||
std::map<std::string, int> mapObjCount;
|
std::map<std::string, int> mapObjCount;
|
||||||
for(auto & obj : visitableObjInstances)
|
for(auto & obj : visitableObjInstances)
|
||||||
mapObjCount[{ VLC->objtypeh->getObjectName(LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex()) }]++;
|
mapObjCount[{ LOCPLINT->cb->getObjInstance(obj)->getObjectName() }]++;
|
||||||
|
|
||||||
// sort by name
|
// convert to vector for indexed access
|
||||||
std::vector<std::pair<std::string, int>> textCountList;
|
std::vector<std::pair<std::string, int>> textCountList;
|
||||||
for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr)
|
for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr)
|
||||||
textCountList.push_back(*itr);
|
textCountList.push_back(*itr);
|
||||||
std::sort(textCountList.begin(), textCountList.end(),
|
|
||||||
[=](std::pair<std::string, int>& a, std::pair<std::string, int>& b)
|
|
||||||
{
|
|
||||||
return a.first < b.first;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// get pos of last selection
|
// get pos of last selection
|
||||||
int lastSel = 0;
|
int lastSel = 0;
|
||||||
@ -510,7 +500,7 @@ void AdventureMapShortcuts::search(bool next)
|
|||||||
// filter for matching objects
|
// filter for matching objects
|
||||||
std::vector<ObjectInstanceID> selVisitableObjInstances;
|
std::vector<ObjectInstanceID> selVisitableObjInstances;
|
||||||
for(auto & obj : visitableObjInstances)
|
for(auto & obj : visitableObjInstances)
|
||||||
if(selObj == VLC->objtypeh->getObjectName(LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex(), LOCPLINT->cb->getObjInstance(obj)->getObjTypeIndex()))
|
if(selObj == LOCPLINT->cb->getObjInstance(obj)->getObjectName())
|
||||||
selVisitableObjInstances.push_back(obj);
|
selVisitableObjInstances.push_back(obj);
|
||||||
|
|
||||||
if(searchPos + 1 < selVisitableObjInstances.size() && searchLast == selObj)
|
if(searchPos + 1 < selVisitableObjInstances.size() && searchLast == selObj)
|
||||||
@ -520,7 +510,7 @@ void AdventureMapShortcuts::search(bool next)
|
|||||||
|
|
||||||
auto objInst = LOCPLINT->cb->getObjInstance(selVisitableObjInstances[searchPos]);
|
auto objInst = LOCPLINT->cb->getObjInstance(selVisitableObjInstances[searchPos]);
|
||||||
owner.centerOnObject(objInst);
|
owner.centerOnObject(objInst);
|
||||||
searchLast = VLC->objtypeh->getObjectName(objInst->getObjGroupIndex(), objInst->getObjTypeIndex());
|
searchLast = objInst->getObjectName();
|
||||||
};
|
};
|
||||||
|
|
||||||
if(next)
|
if(next)
|
||||||
|
@ -479,6 +479,17 @@ std::vector <const CGObjectInstance *> CGameInfoCallback::getVisitableObjs(int3
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ConstTransitivePtr<CGObjectInstance>> CGameInfoCallback::getAllVisitableObjs() const
|
||||||
|
{
|
||||||
|
std::vector<ConstTransitivePtr<CGObjectInstance>> ret;
|
||||||
|
for(auto & obj : gs->map->objects)
|
||||||
|
if(obj->isVisitable() && obj->ID != Obj::EVENT && getTile(obj->pos, false))
|
||||||
|
ret.push_back(obj);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
const CGObjectInstance * CGameInfoCallback::getTopObj (int3 pos) const
|
const CGObjectInstance * CGameInfoCallback::getTopObj (int3 pos) const
|
||||||
{
|
{
|
||||||
return vstd::backOrNull(getVisitableObjs(pos));
|
return vstd::backOrNull(getVisitableObjs(pos));
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "int3.h"
|
#include "int3.h"
|
||||||
#include "ResourceSet.h" // for Res
|
#include "ResourceSet.h" // for Res
|
||||||
|
#include "ConstTransitivePtr.h"
|
||||||
|
|
||||||
#define ASSERT_IF_CALLED_WITH_PLAYER if(!getPlayerID()) {logGlobal->error(BOOST_CURRENT_FUNCTION); assert(0);}
|
#define ASSERT_IF_CALLED_WITH_PLAYER if(!getPlayerID()) {logGlobal->error(BOOST_CURRENT_FUNCTION); assert(0);}
|
||||||
|
|
||||||
@ -189,6 +190,7 @@ public:
|
|||||||
const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
|
const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
|
||||||
virtual std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
|
virtual std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
|
||||||
std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true) const override;
|
std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true) const override;
|
||||||
|
std::vector<ConstTransitivePtr<CGObjectInstance>> getAllVisitableObjs() const;
|
||||||
virtual std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
|
virtual std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
|
||||||
virtual const CGObjectInstance * getTopObj (int3 pos) const;
|
virtual const CGObjectInstance * getTopObj (int3 pos) const;
|
||||||
virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
|
virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user