Json configuration for towns

Holy! :open_mouth:

Yeah, I wonder what you will do with external dwelings, for example :stuck_out_tongue:

Short version: do not crash.

Long version:
I think that VCMI should handle such cases like empty tavern (all H3 classes have 0 chance to appear in Cove tavern), missing dwellings, 0 chance for all spells, etc correctly - right now most of them will cause crash.

There are also such issues like numeric ID’s - right now cove creatures were added to town using numeric ID’s - this will break with different list of mods. This should be fixed too.

After all of this is done - such missing objects like dwellings or heroes should be implemented as well.

Bravo!

Seeing how fast we are getting new units and new towns is kind of reassuring that our approach (rewriting the game from scratch) does have sense. :slight_smile:

Yes and no. :-p

I say “crash early”. We operate under certain assumptions. It could have been reasonably assumed (well, till now) that the dwellings won’t be missing. And if they are, it means that game installation is seriously broken and it’s better crash right now (with an apparent reason), rather then suppress the issue and let it break somewhere later (in place that may be not obviously related to the actual problem). However the assumptions change, as the engine evolves and new features are available. The code that is now offending may now have been that evil when it was written. [Or it could have… we do have many pieces I’m ashamed of. :stuck_out_tongue: ]

I remember specifically fixing the crash when there are no available heroes… must’ve got broken in the meantime, being not tested. [Some day I should certainly think about some kind of automatic tests for such issues.]
Other issues… I can fix it right away, if you provide me some “reproducibility package”, otherwise do it yourself. :wink:

How about using CCreature::refName as an string creature ID for config for the current (interim) period? It was useb by the H3 itself to cross-reference creatures.

Yeah. And VCMI 1.0 still have chances to beat WoG 3.59 time-wise :slight_smile:

I agree that delaying crash is a bad idea. But if crash can be avoided entirely (for example change dwelling to any other available) similar to how this is done for heroes then why not?

Anyway it seems that most crashes were from bugs in my “mod” - vcmi code is fine. Let’s see what happens after I hexedit Cove into another map - no bugs on Arrogance so far.

I noticed some already present checks. At least part of this crash was due to out of range array access - heroes from Cove supposed to have ID’s > HEROES_QUANTITY. Not something you expected back that time I suppose.

Of course. That string ID -> numeric ID conversion we discussed earlier is still TODO. More than enough time to implement it for next release.

This is just how upgrades for new creatures are already done. See CModhandler::RecreateHandlers:

	BOOST_FOREACH (auto creature, creatures)
	{
		creature->idNumber = VLC->creh->creatures.size(); //calculate next index for every used creature
		BOOST_FOREACH (auto bonus, creature->getBonusList())
		{
			bonus->sid = creature->idNumber;
		}
		VLC->creh->creatures.push_back (creature);
		//TODO: use refName?
		//if (creature->nameRef.size())
		//	VLC->creh->nameToID[creature->nameRef] = creature->idNumber;
		VLC->creh->nameToID[creature->nameSing] = creature->idNumber;

	}
	recreateAdvMapDefs();
	BOOST_FOREACH (auto creature, VLC->creh->creatures) //populate upgrades described with string
	{
		BOOST_FOREACH (auto upgradeName, creature->upgradeNames)
		{
			auto it = VLC->creh->nameToID.find(upgradeName);
			if (it != VLC->creh->nameToID.end())
			{
				creature->upgrades.insert (it->second);
			}
		}
	}

Good news: new town looks to be quite stable - no crashes anymore :slight_smile:

Now I need to correctly integrate this into modhandler.

But there is one ting that I want to do first: move creature loading (Json -> CCreature to be precise) to CreatureHandler. Instead ModHander should only store json config (and possibly make some guesses regarding mod content). Why?

  1. It will be more easy to manage - all loading will be done by existing handlers, ModHander will be used only for mod handling - set load order, set enabled\disabled mods, resolve string ID’s between different mods.

  2. Right now it is impossible for several mods to modify same object. This can be fixed easily by merging json tree from different mods before sending it to handlers.
    For example this will allow localization mods to consist from only localized strings instead of full config, rebalance mods won’t affect graphics or texts, etc.

Looks like a good idea, +1.

Go on, I planned Mod Handler to be somewhat more sophisticated, but it’s not really used. At the moment mod loading is as straightforward as possible.

String ID -> Numeric ID conversion is done. Already replaced all cases where VCMI used string ID’s (creature upgrades and initial hero armies) as well as all town-related cases (creatures’ factions and recruitable creatures)

Now heroes and external dwellings are probably the most notable missing pieces in new towns (+some graphical bugs in old code - pregame and messages)

What is about a light house when you conquer a city? You have not constructed it nor is the game loaded. Or is the construction function called when you conquer a city?

And what is about lighthouses? Not sure if I got your post correctly…

Lighthouse as well as some other buildings are implemented using our “bonus system” - player owning a town will receive +500 sea movement bonus. After conquering town all bonuses attached to the city will be transferred to new owner.

One more (hopefully last) breaking change into mod system - filesystem.json is merged with config/mod.json. I have one more change planned in FS but it won’t break compatibility with these mods.

Updated main menu mod is here: dl.dropbox.com/u/22372764/vcmi/ … w-menu.zip
Nothing really new here.

Now to HotA mod: dl.dropbox.com/u/22372764/vcmi/mods/cove.zip

Consist from two mods, right now these mods depend on each other:
cove-creatures: all 15 creatures from HotA, slightly reorganized filesystem.
cove-town: yes. This is town #10, town itself is mostly functional apart from two cove-specific buildings. Also comes with
a) some maps with playable Cove
b) Russian fonts (too lazy to translate text myself or to ask HotA team for translation)

Missing parts I know about:

  • Heroes. Including empty tavern. Makes town almost unplayable. :frowning:
  • External dwellings: will be replaced by dwellings from other factions.
  • Spell chances: In H3 different towns have different chances to get specific spells. Not implemented yet.
  • Grotto and Thieves Guild buildings. Still todo, unlikely to be implemented before next release.

Apart from this everything should work.

Now to mod system itself. How it works:

  • ResHandler finds all subdirectories in Mods/ and sends list to ModHandler
  • ModHandler is trying to load mod.json for each mod and generates list of active mods (+their load order). Deactivating mods is still todo but easy to implement.
  • ResHandler loads filesystems of active mods
    (rest of game loading)
  • ModHandler loads all content from mods.

Note that content (right now - creatures and factions description) is stored separately to keep mod.json small. Full descriptions will be assembled from one or several config files.
This allows to keep individual files small and some neat features like separating localizeable strings from the rest of file. Not a full-scale localization system but better than nothing.

Amazing job :smiley:

I don’t get why there are no heroes to recruit at all in Cove. Even if theere are no native heroes available, tavern should pick ones from other factions, shouldn’t it?

Don’t know that either. Especially why there is difference between mage guild and tavern? All hero classes have 0 chance to appear in Cove tavern so no heroes at all is technically a correct behavior. But the same should apply to spells - there is definitely a bug somewhere.

Empty tavern is definitely the biggest issue with Cove right now so I’m planning to fix that soon.

Updated my cove package, same link: dl.dropbox.com/u/22372764/vcmi/mods/cove.zip

  • some bugfixing (1-2 typos, some town screen glitches found on HC)
  • added missing puzzle map
  • added theoretically working mod with cove heroes. Still no code to use it but at least I know that all data is here.

In case if you haven’t noticed - hero and hero classes formats description are on wiki:
wiki.vcmi.eu/index.php?title=Hero_Classes_Format
wiki.vcmi.eu/index.php?title=Hero_Format

Interesting, good job.

I wonder how to handle hero specialty in this case. Original specialties were translated to bonuses with hard-coded parser (CGObjectHandler.cpp). It is also important than some of specialties grow with hero level, while others - do not. Probably some extension of hero specialty mechanism is a good thing to do soon.

Some of issues (unknown numeric ID’s of creatures for creature specialists) should be possible to fix using name resolver.
In this case ID’s should be full e.g. “creature.pirat” because bonuses can have different type - like spells. So specialty for archers specialist, Valeska, will look something like this:

{
    "type": "creatureSpec", // some hardcoded specialty type ID
    "val": 0,
    "subtype": 0,
    "info": "creature.archer" // already present ID that can be resolved to number by modHandler
}

(BTW - I think that this stringID -> number should be also implemented for bonus system itself - to allow bonuses like “hate”)

Anyway - I wanted to implement everything but specialties and give it to you for finishing - you know this code better than me.

So we need “level” parameter for calculation of bonus value in bonus system.
(And use it for growing artifacts and specialties)

One more update: dl.dropbox.com/u/22372764/vcmi/mods/cove.zip

Tavern is still empty, starting hero selection in pregame is a bit weird due to way VCMI checks for available heroes.
None of heroes have any specialty apart from text\icons.

Apart from this - everything should work.
And a nice screenshot :slight_smile: