mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- Some hardcoded settings will now be read from config/defaultMods.json
- Fixed AI crash when it was placed in closed and safe area
This commit is contained in:
parent
aa326491a3
commit
edbc7f1223
@ -984,7 +984,7 @@ void VCAI::makeTurn()
|
||||
++dangerousObjects;
|
||||
}
|
||||
}
|
||||
ui64 averageDanger = totalDanger / dangerousObjects;
|
||||
ui64 averageDanger = totalDanger / std::max(dangerousObjects, 1);
|
||||
if (dangerousObjects && averageDanger > h->getHeroStrength())
|
||||
{
|
||||
setGoal (h, CGoal(GATHER_ARMY).sethero(h).setvalue(averageDanger * SAFE_ATTACK_CONSTANT).setisAbstract(true));
|
||||
|
12
config/defaultMods.json
Normal file
12
config/defaultMods.json
Normal file
@ -0,0 +1,12 @@
|
||||
// default configuration for mod system loaded at launch
|
||||
|
||||
{
|
||||
"hardcodedFeatures" :
|
||||
{
|
||||
"CREEP_SIZE": 4000,
|
||||
"WEEKLY_GROWTH_PERCENT" : 10,
|
||||
"NEUTRAL_STACK_EXP_DAILY" : 500,
|
||||
"DWELLINGS_ACCUMULATE_CREATURES" : false,
|
||||
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#define ALLCREATURESGETDOUBLEMONTHS false
|
||||
|
||||
class CCreatureHandler;
|
||||
class CCreature;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "StdInc.h"
|
||||
#include "CModHandler.h"
|
||||
#include "JsonNode.h"
|
||||
|
||||
/*
|
||||
* CModHandler.h, part of VCMI engine
|
||||
@ -25,6 +26,7 @@ CModHandler::CModHandler()
|
||||
{
|
||||
VLC->modh = this;
|
||||
|
||||
loadConfigFromFile ("defaultMods");
|
||||
//CResourceHandler::loadModsFilesystems(); //scan for all mods
|
||||
//TODO: mod filesystem is already initialized at LibClasses launch
|
||||
//TODO: load default (last?) config
|
||||
@ -43,9 +45,30 @@ creID CModHandler::addNewCreature (CCreature * cre)
|
||||
}
|
||||
|
||||
void CModHandler::loadConfigFromFile (std::string name)
|
||||
{}
|
||||
{
|
||||
|
||||
const JsonNode config(ResourceID("config/" + name + ".json"));
|
||||
auto hardcodedFeatures = config["hardcodedFeatures"];
|
||||
|
||||
settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
|
||||
settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
|
||||
settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
|
||||
settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
|
||||
settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
|
||||
}
|
||||
void CModHandler::saveConfigToFile (std::string name)
|
||||
{}
|
||||
{
|
||||
//JsonNode savedConf = config;
|
||||
//JsonNode schema(ResourceID("config/defaultSettings.json"));
|
||||
|
||||
//savedConf.Struct().erase("session");
|
||||
//savedConf.minimize(schema);
|
||||
|
||||
CResourceHandler::get()->createResource("config/" + name +".json");
|
||||
|
||||
std::ofstream file(CResourceHandler::get()->getResourceName(ResourceID("config/" + name +".json")), std::ofstream::trunc);
|
||||
//file << savedConf;
|
||||
}
|
||||
void CModHandler::recreateHandlers()
|
||||
{
|
||||
//TODO: consider some template magic to unify all handlers?
|
||||
|
@ -77,12 +77,27 @@ public:
|
||||
void saveConfigToFile (std::string name);
|
||||
void recreateHandlers();
|
||||
|
||||
struct DLL_LINKAGE hardcodedFeatures
|
||||
{
|
||||
int CREEP_SIZE; // neutral stacks won't grow beyond this number
|
||||
int WEEKLY_GROWTH; //percent
|
||||
int NEUTRAL_STACK_EXP;
|
||||
bool DWELLINGS_ACCUMULATE_CREATURES;
|
||||
bool ALL_CREATURES_GET_DOUBLE_MONTHS;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & CREEP_SIZE & WEEKLY_GROWTH & NEUTRAL_STACK_EXP;
|
||||
h & DWELLINGS_ACCUMULATE_CREATURES & ALL_CREATURES_GET_DOUBLE_MONTHS;
|
||||
}
|
||||
} settings;
|
||||
|
||||
CModHandler();
|
||||
~CModHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & creatures & artifacts;
|
||||
h & allMods & activeMods;
|
||||
h & allMods & activeMods & settings;
|
||||
}
|
||||
};
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "CDefObjInfoHandler.h"
|
||||
#include "CHeroHandler.h"
|
||||
#include "CSpellHandler.h"
|
||||
#include "CModHandler.h"
|
||||
#include "../client/CSoundBase.h"
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include "CTownHandler.h"
|
||||
@ -1718,7 +1719,7 @@ void CGDwelling::newTurn() const
|
||||
{
|
||||
CCreature *cre = VLC->creh->creatures[creatures[i].second[0]];
|
||||
TQuantity amount = cre->growth * (1 + cre->valOfBonuses(Bonus::CREATURE_GROWTH_PERCENT)/100) + cre->valOfBonuses(Bonus::CREATURE_GROWTH);
|
||||
if (GameConstants::DWELLINGS_ACCUMULATE_CREATURES)
|
||||
if (VLC->modh->settings.DWELLINGS_ACCUMULATE_CREATURES)
|
||||
sac.creatures[i].first += amount;
|
||||
else
|
||||
sac.creatures[i].first = amount;
|
||||
@ -3092,14 +3093,14 @@ void CGCreature::initObj()
|
||||
}
|
||||
void CGCreature::newTurn() const
|
||||
{//Works only for stacks of single type of size up to 2 millions
|
||||
if (stacks.begin()->second->count < GameConstants::CREEP_SIZE && cb->getDate(1) == 1 && cb->getDate(0) > 1)
|
||||
if (stacks.begin()->second->count < VLC->modh->settings.CREEP_SIZE && cb->getDate(1) == 1 && cb->getDate(0) > 1)
|
||||
{
|
||||
ui32 power = temppower * (100 + GameConstants::WEEKLY_GROWTH)/100;
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_COUNT, std::min (power/1000 , (ui32)GameConstants::CREEP_SIZE)); //set new amount
|
||||
ui32 power = temppower * (100 + VLC->modh->settings.WEEKLY_GROWTH)/100;
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_COUNT, std::min (power/1000 , (ui32)VLC->modh->settings.CREEP_SIZE)); //set new amount
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_POWER, power); //increase temppower
|
||||
}
|
||||
if (GameConstants::STACK_EXP)
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_EXP, 500); //for testing purpose
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_EXP, VLC->modh->settings.NEUTRAL_STACK_EXP); //for testing purpose
|
||||
}
|
||||
void CGCreature::setPropertyDer(ui8 what, ui32 val)
|
||||
{
|
||||
|
@ -80,10 +80,7 @@ namespace GameConstants
|
||||
const int CREATURES_PER_TOWN = 7; //without upgrades
|
||||
const int MAX_BUILDING_PER_TURN = 1;
|
||||
const int SPELL_LEVELS = 5;
|
||||
const int CREEP_SIZE = 4000; // neutral stacks won't grow beyond this number
|
||||
const int WEEKLY_GROWTH = 10; //percent
|
||||
const int AVAILABLE_HEROES_PER_PLAYER = 2;
|
||||
const bool DWELLINGS_ACCUMULATE_CREATURES = false;
|
||||
const int SPELLBOOK_GOLD_COST = 500;
|
||||
|
||||
const ui16 BACKPACK_START = 19;
|
||||
|
@ -1175,7 +1175,7 @@ void CGameHandler::newTurn()
|
||||
if (monthType < 40) //double growth
|
||||
{
|
||||
n.specialWeek = NewTurn::DOUBLE_GROWTH;
|
||||
if (ALLCREATURESGETDOUBLEMONTHS)
|
||||
if (VLC->modh->settings.ALL_CREATURES_GET_DOUBLE_MONTHS)
|
||||
{
|
||||
std::pair<int,int> newMonster(54, VLC->creh->pickRandomMonster(boost::ref(rand)));
|
||||
n.creatureid = newMonster.second;
|
||||
|
Loading…
Reference in New Issue
Block a user