mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Moved game Modules to config file.
This commit is contained in:
parent
d56e7c568a
commit
39d433c1c7
@ -21,6 +21,7 @@
|
||||
#include "../lib/CSpellHandler.h"
|
||||
#include "../lib/CArtHandler.h"
|
||||
#include "../lib/NetPacks.h" //ArtifactLocation
|
||||
#include "../lib/CModHandler.h"
|
||||
|
||||
#include "UIFramework/CGuiHandler.h"
|
||||
#include "UIFramework/CIntObjectClasses.h"
|
||||
@ -342,7 +343,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
|
||||
new CAnimImage("PSKIL42", 4, 0, 387, 51); //exp icon - Print it always?
|
||||
if (type) //not in fort window
|
||||
{
|
||||
if (GameConstants::STACK_EXP && type < COMMANDER)
|
||||
if (CGI->modh->modules.STACK_EXP && type < COMMANDER)
|
||||
{
|
||||
int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more
|
||||
new CLabel(488, 82, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(stack->experience));
|
||||
@ -391,7 +392,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
|
||||
}
|
||||
}
|
||||
|
||||
if (GameConstants::STACK_ARTIFACT)
|
||||
if (CGI->modh->modules.STACK_EXP)
|
||||
{
|
||||
creArt = true;
|
||||
}
|
||||
|
@ -6,7 +6,14 @@
|
||||
"CREEP_SIZE": 4000,
|
||||
"WEEKLY_GROWTH_PERCENT" : 10,
|
||||
"NEUTRAL_STACK_EXP_DAILY" : 500,
|
||||
"DWELLINGS_ACCUMULATE_CREATURES" : false,
|
||||
"DWELLINGS_ACCUMULATE_CREATURES" : true,
|
||||
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false
|
||||
},
|
||||
"modules":
|
||||
{
|
||||
"STACK_EXPERIENCE": true,
|
||||
"STACK_ARTIFACTS": true,
|
||||
"COMMANDERS": true,
|
||||
"MITHRIL": false //so far unused
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
#include "CGeneralTextHandler.h"
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include "VCMI_Lib.h"
|
||||
#include "CModHandler.h"
|
||||
#include "CSpellHandler.h"
|
||||
#include "CObjectHandler.h"
|
||||
#include "NetPacks.h"
|
||||
@ -361,7 +362,7 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
|
||||
|
||||
artifacts.push_back(&nart);
|
||||
}
|
||||
if (GameConstants::COMMANDERS)
|
||||
if (VLC->modh->modules.COMMANDERS)
|
||||
{ //TODO: move all artifacts config to separate json file
|
||||
const JsonNode config(ResourceID("config/commanders.json"));
|
||||
BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector())
|
||||
@ -819,7 +820,7 @@ void CArtHandler::addBonuses()
|
||||
|
||||
|
||||
//Stack artifact test
|
||||
if (GameConstants::STACK_ARTIFACT)
|
||||
if (VLC->modh->modules.STACK_ARTIFACT)
|
||||
{
|
||||
makeItCreatureArt(141);
|
||||
makeItCreatureArt(142);
|
||||
@ -863,7 +864,7 @@ void CArtHandler::addBonuses()
|
||||
artifacts[156].get()->setDescription ("+2 stack HP");
|
||||
|
||||
}
|
||||
if (GameConstants::COMMANDERS)
|
||||
if (VLC->modh->modules.COMMANDERS)
|
||||
{
|
||||
for (int i = 146; i <= 155; ++i)
|
||||
{
|
||||
@ -995,7 +996,7 @@ void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
|
||||
if (allowed[i])
|
||||
allowedArtifacts.push_back(artifacts[i]);
|
||||
}
|
||||
if (GameConstants::COMMANDERS) //allow all commander artifacts for testing
|
||||
if (VLC->modh->modules.COMMANDERS) //allow all commander artifacts for testing
|
||||
{
|
||||
for (int i = 146; i <= 155; ++i)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "../lib/CGameState.h"
|
||||
#include "../lib/JsonNode.h"
|
||||
#include "CHeroHandler.h"
|
||||
#include "CModHandler.h"
|
||||
|
||||
using namespace boost::assign;
|
||||
|
||||
@ -493,7 +494,7 @@ void CCreatureHandler::loadCreatures()
|
||||
//std::map<TBonusType, std::pair<std::string, std::string> >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE);
|
||||
//stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair<std::string, std::string>(it->second.first, it->second.second);
|
||||
|
||||
if (GameConstants::STACK_EXP) //reading default stack experience bonuses
|
||||
if (VLC->modh->modules.STACK_EXP) //reading default stack experience bonuses
|
||||
{
|
||||
auto textFile = CResourceHandler::get()->loadData(ResourceID("DATA/CREXPBON.TXT"));
|
||||
std::string buf((char*)textFile.first.get(), textFile.second);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "CCreatureHandler.h"
|
||||
#include "VCMI_Lib.h"
|
||||
#include "CModHandler.h"
|
||||
#include "CObjectHandler.h"
|
||||
#include "IGameCallback.h"
|
||||
#include "CGameState.h"
|
||||
@ -241,7 +242,7 @@ void CCreatureSet::setStackCount(TSlot slot, TQuantity count)
|
||||
{
|
||||
assert(hasStackAtSlot(slot));
|
||||
assert(stacks[slot]->count + count > 0);
|
||||
if (GameConstants::STACK_EXP && count > stacks[slot]->count)
|
||||
if (VLC->modh->modules.STACK_EXP && count > stacks[slot]->count)
|
||||
stacks[slot]->experience *= (count / static_cast<double>(stacks[slot]->count));
|
||||
stacks[slot]->count = count;
|
||||
armyChanged();
|
||||
@ -544,7 +545,7 @@ void CStackInstance::setType(const CCreature *c)
|
||||
if(type)
|
||||
{
|
||||
detachFrom(const_cast<CCreature*>(type));
|
||||
if (type->isMyUpgrade(c) && GameConstants::STACK_EXP)
|
||||
if (type->isMyUpgrade(c) && VLC->modh->modules.STACK_EXP)
|
||||
experience *= VLC->creh->expAfterUpgrade / 100.0;
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,12 @@ void CModHandler::loadConfigFromFile (std::string name)
|
||||
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();
|
||||
|
||||
auto gameModules = config["modules"];
|
||||
modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
|
||||
modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
|
||||
modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
|
||||
modules.MITHRIL = gameModules["MITHRIL"].Bool();
|
||||
}
|
||||
void CModHandler::saveConfigToFile (std::string name)
|
||||
{
|
||||
@ -81,10 +87,14 @@ void CModHandler::recreateHandlers()
|
||||
BOOST_FOREACH (auto art, allMods[mod].artifacts)
|
||||
{
|
||||
VLC->arth->artifacts.push_back (artifacts[art]);
|
||||
|
||||
//TODO: recreate types / limiters based on string id
|
||||
}
|
||||
BOOST_FOREACH (auto creature, allMods[mod].creatures)
|
||||
{
|
||||
VLC->creh->creatures.push_back (creatures[creature]);
|
||||
|
||||
//TODO: recreate upgrades and other properties based on string id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,12 +92,26 @@ public:
|
||||
}
|
||||
} settings;
|
||||
|
||||
struct DLL_LINKAGE gameModules
|
||||
{
|
||||
bool STACK_EXP;
|
||||
bool STACK_ARTIFACT;
|
||||
bool COMMANDERS;
|
||||
bool MITHRIL;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & STACK_EXP & STACK_ARTIFACT & COMMANDERS & MITHRIL;
|
||||
}
|
||||
} modules;
|
||||
|
||||
CModHandler();
|
||||
~CModHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & currentConfig;
|
||||
h & creatures & artifacts;
|
||||
h & allMods & activeMods & settings;
|
||||
h & allMods & activeMods & settings & modules;
|
||||
}
|
||||
};
|
||||
|
@ -774,7 +774,7 @@ void CGHeroInstance::initHero()
|
||||
}
|
||||
assert(validTypes());
|
||||
|
||||
if (GameConstants::COMMANDERS)
|
||||
if (VLC->modh->modules.COMMANDERS)
|
||||
{
|
||||
commander = new CCommanderInstance (VLC->creh->factionCommanders[type->heroType / 2]); //hopefully it returns town type
|
||||
commander->setArmyObj (castToArmyObj()); //TODO: separate function for setting commanders
|
||||
@ -3099,7 +3099,7 @@ void CGCreature::newTurn() const
|
||||
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)
|
||||
if (VLC->modh->modules.STACK_EXP)
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_EXP, VLC->modh->settings.NEUTRAL_STACK_EXP); //for testing purpose
|
||||
}
|
||||
void CGCreature::setPropertyDer(ui8 what, ui32 val)
|
||||
|
@ -85,12 +85,6 @@ namespace GameConstants
|
||||
|
||||
const ui16 BACKPACK_START = 19;
|
||||
const int ID_CATAPULT = 3, ID_LOCK = 145;
|
||||
|
||||
//game modules
|
||||
const bool STACK_EXP = true;
|
||||
const bool STACK_ARTIFACT = true; //now toggle for testing
|
||||
const bool COMMANDERS = true;
|
||||
const bool MITHRIL = false;
|
||||
}
|
||||
|
||||
// Enum declarations
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "CArtHandler.h"
|
||||
#include "CHeroHandler.h"
|
||||
#include "CObjectHandler.h"
|
||||
#include "CModHandler.h"
|
||||
#include "VCMI_Lib.h"
|
||||
#include "map.h"
|
||||
#include "CSpellHandler.h"
|
||||
@ -707,13 +708,14 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs )
|
||||
{
|
||||
const CCreature *srcType = src.army->getCreature(src.slot);
|
||||
TQuantity srcCount = src.army->getStackCount(src.slot);
|
||||
bool stackExp = VLC->modh->modules.STACK_EXP;
|
||||
|
||||
if(srcCount == count) //moving whole stack
|
||||
{
|
||||
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
|
||||
{
|
||||
assert(c == srcType);
|
||||
if (GameConstants::STACK_EXP)
|
||||
if (stackExp)
|
||||
{
|
||||
ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot);
|
||||
src.army->eraseStack(src.slot);
|
||||
@ -737,7 +739,7 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs )
|
||||
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
|
||||
{
|
||||
assert(c == srcType);
|
||||
if (GameConstants::STACK_EXP)
|
||||
if (stackExp)
|
||||
{
|
||||
ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot);
|
||||
src.army->changeStackCount(src.slot, -count);
|
||||
@ -754,7 +756,7 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs )
|
||||
{
|
||||
src.army->changeStackCount(src.slot, -count);
|
||||
dst.army->addToSlot(dst.slot, srcType->idNumber, count, false);
|
||||
if (GameConstants::STACK_EXP)
|
||||
if (stackExp)
|
||||
dst.army->setStackExp(dst.slot, src.army->getStackExperience(src.slot));
|
||||
}
|
||||
}
|
||||
@ -1074,7 +1076,7 @@ void BattleResult::applyGs( CGameState *gs )
|
||||
}
|
||||
}
|
||||
|
||||
if (GameConstants::STACK_EXP)
|
||||
if (VLC->modh->modules.STACK_EXP)
|
||||
{
|
||||
if (exp[0]) //checking local array is easier than dereferencing this crap twice
|
||||
gs->curB->belligerents[0]->giveStackExp(exp[0]);
|
||||
|
@ -264,7 +264,7 @@ void LibClasses::callWhenDeserializing()
|
||||
generaltexth = new CGeneralTextHandler;
|
||||
generaltexth->load();
|
||||
arth->loadArtifacts(true);
|
||||
modh->loadConfigFromFile ("default"); //TODO: remember last saved config
|
||||
//modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config
|
||||
}
|
||||
|
||||
LibClasses::~LibClasses()
|
||||
|
Loading…
Reference in New Issue
Block a user