1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Moved "max heroes on map per player", "max heroes available for player" to "defaultMods.json"

This commit is contained in:
Macron1Robot 2014-04-27 10:43:42 +04:00
parent 907caedb13
commit 8ec7a9b919
9 changed files with 64 additions and 15 deletions

View File

@ -2878,7 +2878,7 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
case Obj::MAGIC_WELL:
return h->mana < h->manaLimit();
case Obj::PRISON:
return ai->myCb->getHeroesInfo().size() < GameConstants::MAX_HEROES_PER_PLAYER;
return ai->myCb->getHeroesInfo().size() < VLC->modh->settings.MAX_HEROES_ON_MAP_PER_PLAYER);// GameConstants::MAX_HEROES_PER_PLAYER;
case Obj::BOAT:
return false;

View File

@ -114,7 +114,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#include <boost/range/algorithm.hpp>
#include <boost/thread.hpp>
#include <boost/variant.hpp>
#include <boost/foreach.hpp>
//#include <boost/foreach.hpp>
#include <boost/math/special_functions/round.hpp>

View File

@ -358,7 +358,7 @@ void CHeroGSlot::clickLeft(tribool down, bool previousState)
bool allow = true;
if(upg) //moving hero out of town - check if it is allowed
{
if(!hero && LOCPLINT->cb->howManyHeroes(false) >= 8)
if(!hero && LOCPLINT->cb->howManyHeroes(false) >= VLC->modh->settings.MAX_HEROES_ON_MAP_PER_PLAYER)
{
std::string tmp = CGI->generaltexth->allTexts[18]; //You already have %d adventuring heroes under your command.
boost::algorithm::replace_first(tmp,"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(false)));

View File

@ -3726,10 +3726,16 @@ CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj):
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[0]; //Cannot afford a Hero
recruit->block(true);
}
else if(LOCPLINT->cb->howManyHeroes(false) >= 8)
else if (LOCPLINT->castleInt && LOCPLINT->cb->howManyHeroes(true) >= VLC->modh->settings.MAX_HEROES_AVAILABLE_PER_PLAYER)
{
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[1]; //Cannot recruit. You already have %d Heroes.
boost::algorithm::replace_first(recruit->hoverTexts[0],"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes()));
boost::algorithm::replace_first(recruit->hoverTexts[0],"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(true)));
recruit->block(true);
}
else if ((!LOCPLINT->castleInt) && LOCPLINT->cb->howManyHeroes(false) >= VLC->modh->settings.MAX_HEROES_ON_MAP_PER_PLAYER)
{
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[1]; //Cannot recruit. You already have %d Heroes.
boost::algorithm::replace_first(recruit->hoverTexts[0], "%d", boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(false)));
recruit->block(true);
}
else if(LOCPLINT->castleInt && LOCPLINT->castleInt->town->visitingHero)

View File

@ -20,7 +20,10 @@
"MAX_BUILDING_PER_TURN" : 1,
"DWELLINGS_ACCUMULATE_CREATURES" : true,
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false,
"NEGATIVE_LUCK" : false
"NEGATIVE_LUCK" : false,
"MAX_HEROES_AVAILABLE_PER_PLAYER" : 16,
"MAX_HEROES_ON_MAP_PER_PLAYER" : 8
},
"modules":
{

View File

@ -506,15 +506,43 @@ CModHandler::CModHandler()
}
void CModHandler::loadConfigFromFile (std::string name)
bool CModHandler::loadConfigFromFile (std::string name)
{
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();
settings.MAX_HEROES_ON_MAP_PER_PLAYER = hardcodedFeatures["MAX_HEROES_ON_MAP_PER_PLAYER"].Float();
if (settings.MAX_HEROES_AVAILABLE_PER_PLAYER<=0)
{
logGlobal->errorStream() << "Error: MAX_HEROES_AVAILABLE must be higher than MAX_HEROES_ON_MAP";
return true;
}
if (settings.MAX_HEROES_ON_MAP_PER_PLAYER <= 0)
{
logGlobal->errorStream() << "Error: MAX_HEROES_AVAILABLE must be higher than MAX_HEROES_ON_MAP";
return true;
}
if (settings.MAX_HEROES_AVAILABLE_PER_PLAYER<settings.MAX_HEROES_ON_MAP_PER_PLAYER)
{
logGlobal->errorStream() << "Error: MAX_HEROES_AVAILABLE must be higher than MAX_HEROES_ON_MAP";
return true;
}
settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
if (settings.CREEP_SIZE<=0)
{
logGlobal->errorStream() << "Error: CREEP_SIZE must be positive value";
return true;
}
settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
settings.WEEKLY_GROWTH = hardcodedFeatures["CREEP_SIZE"].Float();
settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
settings.MAX_BUILDING_PER_TURN = hardcodedFeatures["MAX_BUILDING_PER_TURN"].Float();
if (settings.MAX_BUILDING_PER_TURN <= 0)
{
logGlobal->errorStream() << "Error: MAX_BUILDING_PER_TURN must be positive value";
return true;
}
settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
@ -523,6 +551,7 @@ void CModHandler::loadConfigFromFile (std::string name)
modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
modules.MITHRIL = gameModules["MITHRIL"].Bool();
return false;
}
// currentList is passed by value to get current list of depending mods
@ -787,7 +816,10 @@ CModInfo & CModHandler::getModData(TModID modId)
void CModHandler::initializeConfig()
{
loadConfigFromFile("defaultMods.json");
if (loadConfigFromFile("defaultMods.json")==true)
{
logGlobal->errorStream() << "Error: defaultMods.json HAS ERRORS";
}
}
void CModHandler::load()

View File

@ -199,7 +199,7 @@ class DLL_LINKAGE CModHandler
std::vector <TModID> activeMods;//active mods, in order in which they were loaded
CModInfo coreMod;
void loadConfigFromFile(std::string name);
bool loadConfigFromFile(std::string name);
bool hasCircularDependency(TModID mod, std::set <TModID> currentList = std::set <TModID>()) const;
@ -244,11 +244,13 @@ public:
int MAX_BUILDING_PER_TURN;
bool DWELLINGS_ACCUMULATE_CREATURES;
bool ALL_CREATURES_GET_DOUBLE_MONTHS;
int MAX_HEROES_AVAILABLE_PER_PLAYER;
int MAX_HEROES_ON_MAP_PER_PLAYER;
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;
h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS & MAX_HEROES_AVAILABLE_PER_PLAYER & MAX_HEROES_ON_MAP_PER_PLAYER;
}
} settings;

View File

@ -876,7 +876,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
{
int txt_id;
if(cb->getHeroCount(h->tempOwner,false) < GameConstants::MAX_HEROES_PER_PLAYER) //free hero slot
if (cb->getHeroCount(h->tempOwner, false) < VLC->modh->settings.MAX_HEROES_ON_MAP_PER_PLAYER)//GameConstants::MAX_HEROES_PER_PLAYER) //free hero slot
{
cb->changeObjPos(id,pos+int3(1,0,0),0);
//update hero parameters
@ -2277,10 +2277,12 @@ TResources CGTownInstance::dailyIncome() const
{
ret[i] = 0;
}
BOOST_FOREACH(TPairCBuilding p, town->buildings)
//BOOST_FOREACH(TPairCBuilding p, town->buildings)
for (TPairCBuilding p : town->buildings)
{
BuildingID buildingUpgrade;
BOOST_FOREACH(TPairCBuilding p2, town->buildings)
// BOOST_FOREACH(TPairCBuilding p2, town->buildings)
for (TPairCBuilding p2 : town->buildings)
{
if (p2.second->upgrade == p.first)
{

View File

@ -3181,9 +3181,13 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl
static const int GOLD_NEEDED = 2500;
//common preconditions
// if( (p->resources.at(Res::GOLD)<GOLD_NEEDED && complain("Not enough gold for buying hero!"))
// || (getHeroCount(player, false) >= GameConstants::MAX_HEROES_PER_PLAYER && complain("Cannot hire hero, only 8 wandering heroes are allowed!")))
if( (p->resources.at(Res::GOLD)<GOLD_NEEDED && complain("Not enough gold for buying hero!"))
|| (getHeroCount(player, false) >= GameConstants::MAX_HEROES_PER_PLAYER && complain("Cannot hire hero, only 8 wandering heroes are allowed!")))
return false;
|| ((!t) && (getHeroCount(player, false) >= VLC->modh->settings.MAX_HEROES_ON_MAP_PER_PLAYER && complain("Cannot hire hero, too many wandering heroes already!")))
|| ((t) && (getHeroCount(player, true) >= VLC->modh->settings.MAX_HEROES_AVAILABLE_PER_PLAYER && complain("Cannot hire hero, too many heroes garrizoned and wandering already!"))) )
return false;
if(t) //tavern in town
{