1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Created large number of missing objects in configs

Minor bugfixes in code
This commit is contained in:
Ivan Savenko 2014-06-17 14:57:47 +03:00
parent 09d595e385
commit 0a71e89f58
8 changed files with 123 additions and 44 deletions

View File

@ -1,6 +1,13 @@
{
/// These are objects that can not be configured, either due to
/// their hardcoded status or because they don't have any configurable functionality
"prison" : {
"index" :62,
"handler": "prison",
"types" : {
"prison" : { "index" : 0 }
}
},
"altarOfSacrifice" : { "index" :2, "handler": "market" },
"tradingPost" : { "index" :221, "handler": "market" },
@ -38,7 +45,6 @@
"magicWell" : { "index" :49, "handler": "magicWell" },
"obelisk" : { "index" :57, "handler": "obelisk" },
"oceanBottle" : { "index" :59, "handler": "sign" },
"prison" : { "index" :62, "handler": "hero" },
"pyramid" : { "index" :63, "handler": "pyramid" },
"scholar" : { "index" :81, "handler": "scholar" },
"shipyard" : { "index" :87, "handler": "shipyard" },

View File

@ -1,7 +1,7 @@
{
/// These are objects that have subtypes that change various aspects of their mechanics
/// Should be made configurable (either directly or via other parts of modding system ASAP)
/// Editing these objects either directly or via mod may have negative effect on game
/// Editing these objects either directly or via mod may have negative effect on game since they are handled by engine
// subtype: artifact ID
"artifact" : {
@ -50,13 +50,13 @@
}
},
"types" : {
"wood" : { "index" : 0 },
"mercury" : { "index" : 1 },
"ore" : { "index" : 2 },
"sulfur" : { "index" : 3 },
"crystal" : { "index" : 4 },
"gems" : { "index" : 5 },
"gold" : { "index" : 6 },
"wood" : { "index" : 0, "templates" : { "res" : { "animation" : "AVTwood0.def" } } },
"mercury" : { "index" : 1, "templates" : { "res" : { "animation" : "AVTmerc0.def" } } },
"ore" : { "index" : 2, "templates" : { "res" : { "animation" : "AVTore0.def" } } },
"sulfur" : { "index" : 3, "templates" : { "res" : { "animation" : "AVTsulf0.def" } } },
"crystal" : { "index" : 4, "templates" : { "res" : { "animation" : "AVTcrys0.def" } } },
"gems" : { "index" : 5, "templates" : { "res" : { "animation" : "AVTgems0.def" } } },
"gold" : { "index" : 6, "templates" : { "res" : { "animation" : "AVTgold0.def" } } },
"mithril" : { "index" : 7 } // TODO: move to WoG?
}
},
@ -99,19 +99,93 @@
"visitableFrom" : [ "+++", "+-+", "+++" ],
"mask" : [ "VVV", "VAV" ]
}
},
"types" : {
"evil" : { "index" : 0 },
"good" : { "index" : 1 },
"neutral" : { "index" : 2 },
}
},
// subtype: color of guard
"borderGuard" : { "index" :9, "handler": "borderGuard" },
"borderGate" : { "index" :212, "handler": "borderGate" },
"keymasterTent" : { "index" :10, "handler": "keymaster" },
// subtype: different content
"creatureBank" : { "index" :16, "handler": "bank" },
"borderGuard" : {
"index" :9,
"handler": "borderGuard",
"types" : {
"lblue" : { "index" : 0 },
"green" : { "index" : 1 },
"red" : { "index" : 2 },
"dblue" : { "index" : 3 },
"brown" : { "index" : 4 },
"purple" : { "index" : 5 },
"white" : { "index" : 6 },
"black" : { "index" : 7 }
}
},
"borderGate" : {
"index" :212,
"handler": "borderGate",
"types" : {
"lblue" : { "index" : 0 },
"green" : { "index" : 1 },
"red" : { "index" : 2 },
"dblue" : { "index" : 3 },
"brown" : { "index" : 4 },
"purple" : { "index" : 5 },
"white" : { "index" : 6 },
"black" : { "index" : 7 }
}
},
"keymasterTent" : {
"index" :10,
"handler": "keymaster",
"types" : {
"lblue" : { "index" : 0 },
"green" : { "index" : 1 },
"red" : { "index" : 2 },
"dblue" : { "index" : 3 },
"brown" : { "index" : 4 },
"purple" : { "index" : 5 },
"white" : { "index" : 6 },
"black" : { "index" : 7 }
}
},
// subtype: different revealed areas
"cartographer" : { "index" :13, "handler": "cartographer" },
"cartographer" : {
"index" :13,
"handler": "cartographer",
"types" : {
"water" : { "index" : 0 },
"land" : { "index" : 1 },
"subterra" : { "index" : 2 }
}
},
// subtype: resource ID
"mine" : {
"index" :53,
"handler": "mine",
"types" : {
"sawmill" : { "index" : 0 },
"alchemistLab" : { "index" : 1 },
"orePit" : { "index" : 2 },
"sulfurDune" : { "index" : 3 },
"crystalCavern" : { "index" : 4 },
"gemPond" : { "index" : 5 },
"goldMine" : { "index" : 6 },
}
},
"abandonedMine" : {
"index" :220,
"handler": "mine",
"types" : {
"mine" : { "index" : 7 }
}
},
// subtype: different content
"creatureBank" : { "index" :16, "handler": "bank" },
// subtype: 0 = normal, 1 = anti-magic
"garrisonHorizontal" : { "index" :33, "handler": "garrison" },
@ -121,13 +195,9 @@
"monolithOneWayEntrance" : { "index" :43, "handler": "teleport" },
"monolithOneWayExit" : { "index" :44, "handler": "teleport" },
"monolithTwoWay" : { "index" :45, "handler": "teleport" },
// subtype: resource ID
"mine" : { "index" :53, "handler": "mine" },
"abandonedMine" : { "index" :220, "handler": "mine" },
// subtype: different appearance. That's all?
"seerHut" : { "index" :83, "handler": "seerHut" },
"seerHut" : { "index" :83, "handler": "seerHut" },
// subtype: level
"randomDwellingLvl" : { "index" :217, "handler": "dwelling" },

View File

@ -45,11 +45,11 @@ DLL_LINKAGE void preinitDLL(CConsoleHandler *Console)
DLL_LINKAGE void loadDLLClasses()
{
// try
try
{
VLC->init();
}
// HANDLE_EXCEPTION;
HANDLE_EXCEPTION;
}
const IBonusTypeHandler * LibClasses::getBth() const

View File

@ -30,7 +30,7 @@ CObjectClassesHandler::CObjectClassesHandler()
#define SET_HANDLER(STRING, TYPENAME) handlerConstructors[STRING] = std::make_shared<CDefaultObjectTypeHandler<TYPENAME> >
// list of all known handlers, hardcoded for now since the only way to add new objects is via C++ code
//WARNING: should be in sync with registerTypesMapObjectTypes function
//Note: should be in sync with registerTypesMapObjectTypes function
SET_HANDLER_CLASS("configurable", CRewardableConstructor);
SET_HANDLER_CLASS("dwelling", CDwellingInstanceConstructor);
SET_HANDLER_CLASS("hero", CHeroInstanceConstructor);
@ -66,6 +66,7 @@ CObjectClassesHandler::CObjectClassesHandler()
SET_HANDLER("onceVisitable", CGOnceVisitable);
SET_HANDLER("pandora", CGPandoraBox);
SET_HANDLER("pickable", CGPickable);
SET_HANDLER("prison", CGHeroInstance);
SET_HANDLER("pyramid", CGPyramid);
SET_HANDLER("questGuard", CGQuestGuard);
SET_HANDLER("resource", CGResource);
@ -85,10 +86,9 @@ CObjectClassesHandler::CObjectClassesHandler()
#undef SET_HANDLER
}
template<typename Container>
void readTextFile(Container & objects, std::string path)
std::vector<JsonNode> CObjectClassesHandler::loadLegacyData(size_t dataSize)
{
CLegacyConfigParser parser(path);
CLegacyConfigParser parser("Data/Objects.txt");
size_t totalNumber = parser.readNumber(); // first line contains number of objects to read and nothing else
parser.endLine();
@ -97,24 +97,18 @@ void readTextFile(Container & objects, std::string path)
ObjectTemplate templ;
templ.readTxt(parser);
parser.endLine();
typename Container::key_type key(templ.id.num, templ.subid);
objects.insert(std::make_pair(key, templ));
std::pair<si32, si32> key(templ.id.num, templ.subid);
legacyTemplates.insert(std::make_pair(key, templ));
}
}
std::vector<JsonNode> CObjectClassesHandler::loadLegacyData(size_t dataSize)
{
readTextFile(legacyTemplates, "Data/Objects.txt");
//readTextFile(legacyTemplates, "Data/Heroes.txt");
std::vector<JsonNode> ret(dataSize);// create storage for 256 objects
assert(dataSize == 256);
CLegacyConfigParser parser("Data/ObjNames.txt");
CLegacyConfigParser namesParser("Data/ObjNames.txt");
for (size_t i=0; i<256; i++)
{
ret[i]["name"].String() = parser.readString();
parser.endLine();
ret[i]["name"].String() = namesParser.readString();
namesParser.endLine();
}
return ret;
}
@ -358,15 +352,19 @@ std::vector<ObjectTemplate> AObjectTypeHandler::getTemplates() const
std::vector<ObjectTemplate> AObjectTypeHandler::getTemplates(si32 terrainType) const// FIXME: replace with ETerrainType
{
std::vector<ObjectTemplate> ret = getTemplates();
std::vector<ObjectTemplate> templates = getTemplates();
std::vector<ObjectTemplate> filtered;
std::copy_if(ret.begin(), ret.end(), std::back_inserter(filtered), [&](const ObjectTemplate & obj)
std::copy_if(templates.begin(), templates.end(), std::back_inserter(filtered), [&](const ObjectTemplate & obj)
{
return obj.canBePlacedAt(ETerrainType(terrainType));
});
// it is possible that there are no templates usable on specific terrain. In this case - return list before filtering
return filtered.empty() ? ret : filtered;
// H3 defines allowed terrains in a weird way - artifacts, monsters and resources have faulty masks here
// Perhaps we should re-define faulty templates and remove this workaround (already done for resources)
if (type == Obj::ARTIFACT || type == Obj::MONSTER)
return templates;
else
return filtered;
}
boost::optional<ObjectTemplate> AObjectTypeHandler::getOverride(si32 terrainType, const CGObjectInstance * object) const

View File

@ -336,7 +336,8 @@ void CGObjectInstance::setType(si32 ID, si32 subID)
//recalculate blockvis tiles - new appearance might have different blockmap than before
cb->gameState()->map->removeBlockVisTiles(this, true);
this->appearance = VLC->objtypeh->getHandlerFor(ID, subID)->getTemplates(tile.terType).at(0);
auto handler = VLC->objtypeh->getHandlerFor(ID, subID);
appearance = handler->getTemplates(tile.terType).at(0);
cb->gameState()->map->addBlockVisTiles(this);
}

View File

@ -213,6 +213,9 @@ void ObjectTemplate::readJson(const JsonNode &node)
allowedTerrains.insert(ETerrainType(i));
}
if (allowedTerrains.empty())
logGlobal->warnStream() << "Loaded template without allowed terrains!";
auto charToTile = [&](const char & ch) -> ui8
{
switch (ch)

View File

@ -100,6 +100,7 @@ void registerTypesMapObjectTypes(Serializer &s)
REGISTER_GENERIC_HANDLER(CGEvent);
REGISTER_GENERIC_HANDLER(CGGarrison);
REGISTER_GENERIC_HANDLER(CGHeroPlaceholder);
REGISTER_GENERIC_HANDLER(CGHeroInstance);
REGISTER_GENERIC_HANDLER(CGKeymasterTent);
REGISTER_GENERIC_HANDLER(CGLighthouse);
REGISTER_GENERIC_HANDLER(CGMagi);

View File

@ -107,7 +107,7 @@ void CPregameServer::handleConnection(CConnection *cpc)
while(state == RUNNING) boost::this_thread::sleep(boost::posix_time::milliseconds(50));
}
}
}
}
catch (const std::exception& e)
{
boost::unique_lock<boost::recursive_mutex> queueLock(mx);