1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-29 22:57:49 +02:00

Moved game Modules to config file.

This commit is contained in:
DjWarmonger 2012-08-24 09:37:52 +00:00
parent d56e7c568a
commit 39d433c1c7
11 changed files with 55 additions and 24 deletions

View File

@ -21,6 +21,7 @@
#include "../lib/CSpellHandler.h" #include "../lib/CSpellHandler.h"
#include "../lib/CArtHandler.h" #include "../lib/CArtHandler.h"
#include "../lib/NetPacks.h" //ArtifactLocation #include "../lib/NetPacks.h" //ArtifactLocation
#include "../lib/CModHandler.h"
#include "UIFramework/CGuiHandler.h" #include "UIFramework/CGuiHandler.h"
#include "UIFramework/CIntObjectClasses.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? new CAnimImage("PSKIL42", 4, 0, 387, 51); //exp icon - Print it always?
if (type) //not in fort window 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 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)); 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; creArt = true;
} }

View File

@ -6,7 +6,14 @@
"CREEP_SIZE": 4000, "CREEP_SIZE": 4000,
"WEEKLY_GROWTH_PERCENT" : 10, "WEEKLY_GROWTH_PERCENT" : 10,
"NEUTRAL_STACK_EXP_DAILY" : 500, "NEUTRAL_STACK_EXP_DAILY" : 500,
"DWELLINGS_ACCUMULATE_CREATURES" : false, "DWELLINGS_ACCUMULATE_CREATURES" : true,
"ALL_CREATURES_GET_DOUBLE_MONTHS" : false "ALL_CREATURES_GET_DOUBLE_MONTHS" : false
},
"modules":
{
"STACK_EXPERIENCE": true,
"STACK_ARTIFACTS": true,
"COMMANDERS": true,
"MITHRIL": false //so far unused
} }
} }

View File

@ -5,6 +5,7 @@
#include "CGeneralTextHandler.h" #include "CGeneralTextHandler.h"
#include <boost/random/linear_congruential.hpp> #include <boost/random/linear_congruential.hpp>
#include "VCMI_Lib.h" #include "VCMI_Lib.h"
#include "CModHandler.h"
#include "CSpellHandler.h" #include "CSpellHandler.h"
#include "CObjectHandler.h" #include "CObjectHandler.h"
#include "NetPacks.h" #include "NetPacks.h"
@ -361,7 +362,7 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
artifacts.push_back(&nart); artifacts.push_back(&nart);
} }
if (GameConstants::COMMANDERS) if (VLC->modh->modules.COMMANDERS)
{ //TODO: move all artifacts config to separate json file { //TODO: move all artifacts config to separate json file
const JsonNode config(ResourceID("config/commanders.json")); const JsonNode config(ResourceID("config/commanders.json"));
BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector()) BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector())
@ -819,7 +820,7 @@ void CArtHandler::addBonuses()
//Stack artifact test //Stack artifact test
if (GameConstants::STACK_ARTIFACT) if (VLC->modh->modules.STACK_ARTIFACT)
{ {
makeItCreatureArt(141); makeItCreatureArt(141);
makeItCreatureArt(142); makeItCreatureArt(142);
@ -863,7 +864,7 @@ void CArtHandler::addBonuses()
artifacts[156].get()->setDescription ("+2 stack HP"); artifacts[156].get()->setDescription ("+2 stack HP");
} }
if (GameConstants::COMMANDERS) if (VLC->modh->modules.COMMANDERS)
{ {
for (int i = 146; i <= 155; ++i) for (int i = 146; i <= 155; ++i)
{ {
@ -995,7 +996,7 @@ void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
if (allowed[i]) if (allowed[i])
allowedArtifacts.push_back(artifacts[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) for (int i = 146; i <= 155; ++i)
{ {

View File

@ -6,6 +6,7 @@
#include "../lib/CGameState.h" #include "../lib/CGameState.h"
#include "../lib/JsonNode.h" #include "../lib/JsonNode.h"
#include "CHeroHandler.h" #include "CHeroHandler.h"
#include "CModHandler.h"
using namespace boost::assign; 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); //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); //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")); auto textFile = CResourceHandler::get()->loadData(ResourceID("DATA/CREXPBON.TXT"));
std::string buf((char*)textFile.first.get(), textFile.second); std::string buf((char*)textFile.first.get(), textFile.second);

View File

@ -3,6 +3,7 @@
#include "CCreatureHandler.h" #include "CCreatureHandler.h"
#include "VCMI_Lib.h" #include "VCMI_Lib.h"
#include "CModHandler.h"
#include "CObjectHandler.h" #include "CObjectHandler.h"
#include "IGameCallback.h" #include "IGameCallback.h"
#include "CGameState.h" #include "CGameState.h"
@ -241,7 +242,7 @@ void CCreatureSet::setStackCount(TSlot slot, TQuantity count)
{ {
assert(hasStackAtSlot(slot)); assert(hasStackAtSlot(slot));
assert(stacks[slot]->count + count > 0); 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]->experience *= (count / static_cast<double>(stacks[slot]->count));
stacks[slot]->count = count; stacks[slot]->count = count;
armyChanged(); armyChanged();
@ -544,7 +545,7 @@ void CStackInstance::setType(const CCreature *c)
if(type) if(type)
{ {
detachFrom(const_cast<CCreature*>(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; experience *= VLC->creh->expAfterUpgrade / 100.0;
} }

View File

@ -55,6 +55,12 @@ void CModHandler::loadConfigFromFile (std::string name)
settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float(); settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool(); settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
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();
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) void CModHandler::saveConfigToFile (std::string name)
{ {
@ -81,10 +87,14 @@ void CModHandler::recreateHandlers()
BOOST_FOREACH (auto art, allMods[mod].artifacts) BOOST_FOREACH (auto art, allMods[mod].artifacts)
{ {
VLC->arth->artifacts.push_back (artifacts[art]); VLC->arth->artifacts.push_back (artifacts[art]);
//TODO: recreate types / limiters based on string id
} }
BOOST_FOREACH (auto creature, allMods[mod].creatures) BOOST_FOREACH (auto creature, allMods[mod].creatures)
{ {
VLC->creh->creatures.push_back (creatures[creature]); VLC->creh->creatures.push_back (creatures[creature]);
//TODO: recreate upgrades and other properties based on string id
} }
} }
} }

View File

@ -92,12 +92,26 @@ public:
} }
} settings; } 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();
~CModHandler(); ~CModHandler();
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & currentConfig;
h & creatures & artifacts; h & creatures & artifacts;
h & allMods & activeMods & settings; h & allMods & activeMods & settings & modules;
} }
}; };

View File

@ -774,7 +774,7 @@ void CGHeroInstance::initHero()
} }
assert(validTypes()); 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 = new CCommanderInstance (VLC->creh->factionCommanders[type->heroType / 2]); //hopefully it returns town type
commander->setArmyObj (castToArmyObj()); //TODO: separate function for setting commanders 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_COUNT, std::min (power/1000 , (ui32)VLC->modh->settings.CREEP_SIZE)); //set new amount
cb->setObjProperty(id, ObjProperty::MONSTER_POWER, power); //increase temppower 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 cb->setObjProperty(id, ObjProperty::MONSTER_EXP, VLC->modh->settings.NEUTRAL_STACK_EXP); //for testing purpose
} }
void CGCreature::setPropertyDer(ui8 what, ui32 val) void CGCreature::setPropertyDer(ui8 what, ui32 val)

View File

@ -85,12 +85,6 @@ namespace GameConstants
const ui16 BACKPACK_START = 19; const ui16 BACKPACK_START = 19;
const int ID_CATAPULT = 3, ID_LOCK = 145; 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 // Enum declarations

View File

@ -6,6 +6,7 @@
#include "CArtHandler.h" #include "CArtHandler.h"
#include "CHeroHandler.h" #include "CHeroHandler.h"
#include "CObjectHandler.h" #include "CObjectHandler.h"
#include "CModHandler.h"
#include "VCMI_Lib.h" #include "VCMI_Lib.h"
#include "map.h" #include "map.h"
#include "CSpellHandler.h" #include "CSpellHandler.h"
@ -707,13 +708,14 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs )
{ {
const CCreature *srcType = src.army->getCreature(src.slot); const CCreature *srcType = src.army->getCreature(src.slot);
TQuantity srcCount = src.army->getStackCount(src.slot); TQuantity srcCount = src.army->getStackCount(src.slot);
bool stackExp = VLC->modh->modules.STACK_EXP;
if(srcCount == count) //moving whole stack if(srcCount == count) //moving whole stack
{ {
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
{ {
assert(c == srcType); 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); ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot);
src.army->eraseStack(src.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 if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
{ {
assert(c == srcType); 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); ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot);
src.army->changeStackCount(src.slot, -count); src.army->changeStackCount(src.slot, -count);
@ -754,7 +756,7 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs )
{ {
src.army->changeStackCount(src.slot, -count); src.army->changeStackCount(src.slot, -count);
dst.army->addToSlot(dst.slot, srcType->idNumber, count, false); 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)); 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 if (exp[0]) //checking local array is easier than dereferencing this crap twice
gs->curB->belligerents[0]->giveStackExp(exp[0]); gs->curB->belligerents[0]->giveStackExp(exp[0]);

View File

@ -264,7 +264,7 @@ void LibClasses::callWhenDeserializing()
generaltexth = new CGeneralTextHandler; generaltexth = new CGeneralTextHandler;
generaltexth->load(); generaltexth->load();
arth->loadArtifacts(true); arth->loadArtifacts(true);
modh->loadConfigFromFile ("default"); //TODO: remember last saved config //modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config
} }
LibClasses::~LibClasses() LibClasses::~LibClasses()