mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Merge pull request #175 from vmarkovtsev/feature/switch_retreat_no_troops
Feature/switch retreat no troops
This commit is contained in:
@@ -23,7 +23,8 @@
|
||||
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false,
|
||||
"NEGATIVE_LUCK" : false,
|
||||
"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":
|
||||
|
@@ -550,21 +550,42 @@ CModHandler::CModHandler()
|
||||
|
||||
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);
|
||||
const JsonNode & hardcodedFeatures = settings.data["hardcodedFeatures"];
|
||||
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();
|
||||
logGlobal->debugStream() << "\tMAX_HEROES_ON_MAP_PER_PLAYER\t" << settings.MAX_HEROES_ON_MAP_PER_PLAYER;
|
||||
settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
|
||||
logGlobal->debugStream() << "\tCREEP_SIZE\t" << settings.CREEP_SIZE;
|
||||
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();
|
||||
logGlobal->debugStream() << "\tNEUTRAL_STACK_EXP\t" << settings.NEUTRAL_STACK_EXP;
|
||||
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();
|
||||
logGlobal->debugStream() << "\tDWELLINGS_ACCUMULATE_CREATURES\t" << settings.DWELLINGS_ACCUMULATE_CREATURES;
|
||||
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"];
|
||||
modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
|
||||
logGlobal->debugStream() << "\tSTACK_EXP\t" << modules.STACK_EXP;
|
||||
modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
|
||||
logGlobal->debugStream() << "\tSTACK_ARTIFACT\t" << modules.STACK_ARTIFACT;
|
||||
modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
|
||||
logGlobal->debugStream() << "\tCOMMANDERS\t" << modules.COMMANDERS;
|
||||
modules.MITHRIL = gameModules["MITHRIL"].Bool();
|
||||
logGlobal->debugStream() << "\tMITHRIL\t" << modules.MITHRIL;
|
||||
}
|
||||
|
||||
// currentList is passed by value to get current list of depending mods
|
||||
|
@@ -259,11 +259,21 @@ public:
|
||||
bool ALL_CREATURES_GET_DOUBLE_MONTHS;
|
||||
int MAX_HEROES_AVAILABLE_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)
|
||||
{
|
||||
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;
|
||||
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "mapping/CCampaignHandler.h" //for CCampaignState
|
||||
#include "rmg/CMapGenerator.h" // for CMapGenOptions
|
||||
|
||||
const ui32 version = 755;
|
||||
const ui32 version = 756;
|
||||
const ui32 minSupportedVersion = 753;
|
||||
|
||||
class CISer;
|
||||
|
@@ -56,6 +56,15 @@ JsonNode::JsonNode(ResourceID && fileURI):
|
||||
*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):
|
||||
type(DATA_NULL)
|
||||
{
|
||||
|
@@ -55,6 +55,7 @@ public:
|
||||
explicit JsonNode(const char * data, size_t datasize);
|
||||
//Create tree from JSON file
|
||||
explicit JsonNode(ResourceID && fileURI);
|
||||
explicit JsonNode(const ResourceID & fileURI);
|
||||
explicit JsonNode(ResourceID && fileURI, bool & isValidSyntax);
|
||||
//Copy c-tor
|
||||
JsonNode(const JsonNode ©);
|
||||
|
@@ -87,6 +87,20 @@ boost::optional<std::string> CFilesystemList::getResourceName(const ResourceID &
|
||||
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> ret;
|
||||
|
@@ -59,15 +59,8 @@ class DLL_LINKAGE CFilesystemList : public ISimpleResourceLoader
|
||||
std::set<ISimpleResourceLoader *> writeableLoaders;
|
||||
|
||||
//FIXME: this is only compile fix, should be removed in the end
|
||||
CFilesystemList(CFilesystemList &)
|
||||
{
|
||||
//class is not copyable
|
||||
}
|
||||
CFilesystemList &operator=(CFilesystemList &)
|
||||
{
|
||||
//class is not copyable
|
||||
return *this;
|
||||
}
|
||||
CFilesystemList(CFilesystemList &) = delete;
|
||||
CFilesystemList &operator=(CFilesystemList &) = delete;
|
||||
|
||||
public:
|
||||
CFilesystemList();
|
||||
@@ -78,6 +71,7 @@ public:
|
||||
bool existsResource(const ResourceID & resourceName) const override;
|
||||
std::string getMountPoint() 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;
|
||||
bool createResource(std::string filename, bool update = false) override;
|
||||
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
|
||||
|
@@ -53,6 +53,22 @@ public:
|
||||
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
|
||||
*
|
||||
|
@@ -757,6 +757,8 @@ void CGameHandler::battleAfterLevelUp( const BattleResult &result )
|
||||
RemoveObject ro(finishingBattle->winnerHero->id);
|
||||
sendAndApply(&ro);
|
||||
|
||||
if (VLC->modh->settings.WINNING_HERO_WITH_NO_TROOPS_RETREATS)
|
||||
{
|
||||
SetAvailableHeroes sah;
|
||||
sah.player = finishingBattle->victor;
|
||||
sah.hid[0] = finishingBattle->winnerHero->subID;
|
||||
@@ -771,6 +773,7 @@ void CGameHandler::battleAfterLevelUp( const BattleResult &result )
|
||||
sendAndApply(&sah);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGameHandler::prepareAttack(BattleAttack &bat, const CStack *att, const CStack *def, int distance, int targetHex)
|
||||
{
|
||||
|
Reference in New Issue
Block a user