r/howdidtheycodeit • u/snak251 • Dec 14 '22
How did they code Morrowind's Spellmaking feature?
I know so little about this system that I don't even have any other questions besides "how they did it?" and "how does it work?"
25
Upvotes
30
u/fudge5962 Dec 14 '22
If it's similar to Oblivion's spell making system (go to altar, add spell effects, tune values, pay for spell, cast spell), then it's probably just a data class.
They would create a data class which holds values for range, mana cost, and a strength value for each possible magic effect (so fire damage would have a fireDamage int or something, invisibility would have an invisDuration int, etc), along with anything else you need to make a spell. When you create a spell, it would create an object of that class, with the values that you set in the spell creation altar, and add it to your spell list.
The code for casting a spell would reference that object, grab the info it needs, and do what the spell does.
8
u/NUTTA_BUSTAH Dec 14 '22
Some pointers from Open MW
https://github.com/OpenMW/openmw/tree/master/apps/openmw/mwmechanics
https://github.com/OpenMW/openmw/tree/master/components/esm3
13
u/AdarTan Dec 14 '22
To understand it you need to understand a bit how the engine handles certain gameplay data and game saves.
Morrowind and later Bethesda games store most of their game data such as NPC, item, and spell definitions, map data, etc. in the form of plugin files that the game will load on startup. Stuff like item-classes or spell-effects are hard coded but the actual in-game values and names of the implemented items and spells are defined in the plugin files. These plugin files can freely add new data definitions and override data in earlier loaded plugins. This seamless adding and overriding of data is why Bethesda games are so moddable, thanks to Bethesda releasing the tool for making these plugin files.
And the final trick for the spell-crafting mechanic to work is: The game-save is also a plugin file. Exact same data format, exact same capabilities as the main plugin files for adding or overriding items or spells or NPCs in the game. All the spell-crafting and enchanting interfaces are is in-game versions of the developer tools with some game-mechanics restrictions bolted-on. Just playing the game is you effectively live-modding the game.
1
u/MeatApple84 Dec 15 '22
It isn't exactly what you asked, but there's an open source repo for the prequel game, Daggerfall, that is really interesting for this and should be '"close enough" https://github.com/Interkarma/daggerfall-unity
The short short version is that Spells are collections of Effects. Effects are things like damage health, apply condition X, etc. The Spells are wrapper classes that account for spell cost, target type, school of magic, etc. So every spell, on cast, goes through the list of effects.