1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-21 12:06:49 +02:00

Merge branch 'develop' into SpellsRefactoring8

This commit is contained in:
AlexVinS 2016-09-11 18:34:18 +03:00
commit 33d1895d21
32 changed files with 174 additions and 87 deletions

@ -509,8 +509,10 @@ bool compareArtifacts(const CArtifactInstance *a1, const CArtifactInstance *a2)
auto art1 = a1->artType; auto art1 = a1->artType;
auto art2 = a2->artType; auto art2 = a2->artType;
if (art1->valOfBonuses(Bonus::PRIMARY_SKILL) > art2->valOfBonuses(Bonus::PRIMARY_SKILL)) if(art1->price == art2->price)
return art1->valOfBonuses(Bonus::PRIMARY_SKILL) > art2->valOfBonuses(Bonus::PRIMARY_SKILL);
else if(art1->price > art2->price)
return true; return true;
else else
return art1->price > art2->price; return false;
} }

@ -15,7 +15,7 @@
class VCAI; class VCAI;
class CArmedInstance; class CArmedInstance;
class CBank; class CBank;
class SectorMap; struct SectorMap;
class engineBase class engineBase
{ {

@ -21,7 +21,7 @@ class FuzzyHelper;
namespace Goals namespace Goals
{ {
struct AbstractGoal; class AbstractGoal;
class VisitTile; class VisitTile;
typedef std::shared_ptr<Goals::AbstractGoal> TSubgoal; typedef std::shared_ptr<Goals::AbstractGoal> TSubgoal;
typedef std::vector<TSubgoal> TGoalVec; typedef std::vector<TSubgoal> TGoalVec;

@ -226,7 +226,6 @@ void CCallback::trade(const CGObjectInstance *market, EMarketMode::EMarketMode m
void CCallback::setFormation(const CGHeroInstance * hero, bool tight) void CCallback::setFormation(const CGHeroInstance * hero, bool tight)
{ {
const_cast<CGHeroInstance*>(hero)-> formation = tight;
SetFormation pack(hero->id,tight); SetFormation pack(hero->id,tight);
sendRequest(&pack); sendRequest(&pack);
} }

@ -407,7 +407,7 @@ int main(int argc, char** argv)
} }
} }
setScreenRes(res["width"].Float(), res["height"].Float(), video["bitsPerPixel"].Float(), video["displayIndex"].Float(), video["fullscreen"].Bool()); setScreenRes(res["width"].Float(), res["height"].Float(), video["bitsPerPixel"].Float(), video["fullscreen"].Bool(), video["displayIndex"].Float());
logGlobal->infoStream() <<"\tInitializing screen: "<<pomtime.getDiff(); logGlobal->infoStream() <<"\tInitializing screen: "<<pomtime.getDiff();
} }

@ -529,17 +529,17 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
updateInfo(town); updateInfo(town);
if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison if(town->garrisonHero) //wandering hero moved to the garrison
{ {
CGI->mh->hideObject(town->garrisonHero); CGI->mh->hideObject(town->garrisonHero);
if (town->garrisonHero->tempOwner == playerID) // our hero if(town->garrisonHero->tempOwner == playerID && vstd::contains(wanderingHeroes,town->garrisonHero)) // our hero
wanderingHeroes -= town->garrisonHero; wanderingHeroes -= town->garrisonHero;
} }
if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison if(town->visitingHero) //hero leaves garrison
{ {
CGI->mh->printObject(town->visitingHero); CGI->mh->printObject(town->visitingHero);
if (town->visitingHero->tempOwner == playerID) // our hero if(town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero
wanderingHeroes.push_back(town->visitingHero); wanderingHeroes.push_back(town->visitingHero);
} }
adventureInt->heroList.update(); adventureInt->heroList.update();

@ -451,19 +451,19 @@ void SetHeroesInTown::applyCl( CClient *cl )
CGHeroInstance *hGarr = GS(cl)->getHero(this->garrison); CGHeroInstance *hGarr = GS(cl)->getHero(this->garrison);
CGHeroInstance *hVisit = GS(cl)->getHero(this->visiting); CGHeroInstance *hVisit = GS(cl)->getHero(this->visiting);
std::set<PlayerColor> playersToNotify; //inform all players that see this object
for(auto i = cl->playerint.cbegin(); i != cl->playerint.cend(); ++i)
{
if(i->first >= PlayerColor::PLAYER_LIMIT)
continue;
if(vstd::contains(cl->playerint,t->tempOwner)) // our town if(GS(cl)->isVisible(t, i->first) ||
playersToNotify.insert(t->tempOwner); (hGarr && GS(cl)->isVisible(hGarr, i->first)) ||
(hVisit && GS(cl)->isVisible(hVisit, i->first)))
if (hGarr && vstd::contains(cl->playerint, hGarr->tempOwner)) {
playersToNotify.insert(hGarr->tempOwner); cl->playerint[i->first]->heroInGarrisonChange(t);
}
if (hVisit && vstd::contains(cl->playerint, hVisit->tempOwner)) }
playersToNotify.insert(hVisit->tempOwner);
for(auto playerID : playersToNotify)
cl->playerint[playerID]->heroInGarrisonChange(t);
} }
// void SetHeroArtifacts::applyCl( CClient *cl ) // void SetHeroArtifacts::applyCl( CClient *cl )

@ -14,7 +14,7 @@
* *
*/ */
class StackWindowInfo; struct StackWindowInfo;
class CCommanderInstance; class CCommanderInstance;
class CStackInstance; class CStackInstance;
class CStack; class CStack;

@ -43,7 +43,14 @@ public:
{ {
h & color & human & team & resources & status; h & color & human & team & resources & status;
h & heroes & towns & availableHeroes & dwellings & quests & visitedObjects; h & heroes & towns & availableHeroes & dwellings & quests & visitedObjects;
h & getBonusList(); //FIXME FIXME FIXME
if(version < 760)
{
//was: h & getBonusList();
BonusList junk;
h & junk;
}
h & status & daysWithoutCastle; h & status & daysWithoutCastle;
h & enteredLosingCheatCode & enteredWinningCheatCode; h & enteredLosingCheatCode & enteredWinningCheatCode;
h & static_cast<CBonusSystemNode&>(*this); h & static_cast<CBonusSystemNode&>(*this);

@ -27,7 +27,7 @@
#include "mapping/CCampaignHandler.h" //for CCampaignState #include "mapping/CCampaignHandler.h" //for CCampaignState
#include "rmg/CMapGenerator.h" // for CMapGenOptions #include "rmg/CMapGenerator.h" // for CMapGenOptions
const ui32 version = 759; const ui32 version = 760;
const ui32 minSupportedVersion = 753; const ui32 minSupportedVersion = 753;
class CISer; class CISer;

@ -535,6 +535,20 @@ struct UpdateCastleEvents : public CPackForClient //125
} }
}; };
struct ChangeFormation : public CPackForClient //126
{
ChangeFormation(){type = 126;}
ObjectInstanceID hid;
ui8 formation;
DLL_LINKAGE void applyGs(CGameState *gs);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & hid & formation;
}
};
struct RemoveObject : public CPackForClient //500 struct RemoveObject : public CPackForClient //500
{ {
RemoveObject(){type = 500;}; RemoveObject(){type = 500;};

@ -157,6 +157,11 @@ DLL_LINKAGE void UpdateCastleEvents::applyGs(CGameState *gs)
t->events = events; t->events = events;
} }
DLL_LINKAGE void ChangeFormation::applyGs(CGameState *gs)
{
gs->getHero(hid)->setFormation(formation);
}
DLL_LINKAGE void HeroVisitCastle::applyGs( CGameState *gs ) DLL_LINKAGE void HeroVisitCastle::applyGs( CGameState *gs )
{ {
CGHeroInstance *h = gs->getHero(hid); CGHeroInstance *h = gs->getHero(hid);

@ -162,6 +162,7 @@
<Unit filename="CObstacleInstance.h" /> <Unit filename="CObstacleInstance.h" />
<Unit filename="CPathfinder.cpp" /> <Unit filename="CPathfinder.cpp" />
<Unit filename="CPathfinder.h" /> <Unit filename="CPathfinder.h" />
<Unit filename="CPlayerState.h" />
<Unit filename="CRandomGenerator.cpp" /> <Unit filename="CRandomGenerator.cpp" />
<Unit filename="CRandomGenerator.h" /> <Unit filename="CRandomGenerator.h" />
<Unit filename="CScriptingModule.h" /> <Unit filename="CScriptingModule.h" />

@ -272,7 +272,7 @@ zlib_filefunc64_def* FileStream::GetMinizipFilefunc()
return &MinizipFilefunc; return &MinizipFilefunc;
} }
template class boost::iostreams::stream<FileBuf>; template struct boost::iostreams::stream<FileBuf>;
/*static*/ /*static*/
bool FileStream::CreateFile(const boost::filesystem::path& filename) bool FileStream::CreateFile(const boost::filesystem::path& filename)

@ -37,7 +37,7 @@ struct zlib_filefunc64_def_s;
typedef zlib_filefunc64_def_s zlib_filefunc64_def; typedef zlib_filefunc64_def_s zlib_filefunc64_def;
#ifdef VCMI_DLL #ifdef VCMI_DLL
extern template class DLL_LINKAGE boost::iostreams::stream<FileBuf>; extern template struct DLL_LINKAGE boost::iostreams::stream<FileBuf>;
#endif #endif
class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf> class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>

@ -38,7 +38,12 @@ static inline std::string readName(std::string name)
{ {
const auto dotPos = name.find_last_of('.'); const auto dotPos = name.find_last_of('.');
if (dotPos != std::string::npos) //do not cut "extension" of directory name
auto delimPos = name.find_last_of('/');
if(delimPos == std::string::npos)
delimPos = name.find_last_of('\\');
if((delimPos == std::string::npos || delimPos < dotPos) && dotPos != std::string::npos)
name.resize(dotPos); name.resize(dotPos);
toUpper(name); toUpper(name);

@ -433,11 +433,11 @@ boost::optional<std::string> AObjectTypeHandler::getCustomName() const
return objectName; return objectName;
} }
void AObjectTypeHandler::addTemplate(ObjectTemplate templ) void AObjectTypeHandler::addTemplate(const ObjectTemplate & templ)
{ {
templ.id = Obj(type);
templ.subid = subtype;
templates.push_back(templ); templates.push_back(templ);
templates.back().id = Obj(type);
templates.back().subid = subtype;
} }
void AObjectTypeHandler::addTemplate(JsonNode config) void AObjectTypeHandler::addTemplate(JsonNode config)
@ -449,7 +449,7 @@ void AObjectTypeHandler::addTemplate(JsonNode config)
tmpl.subid = subtype; tmpl.subid = subtype;
tmpl.stringID = ""; // TODO? tmpl.stringID = ""; // TODO?
tmpl.readJson(config); tmpl.readJson(config);
addTemplate(tmpl); templates.push_back(tmpl);
} }
std::vector<ObjectTemplate> AObjectTypeHandler::getTemplates() const std::vector<ObjectTemplate> AObjectTypeHandler::getTemplates() const

@ -128,7 +128,7 @@ public:
/// Returns object-specific name, if set /// Returns object-specific name, if set
boost::optional<std::string> getCustomName() const; boost::optional<std::string> getCustomName() const;
void addTemplate(ObjectTemplate templ); void addTemplate(const ObjectTemplate & templ);
void addTemplate(JsonNode config); void addTemplate(JsonNode config);
/// returns all templates matching parameters /// returns all templates matching parameters
@ -147,14 +147,14 @@ public:
/// Creates object and set up core properties (like ID/subID). Object is NOT initialized /// Creates object and set up core properties (like ID/subID). Object is NOT initialized
/// to allow creating objects before game start (e.g. map loading) /// to allow creating objects before game start (e.g. map loading)
virtual CGObjectInstance * create(ObjectTemplate tmpl) const = 0; virtual CGObjectInstance * create(const ObjectTemplate & tmpl) const = 0;
/// Configures object properties. Should be re-entrable, resetting state of the object if necessarily /// Configures object properties. Should be re-entrable, resetting state of the object if necessarily
/// This should set remaining properties, including randomized or depending on map /// This should set remaining properties, including randomized or depending on map
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0; virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0;
/// Returns object configuration, if available. Otherwise returns NULL /// Returns object configuration, if available. Otherwise returns NULL
virtual std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const = 0; virtual std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const = 0;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

@ -185,7 +185,7 @@ void CRewardableConstructor::initTypeData(const JsonNode & config)
objectInfo.init(config); objectInfo.init(config);
} }
CGObjectInstance * CRewardableConstructor::create(ObjectTemplate tmpl) const CGObjectInstance * CRewardableConstructor::create(const ObjectTemplate & tmpl) const
{ {
auto ret = new CRewardableObject(); auto ret = new CRewardableObject();
preInitObject(ret); preInitObject(ret);
@ -198,7 +198,7 @@ void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomG
objectInfo.configureObject(dynamic_cast<CRewardableObject*>(object), rng); objectInfo.configureObject(dynamic_cast<CRewardableObject*>(object), rng);
} }
std::unique_ptr<IObjectInfo> CRewardableConstructor::getObjectInfo(ObjectTemplate tmpl) const std::unique_ptr<IObjectInfo> CRewardableConstructor::getObjectInfo(const ObjectTemplate & tmpl) const
{ {
return std::unique_ptr<IObjectInfo>(new CRandomRewardObjectInfo(objectInfo)); return std::unique_ptr<IObjectInfo>(new CRandomRewardObjectInfo(objectInfo));
} }

@ -50,9 +50,9 @@ class DLL_LINKAGE CRewardableConstructor : public AObjectTypeHandler
public: public:
CRewardableConstructor(); CRewardableConstructor();
CGObjectInstance * create(ObjectTemplate tmpl) const override; CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override; void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const override; std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const override;
}; };

@ -71,7 +71,7 @@ bool CTownInstanceConstructor::objectFilter(const CGObjectInstance * object, con
return false; return false;
} }
CGObjectInstance * CTownInstanceConstructor::create(ObjectTemplate tmpl) const CGObjectInstance * CTownInstanceConstructor::create(const ObjectTemplate & tmpl) const
{ {
CGTownInstance * obj = createTyped(tmpl); CGTownInstance * obj = createTyped(tmpl);
obj->town = faction->town; obj->town = faction->town;
@ -126,7 +126,7 @@ bool CHeroInstanceConstructor::objectFilter(const CGObjectInstance * object, con
return false; return false;
} }
CGObjectInstance * CHeroInstanceConstructor::create(ObjectTemplate tmpl) const CGObjectInstance * CHeroInstanceConstructor::create(const ObjectTemplate & tmpl) const
{ {
CGHeroInstance * obj = createTyped(tmpl); CGHeroInstance * obj = createTyped(tmpl);
obj->type = nullptr; //FIXME: set to valid value. somehow. obj->type = nullptr; //FIXME: set to valid value. somehow.
@ -169,7 +169,7 @@ bool CDwellingInstanceConstructor::objectFilter(const CGObjectInstance *, const
return false; return false;
} }
CGObjectInstance * CDwellingInstanceConstructor::create(ObjectTemplate tmpl) const CGObjectInstance * CDwellingInstanceConstructor::create(const ObjectTemplate & tmpl) const
{ {
CGDwelling * obj = createTyped(tmpl); CGDwelling * obj = createTyped(tmpl);
@ -267,7 +267,7 @@ void CBankInstanceConstructor::initTypeData(const JsonNode & input)
bankResetDuration = input["resetDuration"].Float(); bankResetDuration = input["resetDuration"].Float();
} }
CGObjectInstance *CBankInstanceConstructor::create(ObjectTemplate tmpl) const CGObjectInstance *CBankInstanceConstructor::create(const ObjectTemplate & tmpl) const
{ {
return createTyped(tmpl); return createTyped(tmpl);
} }
@ -448,7 +448,7 @@ bool CBankInfo::givesSpells() const
} }
std::unique_ptr<IObjectInfo> CBankInstanceConstructor::getObjectInfo(ObjectTemplate tmpl) const std::unique_ptr<IObjectInfo> CBankInstanceConstructor::getObjectInfo(const ObjectTemplate & tmpl) const
{ {
return std::unique_ptr<IObjectInfo>(new CBankInfo(levels)); return std::unique_ptr<IObjectInfo>(new CBankInfo(levels));
} }

@ -29,7 +29,7 @@ template<class ObjectType>
class CDefaultObjectTypeHandler : public AObjectTypeHandler class CDefaultObjectTypeHandler : public AObjectTypeHandler
{ {
protected: protected:
ObjectType * createTyped(ObjectTemplate tmpl) const ObjectType * createTyped(const ObjectTemplate & tmpl) const
{ {
auto obj = new ObjectType(); auto obj = new ObjectType();
preInitObject(obj); preInitObject(obj);
@ -39,7 +39,7 @@ protected:
public: public:
CDefaultObjectTypeHandler(){} CDefaultObjectTypeHandler(){}
CGObjectInstance * create(ObjectTemplate tmpl) const override CGObjectInstance * create(const ObjectTemplate & tmpl) const override
{ {
return createTyped(tmpl); return createTyped(tmpl);
} }
@ -48,7 +48,7 @@ public:
{ {
} }
virtual std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const override virtual std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const override
{ {
return nullptr; return nullptr;
} }
@ -73,7 +73,7 @@ public:
std::map<std::string, LogicalExpression<BuildingID>> filters; std::map<std::string, LogicalExpression<BuildingID>> filters;
CTownInstanceConstructor(); CTownInstanceConstructor();
CGObjectInstance * create(ObjectTemplate tmpl) const override; CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override; void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
void afterLoadFinalization() override; void afterLoadFinalization() override;
@ -96,7 +96,7 @@ public:
std::map<std::string, LogicalExpression<HeroTypeID>> filters; std::map<std::string, LogicalExpression<HeroTypeID>> filters;
CHeroInstanceConstructor(); CHeroInstanceConstructor();
CGObjectInstance * create(ObjectTemplate tmpl) const override; CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override; void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
void afterLoadFinalization() override; void afterLoadFinalization() override;
@ -120,7 +120,7 @@ protected:
public: public:
CDwellingInstanceConstructor(); CDwellingInstanceConstructor();
CGObjectInstance * create(ObjectTemplate tmpl) const override; CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override; void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
bool producesCreature(const CCreature * crea) const; bool producesCreature(const CCreature * crea) const;
@ -186,10 +186,10 @@ public:
CBankInstanceConstructor(); CBankInstanceConstructor();
CGObjectInstance *create(ObjectTemplate tmpl) const override; CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override; void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const override; std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

@ -17,8 +17,8 @@ class JsonNode;
typedef std::vector<JsonNode> JsonVector; typedef std::vector<JsonNode> JsonVector;
class CRandomGenerator; class CRandomGenerator;
class Bonus; struct Bonus;
class Component; struct Component;
class CStackBasicDescriptor; class CStackBasicDescriptor;
namespace JsonRandom namespace JsonRandom

@ -58,6 +58,37 @@ ObjectTemplate::ObjectTemplate():
{ {
} }
ObjectTemplate::ObjectTemplate(const ObjectTemplate& other):
visitDir(other.visitDir),
allowedTerrains(other.allowedTerrains),
id(other.id),
subid(other.subid),
printPriority(other.printPriority),
animationFile(other.animationFile)
{
//default copy constructor is failing with usedTiles this for unknown reason
usedTiles.resize(other.usedTiles.size());
for(size_t i = 0; i < usedTiles.size(); i++)
std::copy(other.usedTiles[i].begin(), other.usedTiles[i].end(), std::back_inserter(usedTiles[i]));
}
ObjectTemplate & ObjectTemplate::operator=(const ObjectTemplate & rhs)
{
visitDir = rhs.visitDir;
allowedTerrains = rhs.allowedTerrains;
id = rhs.id;
subid = rhs.subid;
printPriority = rhs.printPriority;
animationFile = rhs.animationFile;
usedTiles.clear();
usedTiles.resize(rhs.usedTiles.size());
for(size_t i = 0; i < usedTiles.size(); i++)
std::copy(rhs.usedTiles[i].begin(), rhs.usedTiles[i].end(), std::back_inserter(usedTiles[i]));
return *this;
}
void ObjectTemplate::readTxt(CLegacyConfigParser & parser) void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
{ {
std::string data = parser.readString(); std::string data = parser.readString();

@ -69,6 +69,10 @@ public:
bool canBePlacedAt(ETerrainType terrain) const; bool canBePlacedAt(ETerrainType terrain) const;
ObjectTemplate(); ObjectTemplate();
//custom copy constructor is required
ObjectTemplate(const ObjectTemplate & other);
ObjectTemplate& operator=(const ObjectTemplate & rhs);
void readTxt(CLegacyConfigParser & parser); void readTxt(CLegacyConfigParser & parser);
void readMsk(); void readMsk();

@ -556,13 +556,6 @@ void CMap::eraseArtifactInstance(CArtifactInstance * art)
artInstances[art->id.getNum()].dellNull(); artInstances[art->id.getNum()].dellNull();
} }
void CMap::addQuest(CGObjectInstance * quest)
{
auto q = dynamic_cast<IQuestObject *>(quest);
q->quest->qid = quests.size();
quests.push_back(q->quest);
}
void CMap::addNewObject(CGObjectInstance * obj) void CMap::addNewObject(CGObjectInstance * obj)
{ {
if(obj->id != ObjectInstanceID(objects.size())) if(obj->id != ObjectInstanceID(objects.size()))
@ -573,19 +566,41 @@ void CMap::addNewObject(CGObjectInstance * obj)
auto it = instanceNames.find(obj->instanceName); auto it = instanceNames.find(obj->instanceName);
if(it != instanceNames.end()) if(it != instanceNames.end())
throw std::runtime_error("Object instance name duplicated:"+obj->instanceName); throw std::runtime_error("Object instance name duplicated: "+obj->instanceName);
objects.push_back(obj); objects.push_back(obj);
instanceNames[obj->instanceName] = obj; instanceNames[obj->instanceName] = obj;
addBlockVisTiles(obj); addBlockVisTiles(obj);
if(obj->ID == Obj::TOWN) //todo: make this virtual method of CGObjectInstance
switch (obj->ID)
{ {
case Obj::TOWN:
towns.push_back(static_cast<CGTownInstance *>(obj)); towns.push_back(static_cast<CGTownInstance *>(obj));
} break;
if(obj->ID == Obj::HERO) case Obj::HERO:
{
heroesOnMap.push_back(static_cast<CGHeroInstance*>(obj)); heroesOnMap.push_back(static_cast<CGHeroInstance*>(obj));
break;
case Obj::SEER_HUT:
case Obj::QUEST_GUARD:
case Obj::BORDERGUARD:
case Obj::BORDER_GATE:
{
auto q = dynamic_cast<IQuestObject *>(obj);
q->quest->qid = quests.size();
quests.push_back(q->quest);
}
break;
case Obj::SPELL_SCROLL:
{
CGArtifact * art = dynamic_cast<CGArtifact *>(obj);
if(art->storedArtifact && art->storedArtifact->id.getNum() < 0)
addNewArtifactInstance(art->storedArtifact);
}
break;
default:
break;
} }
} }

@ -313,7 +313,7 @@ public:
void addNewArtifactInstance(CArtifactInstance * art); void addNewArtifactInstance(CArtifactInstance * art);
void eraseArtifactInstance(CArtifactInstance * art); void eraseArtifactInstance(CArtifactInstance * art);
void addQuest(CGObjectInstance * quest);
void addNewObject(CGObjectInstance * obj); void addNewObject(CGObjectInstance * obj);
/// Gets object of specified type on requested position /// Gets object of specified type on requested position

@ -1112,7 +1112,6 @@ void CMapLoaderH3M::readObjects()
case Obj::SEER_HUT: case Obj::SEER_HUT:
{ {
nobj = readSeerHut(); nobj = readSeerHut();
map->addQuest(nobj);
break; break;
} }
case Obj::WITCH_HUT: case Obj::WITCH_HUT:
@ -1363,7 +1362,6 @@ void CMapLoaderH3M::readObjects()
case Obj::QUEST_GUARD: case Obj::QUEST_GUARD:
{ {
auto guard = new CGQuestGuard(); auto guard = new CGQuestGuard();
map->addQuest(guard);
readQuest(guard); readQuest(guard);
nobj = guard; nobj = guard;
break; break;
@ -1400,13 +1398,11 @@ void CMapLoaderH3M::readObjects()
case Obj::BORDERGUARD: case Obj::BORDERGUARD:
{ {
nobj = new CGBorderGuard(); nobj = new CGBorderGuard();
map->addQuest(nobj);
break; break;
} }
case Obj::BORDER_GATE: case Obj::BORDER_GATE:
{ {
nobj = new CGBorderGate(); nobj = new CGBorderGate();
map->addQuest (nobj);
break; break;
} }
case Obj::PYRAMID: //Pyramid of WoG object case Obj::PYRAMID: //Pyramid of WoG object

@ -17,7 +17,7 @@
#include "../filesystem/CZipLoader.h" #include "../filesystem/CZipLoader.h"
#include "../GameConstants.h" #include "../GameConstants.h"
class TriggeredEvent; struct TriggeredEvent;
struct TerrainTile; struct TerrainTile;
struct PlayerInfo; struct PlayerInfo;
class CGObjectInstance; class CGObjectInstance;

@ -227,6 +227,7 @@ void registerTypesClientPacks1(Serializer &s)
s.template registerType<CPackForClient, UpdateArtHandlerLists>(); s.template registerType<CPackForClient, UpdateArtHandlerLists>();
s.template registerType<CPackForClient, UpdateMapEvents>(); s.template registerType<CPackForClient, UpdateMapEvents>();
s.template registerType<CPackForClient, UpdateCastleEvents>(); s.template registerType<CPackForClient, UpdateCastleEvents>();
s.template registerType<CPackForClient, ChangeFormation>();
s.template registerType<CPackForClient, RemoveObject>(); s.template registerType<CPackForClient, RemoveObject>();
s.template registerType<CPackForClient, TryMoveHero>(); s.template registerType<CPackForClient, TryMoveHero>();
//s.template registerType<CPackForClient, SetGarrisons>(); //s.template registerType<CPackForClient, SetGarrisons>();

@ -2522,7 +2522,6 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
} }
} }
auto a = CArtifactInstance::createScroll(RandomGeneratorUtil::nextItem(out, gen->rand)->toSpell()); auto a = CArtifactInstance::createScroll(RandomGeneratorUtil::nextItem(out, gen->rand)->toSpell());
gen->map->addNewArtifactInstance(a);
obj->storedArtifact = a; obj->storedArtifact = a;
return obj; return obj;
}; };
@ -2760,7 +2759,6 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
obj->quest->isCustomFirst = obj->quest->isCustomNext = obj->quest->isCustomComplete = false; obj->quest->isCustomFirst = obj->quest->isCustomNext = obj->quest->isCustomComplete = false;
gen->banQuestArt(artid); gen->banQuestArt(artid);
gen->map->addQuest(obj);
this->questArtZone->possibleObjects.push_back (generateArtInfo(artid)); this->questArtZone->possibleObjects.push_back (generateArtInfo(artid));
@ -2799,7 +2797,6 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
obj->quest->isCustomFirst = obj->quest->isCustomNext = obj->quest->isCustomComplete = false; obj->quest->isCustomFirst = obj->quest->isCustomNext = obj->quest->isCustomComplete = false;
gen->banQuestArt(artid); gen->banQuestArt(artid);
gen->map->addQuest(obj);
this->questArtZone->possibleObjects.push_back(generateArtInfo(artid)); this->questArtZone->possibleObjects.push_back(generateArtInfo(artid));
@ -2823,7 +2820,6 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
obj->quest->isCustomFirst = obj->quest->isCustomNext = obj->quest->isCustomComplete = false; obj->quest->isCustomFirst = obj->quest->isCustomNext = obj->quest->isCustomComplete = false;
gen->banQuestArt(artid); gen->banQuestArt(artid);
gen->map->addQuest(obj);
this->questArtZone->possibleObjects.push_back(generateArtInfo(artid)); this->questArtZone->possibleObjects.push_back(generateArtInfo(artid));

@ -1913,7 +1913,7 @@ void CGameHandler::giveSpells(const CGTownInstance *t, const CGHeroInstance *h)
void CGameHandler::setBlockVis(ObjectInstanceID objid, bool bv) void CGameHandler::setBlockVis(ObjectInstanceID objid, bool bv)
{ {
SetObjectProperty sop(objid,2,bv); SetObjectProperty sop(objid, ObjProperty::BLOCKVIS, bv);
sendAndApply(&sop); sendAndApply(&sop);
} }
@ -1935,7 +1935,7 @@ bool CGameHandler::removeObject( const CGObjectInstance * obj )
void CGameHandler::setAmount(ObjectInstanceID objid, ui32 val) void CGameHandler::setAmount(ObjectInstanceID objid, ui32 val)
{ {
SetObjectProperty sop(objid,3,val); SetObjectProperty sop(objid, ObjProperty::PRIMARY_STACK_COUNT, val);
sendAndApply(&sop); sendAndApply(&sop);
} }
@ -2151,7 +2151,7 @@ bool CGameHandler::teleportHero(ObjectInstanceID hid, ObjectInstanceID dstid, ui
void CGameHandler::setOwner(const CGObjectInstance * obj, PlayerColor owner) void CGameHandler::setOwner(const CGObjectInstance * obj, PlayerColor owner)
{ {
PlayerColor oldOwner = getOwner(obj->id); PlayerColor oldOwner = getOwner(obj->id);
SetObjectProperty sop(obj->id, 1, owner.getNum()); SetObjectProperty sop(obj->id, ObjProperty::OWNER, owner.getNum());
sendAndApply(&sop); sendAndApply(&sop);
std::set<PlayerColor> playerColors = {owner, oldOwner}; std::set<PlayerColor> playerColors = {owner, oldOwner};
@ -3501,9 +3501,20 @@ bool CGameHandler::sendResources(ui32 val, PlayerColor player, Res::ERes r1, Pla
return true; return true;
} }
bool CGameHandler::setFormation( ObjectInstanceID hid, ui8 formation ) bool CGameHandler::setFormation(ObjectInstanceID hid, ui8 formation)
{ {
gs->getHero(hid)-> formation = formation; const CGHeroInstance *h = getHero(hid);
if(!h)
{
logGlobal->error("Hero doesn't exist!");
return false;
}
ChangeFormation cf;
cf.hid = hid;
cf.formation = formation;
sendAndApply(&cf);
return true; return true;
} }