mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-14 02:33:51 +02:00
Merge pull request #175 from vmarkovtsev/feature/switch_retreat_no_troops
Feature/switch retreat no troops
This commit is contained in:
commit
3c84400262
@ -23,7 +23,8 @@
|
|||||||
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false,
|
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false,
|
||||||
"NEGATIVE_LUCK" : false,
|
"NEGATIVE_LUCK" : false,
|
||||||
"MAX_HEROES_AVAILABLE_PER_PLAYER" : 16,
|
"MAX_HEROES_AVAILABLE_PER_PLAYER" : 16,
|
||||||
"MAX_HEROES_ON_MAP_PER_PLAYER" : 8
|
"MAX_HEROES_ON_MAP_PER_PLAYER" : 8,
|
||||||
|
"WINNING_HERO_WITH_NO_TROOPS_RETREATS": true
|
||||||
|
|
||||||
},
|
},
|
||||||
"modules":
|
"modules":
|
||||||
|
@ -550,21 +550,42 @@ CModHandler::CModHandler()
|
|||||||
|
|
||||||
void CModHandler::loadConfigFromFile (std::string name)
|
void CModHandler::loadConfigFromFile (std::string name)
|
||||||
{
|
{
|
||||||
|
std::string paths;
|
||||||
|
for(auto& p : CResourceHandler::get()->getResourceNames(ResourceID("config/" + name)))
|
||||||
|
{
|
||||||
|
paths += p + ", ";
|
||||||
|
}
|
||||||
|
paths = paths.substr(0, paths.size() - 2);
|
||||||
|
logGlobal->debugStream() << "Loading hardcoded features settings from [" << paths << "], result:";
|
||||||
settings.data = JsonUtils::assembleFromFiles("config/" + name);
|
settings.data = JsonUtils::assembleFromFiles("config/" + name);
|
||||||
const JsonNode & hardcodedFeatures = settings.data["hardcodedFeatures"];
|
const JsonNode & hardcodedFeatures = settings.data["hardcodedFeatures"];
|
||||||
settings.MAX_HEROES_AVAILABLE_PER_PLAYER = hardcodedFeatures["MAX_HEROES_AVAILABLE_PER_PLAYER"].Float();
|
settings.MAX_HEROES_AVAILABLE_PER_PLAYER = hardcodedFeatures["MAX_HEROES_AVAILABLE_PER_PLAYER"].Float();
|
||||||
|
logGlobal->debugStream() << "\tMAX_HEROES_AVAILABLE_PER_PLAYER\t" << settings.MAX_HEROES_AVAILABLE_PER_PLAYER;
|
||||||
settings.MAX_HEROES_ON_MAP_PER_PLAYER = hardcodedFeatures["MAX_HEROES_ON_MAP_PER_PLAYER"].Float();
|
settings.MAX_HEROES_ON_MAP_PER_PLAYER = hardcodedFeatures["MAX_HEROES_ON_MAP_PER_PLAYER"].Float();
|
||||||
|
logGlobal->debugStream() << "\tMAX_HEROES_ON_MAP_PER_PLAYER\t" << settings.MAX_HEROES_ON_MAP_PER_PLAYER;
|
||||||
settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
|
settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
|
||||||
|
logGlobal->debugStream() << "\tCREEP_SIZE\t" << settings.CREEP_SIZE;
|
||||||
settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
|
settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
|
||||||
|
logGlobal->debugStream() << "\tWEEKLY_GROWTH\t" << settings.WEEKLY_GROWTH;
|
||||||
settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
|
settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
|
||||||
|
logGlobal->debugStream() << "\tNEUTRAL_STACK_EXP\t" << settings.NEUTRAL_STACK_EXP;
|
||||||
settings.MAX_BUILDING_PER_TURN = hardcodedFeatures["MAX_BUILDING_PER_TURN"].Float();
|
settings.MAX_BUILDING_PER_TURN = hardcodedFeatures["MAX_BUILDING_PER_TURN"].Float();
|
||||||
|
logGlobal->debugStream() << "\tMAX_BUILDING_PER_TURN\t" << settings.MAX_BUILDING_PER_TURN;
|
||||||
settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
|
settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tDWELLINGS_ACCUMULATE_CREATURES\t" << settings.DWELLINGS_ACCUMULATE_CREATURES;
|
||||||
settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
|
settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tALL_CREATURES_GET_DOUBLE_MONTHS\t" << settings.ALL_CREATURES_GET_DOUBLE_MONTHS;
|
||||||
|
settings.WINNING_HERO_WITH_NO_TROOPS_RETREATS = hardcodedFeatures["WINNING_HERO_WITH_NO_TROOPS_RETREATS"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tWINNING_HERO_WITH_NO_TROOPS_RETREATS\t" << settings.WINNING_HERO_WITH_NO_TROOPS_RETREATS;
|
||||||
const JsonNode & gameModules = settings.data["modules"];
|
const JsonNode & gameModules = settings.data["modules"];
|
||||||
modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
|
modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tSTACK_EXP\t" << modules.STACK_EXP;
|
||||||
modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
|
modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tSTACK_ARTIFACT\t" << modules.STACK_ARTIFACT;
|
||||||
modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
|
modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tCOMMANDERS\t" << modules.COMMANDERS;
|
||||||
modules.MITHRIL = gameModules["MITHRIL"].Bool();
|
modules.MITHRIL = gameModules["MITHRIL"].Bool();
|
||||||
|
logGlobal->debugStream() << "\tMITHRIL\t" << modules.MITHRIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// currentList is passed by value to get current list of depending mods
|
// currentList is passed by value to get current list of depending mods
|
||||||
|
@ -259,11 +259,21 @@ public:
|
|||||||
bool ALL_CREATURES_GET_DOUBLE_MONTHS;
|
bool ALL_CREATURES_GET_DOUBLE_MONTHS;
|
||||||
int MAX_HEROES_AVAILABLE_PER_PLAYER;
|
int MAX_HEROES_AVAILABLE_PER_PLAYER;
|
||||||
int MAX_HEROES_ON_MAP_PER_PLAYER;
|
int MAX_HEROES_ON_MAP_PER_PLAYER;
|
||||||
|
bool WINNING_HERO_WITH_NO_TROOPS_RETREATS;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & data & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP & MAX_BUILDING_PER_TURN;
|
h & data & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP & MAX_BUILDING_PER_TURN;
|
||||||
h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS & MAX_HEROES_AVAILABLE_PER_PLAYER & MAX_HEROES_ON_MAP_PER_PLAYER;
|
h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS &
|
||||||
|
MAX_HEROES_AVAILABLE_PER_PLAYER & MAX_HEROES_ON_MAP_PER_PLAYER;
|
||||||
|
if(version >= 756)
|
||||||
|
{
|
||||||
|
h & WINNING_HERO_WITH_NO_TROOPS_RETREATS;
|
||||||
|
}
|
||||||
|
else if(!h.saving)
|
||||||
|
{
|
||||||
|
WINNING_HERO_WITH_NO_TROOPS_RETREATS = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} settings;
|
} settings;
|
||||||
|
|
||||||
|
@ -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 = 755;
|
const ui32 version = 756;
|
||||||
const ui32 minSupportedVersion = 753;
|
const ui32 minSupportedVersion = 753;
|
||||||
|
|
||||||
class CISer;
|
class CISer;
|
||||||
|
@ -56,6 +56,15 @@ JsonNode::JsonNode(ResourceID && fileURI):
|
|||||||
*this = parser.parse(fileURI.getName());
|
*this = parser.parse(fileURI.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode::JsonNode(const ResourceID & fileURI):
|
||||||
|
type(DATA_NULL)
|
||||||
|
{
|
||||||
|
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||||
|
|
||||||
|
JsonParser parser(reinterpret_cast<char*>(file.first.get()), file.second);
|
||||||
|
*this = parser.parse(fileURI.getName());
|
||||||
|
}
|
||||||
|
|
||||||
JsonNode::JsonNode(ResourceID && fileURI, bool &isValidSyntax):
|
JsonNode::JsonNode(ResourceID && fileURI, bool &isValidSyntax):
|
||||||
type(DATA_NULL)
|
type(DATA_NULL)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +55,7 @@ public:
|
|||||||
explicit JsonNode(const char * data, size_t datasize);
|
explicit JsonNode(const char * data, size_t datasize);
|
||||||
//Create tree from JSON file
|
//Create tree from JSON file
|
||||||
explicit JsonNode(ResourceID && fileURI);
|
explicit JsonNode(ResourceID && fileURI);
|
||||||
|
explicit JsonNode(const ResourceID & fileURI);
|
||||||
explicit JsonNode(ResourceID && fileURI, bool & isValidSyntax);
|
explicit JsonNode(ResourceID && fileURI, bool & isValidSyntax);
|
||||||
//Copy c-tor
|
//Copy c-tor
|
||||||
JsonNode(const JsonNode ©);
|
JsonNode(const JsonNode ©);
|
||||||
|
@ -87,6 +87,20 @@ boost::optional<std::string> CFilesystemList::getResourceName(const ResourceID &
|
|||||||
return boost::optional<std::string>();
|
return boost::optional<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<std::string> CFilesystemList::getResourceNames(const ResourceID & resourceName) const
|
||||||
|
{
|
||||||
|
std::set<std::string> paths;
|
||||||
|
for(auto& loader : getResourcesWithName(resourceName))
|
||||||
|
{
|
||||||
|
auto rn = loader->getResourceName(resourceName);
|
||||||
|
if(rn)
|
||||||
|
{
|
||||||
|
paths.insert(*rn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::move(paths);
|
||||||
|
}
|
||||||
|
|
||||||
std::unordered_set<ResourceID> CFilesystemList::getFilteredFiles(std::function<bool(const ResourceID &)> filter) const
|
std::unordered_set<ResourceID> CFilesystemList::getFilteredFiles(std::function<bool(const ResourceID &)> filter) const
|
||||||
{
|
{
|
||||||
std::unordered_set<ResourceID> ret;
|
std::unordered_set<ResourceID> ret;
|
||||||
|
@ -59,15 +59,8 @@ class DLL_LINKAGE CFilesystemList : public ISimpleResourceLoader
|
|||||||
std::set<ISimpleResourceLoader *> writeableLoaders;
|
std::set<ISimpleResourceLoader *> writeableLoaders;
|
||||||
|
|
||||||
//FIXME: this is only compile fix, should be removed in the end
|
//FIXME: this is only compile fix, should be removed in the end
|
||||||
CFilesystemList(CFilesystemList &)
|
CFilesystemList(CFilesystemList &) = delete;
|
||||||
{
|
CFilesystemList &operator=(CFilesystemList &) = delete;
|
||||||
//class is not copyable
|
|
||||||
}
|
|
||||||
CFilesystemList &operator=(CFilesystemList &)
|
|
||||||
{
|
|
||||||
//class is not copyable
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CFilesystemList();
|
CFilesystemList();
|
||||||
@ -78,6 +71,7 @@ public:
|
|||||||
bool existsResource(const ResourceID & resourceName) const override;
|
bool existsResource(const ResourceID & resourceName) const override;
|
||||||
std::string getMountPoint() const override;
|
std::string getMountPoint() const override;
|
||||||
boost::optional<std::string> getResourceName(const ResourceID & resourceName) const override;
|
boost::optional<std::string> getResourceName(const ResourceID & resourceName) const override;
|
||||||
|
std::set<std::string> getResourceNames(const ResourceID & resourceName) const override;
|
||||||
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
||||||
bool createResource(std::string filename, bool update = false) override;
|
bool createResource(std::string filename, bool update = false) override;
|
||||||
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
|
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
|
||||||
|
@ -53,6 +53,22 @@ public:
|
|||||||
return boost::optional<std::string>();
|
return boost::optional<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all full names of matching resources, e.g. names of files in filesystem.
|
||||||
|
*
|
||||||
|
* @return std::set with names.
|
||||||
|
*/
|
||||||
|
virtual std::set<std::string> getResourceNames(const ResourceID & resourceName) const
|
||||||
|
{
|
||||||
|
std::set<std::string> result;
|
||||||
|
auto rn = getResourceName(resourceName);
|
||||||
|
if(rn)
|
||||||
|
{
|
||||||
|
result.insert(*rn);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of files that matches filter function
|
* Get list of files that matches filter function
|
||||||
*
|
*
|
||||||
|
@ -757,18 +757,21 @@ void CGameHandler::battleAfterLevelUp( const BattleResult &result )
|
|||||||
RemoveObject ro(finishingBattle->winnerHero->id);
|
RemoveObject ro(finishingBattle->winnerHero->id);
|
||||||
sendAndApply(&ro);
|
sendAndApply(&ro);
|
||||||
|
|
||||||
SetAvailableHeroes sah;
|
if (VLC->modh->settings.WINNING_HERO_WITH_NO_TROOPS_RETREATS)
|
||||||
sah.player = finishingBattle->victor;
|
{
|
||||||
sah.hid[0] = finishingBattle->winnerHero->subID;
|
SetAvailableHeroes sah;
|
||||||
sah.army[0].clear();
|
sah.player = finishingBattle->victor;
|
||||||
sah.army[0].setCreature(SlotID(0), finishingBattle->winnerHero->type->initialArmy.at(0).creature, 1);
|
sah.hid[0] = finishingBattle->winnerHero->subID;
|
||||||
|
sah.army[0].clear();
|
||||||
|
sah.army[0].setCreature(SlotID(0), finishingBattle->winnerHero->type->initialArmy.at(0).creature, 1);
|
||||||
|
|
||||||
if(const CGHeroInstance *another = getPlayer(finishingBattle->victor)->availableHeroes.at(0))
|
if(const CGHeroInstance *another = getPlayer(finishingBattle->victor)->availableHeroes.at(0))
|
||||||
sah.hid[1] = another->subID;
|
sah.hid[1] = another->subID;
|
||||||
else
|
else
|
||||||
sah.hid[1] = -1;
|
sah.hid[1] = -1;
|
||||||
|
|
||||||
sendAndApply(&sah);
|
sendAndApply(&sah);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user