After fiddling with this a lot on my own I have decided to try and write out a guide for making cool magic systems. All kinds of magic is possible in dwarf fortress even if the vanilla game only has necromancers, so here's how you could go about doing it.
I should clarify here that there are a lot of ways to add abilities, syndromes, powers, etc. My goal with this guide is to show how to create a system that dynamically adds magic to the world as a whole instead of just the player. As such, I won't be touching things like fort or adventure mode crafting or the ingestion of specific stuff to gain powers, as only the player can get magic that way. This guide explains how to make magic that both the player and NPCs can take advantage of. It also assumes you already have a basic understanding of the raws and raw modding. It is recommended you already have an understanding of necromancer, vampire, and werebeast mechanics at minimum.
Magic injection vectors:1. Slabs/Secrets: Slabs are used in the vanilla necromancy interaction. An individual desiring immortality (no other goals work) will be given one by a god, and learn the powers associated with it. Slabs are very useful, but also very tricky. For one, they do not work in fortress mode. Fort NPCs will never read a slab. They will read books or scrolls copied from the slab, though, and gain the power that way. Also, slabs will usually describe what power they teach, such as in vanilla the secrets of life and death. However, if you have more than one slab secret, the description will always default to the one which is lowest in alphabetical order, but only if the slabs share the same sphere (or have no spheres attached, in which case the sphereless slab description will overwrite ALL slab descriptions higher than them in alphabetical order). On that note, slabs are tied to divine spheres. The vanilla ones are usually associate with death, for example. Slab powers can be thematically linked to spheres this way, like having fire powers come from fire gods. Usually, but not always, someone will only read one slab in worldgen. Books which copy slab secret DO NOT suffer from the description bug and will accurately tell you what they teach. In addition, removing the line about IS_SECRET:MUNDANE_RECORDING_POSSIBLE will prevent a secret from coming with a slab at all or written into a book, and removing [IS_SECRET:MUNDANE_TEACHING_POSSIBLE] prevents the learner from teaching it to any apprentices they take on.
2. Curses: Curses come from toppling statues in and out of worldgen. Doing so in the vanilla game can result in becoming a werebeast or vampire. However, this can also be used to bestow magical powers. Curses are also useful because an individual may topple many statues in their lifetime and thus accrue many curses, making it easier for them to gain a lot of different magic types that way.
3. Infection: Infection happens both during and after worldgen. In vanilla, infection can happen from werebeasts bites. But this can be changed to grant magic abilities instead of a disease. It is a useful way to spread powers if you, for example, attach it to a powerful megabeast that "teaches" those brave enough to seek it out some secret, if they survive it of course.
4. Blood: This is one of the least effective methods of spreading secrets, at least in my experience, but it is worth mentioning. In worldgen, vampires can gain minions by offering, and sometimes delivering on, the promise of bestowing vampirism on them. This spreading system can be applied to any slab or curse based secret, giving it an alternative mode of transmission, but this has certain effects if applied to slab secrets. Specifically, it makes it so the slab will not tell you what power it teaches. While this is annoying, it serves an useful purpose of negating false information. Due to the aforementioned slab bug, where slabs with different powers that share a sphere will have incorrect descriptions, blanking out the description entirely can be more aesthetically pleasing while also preventing the player from being mislead. You can also change the learning vector from blood to, for example, brain matter, and since you can't eat sapient meat for whatever reason this would prevent this method from being used by players and would allow it to exist only to negate the slab bug. Also, blanking out the slab descriptions does not affect books, meaning if you make a book copy of a blank slab secret the book will tell you what secret you will learn.
Note that these vectors can be used separately or together. You could make an interaction which can be learned from both a curse AND a slab AND through blood, or just one of the three.
Tower Building:Necromancers build towers in worldgen, separating them from the rest of the world as distinct factions. However, this is not mandatory for slab-based secrets. Towers only appear under specific conditions and it can easily be controlled if a secret leads to tower building. Firstly, an individual must gain a zombie-raising ability, NOT the ability to revive the dead, summon creatures like bogeymen, or raise undead lieutenants, but basic mindless zombies. Secondly, it seems to only work if the zombie ability is the FIRST secret they learn, and needs to come from a Slab rather than any other method.
It should also be noted that a zombie-raiser and potential tower-builder of any kind will only wage wars on other factions if they are a mortal creature with the NO_AGING tag applied, and also any intelligent beings they produce from corpses using the FIT_FOR_RESURRECTION interactions are also mortal creatures with NO_AGING. This seems to be required for them to wage wars. Also, any intelligent beings they raise cannot themselves raise corpses.
However, if a power is taught that does not cause tower building, opposition to life, or madness, something very important happens. That individual will remain within the society they were born into and retain their original loyalties. This allows for magic users to rule as kings and fight as soldiers in battles, or be wandering adventurers and mercenaries. In short it allows for more traditional magic users that are popularly depicted in fantasy.
Immortality:Magic users can only appear from the historical figure population and of them only a small amount become magic users. As such, if they age and die, they will do very little given how small their population is. While it isn't necessary for magic systems to function, I personally recommend you give your magic users NO_AGING or transform them into immortal creatures if you want them to be relevant in worldgen. With this in mind, I personally would suggest designing your wizards more under the themes of rare and powerful individuals like Gandalf or Thulsa Doom than the typical level 1 dnd wizard.
Chance and Duration:In worldgen, percentages and time do not apply. If you make form of interaction which has a percentage-based chance of happening, it will usually default to successful. For example, if you made a custom necromancy interaction that has a 1% chance of turning the user into a lich, EVERY individual who learns this secret will become a lich, and this applies most interactions. Furthermore, time-based abilities also do not end until gameplay begins. If you, for example, added the NO_AGING tag but set it to end after a worldgen year, then it would not actually end through all of worldgen. However, the moment that individual entered your fort, or you visited them in adventure mode, they would immediately die as the game remembers that their immortality was supposed to end.
The one finicky area of this is interactions which apply tags such as NO_AGING. I believe that, for example, adding a percentage-based chance of NO_AGING will cause the game to run those odds immediately upon loading the individual in during gameplay. So someone who learns a secret with a 1% chance of NO_AGING will be treated as immortal during worldgen, but upon being loaded into gameplay the actual roll will occur, usually resulting in them dying instantly. When it comes to creature transformations and other interactions however, as far as I know it will always be treated as a 100% chance. In general it's weird so use these sorts of things with caution.
Magic Systems:A "Magic System" as defined by me is a comprehensive system of integrating magic into the world of dwarf fortress utilizing the above knowledge. Not just adding it to fort mode or making it available to your adventurer, but ensuring you will encounter magic users or superpowered individuals out and about in the world, and ensuring the player can interact and participate in it. I will list some "styles" that I find to be viable.
The Sphereless Single Spell System:The Single Spell system is set up so that every interaction that is part of it teaches a single spell, and none are tied to spheres, so any god can produce any spell, which creates thousands of magic users in longer worlds. So for example, a single slab/statue topple/etc would just teach "fireball" or "firejet" instead of multiple spells, though multiple spell interactions are possible as well. The design principle of this system is to allow for a wide variety of wizards who each have a unique arsenal of abilities, because instead of becoming pyromancers or necromancers, all wizards are unique individuals who have learned individual spells, allowing for a wide variety of combinations. An example of this is my system I use in my Long Night mod, where each individual spell can be learned in multiple ways, and magic users can be combined.
In fact, this system relies on spells being accessible through curses, because NPCs rarely read multiple slabs. What happens is that NPCs will read one slab, become immortal, and then will topple multiple statues to gain many curses. But because all spells can be learned from curses, what happens is they just learn new spells an become more powerful. You can alter how safe this is by increasing or decreasing the number of actual curses which could be bestowed on the individuals that do this. For example, if there are 5 learneable spells total, and 1 actual curse that turns you into an insane monster, then it's basically playing Russian roulette.
The downside is that there is often very little thematic cohesion unless the entire system has a specific theme. Again, in my Long Night mod, everything is based around nanomachines and energy transmission, so no matter what combination of "spells" you get, it all fits together thematically as techno-wizardry. But if you were to add many different flavors of spell, it would result in everyone having a thematically incoherent arsenal of spells. Though if that's okay with you and you are focused more on a wide variety of unique opponents, then this won't be a problem. Another downside is that due to the slab description bug, all slabs will be blank, and will not tell you what power you will learn.
Here is an example of a sphereless single spell interaction:
[INTERACTION:FIREBALL_SECRET]
[I_SOURCE:DEITY]
[IS_USAGE_HINT:MAJOR_CURSE]
[IS_HIST_STRING_1: was challenged in the spirit realm by ] (god name) was challenged by (NPC name)
[IS_HIST_STRING_2: who gained the spell "Fireball" from them]
[I_SOURCE:SECRET]
[IS_NAME:the spell "Fireball"]
[IS_SECRET_GOAL:IMMORTALITY]
[IS_SECRET:SUPERNATURAL_LEARNING_POSSIBLE]
[IS_SECRET:MUNDANE_RESEARCH_POSSIBLE]
[IS_SECRET:MUNDANE_TEACHING_POSSIBLE]
[IS_SECRET:MUNDANE_RECORDING_POSSIBLE:objects/text/book_instruction.txt:objects/text/secret_pyromancy.txt] remember to have a text name for it, like 'Pyromancy'
[I_SOURCE:INGESTION]
[IS_HIST_STRING_1: consumed the magical blood of ]
[IS_HIST_STRING_2: and gained their power]
[I_TARGET:A:CREATURE]
[IT_LOCATION:CONTEXT_CREATURE]
[IT_REQUIRES:CAN_LEARN]
[IT_REQUIRES:CAN_SPEAK]
[IT_CANNOT_HAVE_SYNDROME_CLASS:FIREBALL] so you don't learn the same spell more than once
[I_EFFECT:ADD_SYNDROME]
[IE_TARGET:A]
[IE_IMMEDIATE]
[IE_ARENA_NAME:Fireball]
[SYNDROME]
[SYN_CLASS:FIREBALL]
[CE_BODY_MAT_INTERACTION:MAT_TOKEN:RESERVED_BLOOD:START:0]
[CE:INTERACTION:FIREBALL_SECRET]
[CE:SYNDROME_TAG:SYN_INGESTED]
[CE:SYNDROME_TAG:SYN_INJECTED]
[CE_DISPLAY_NAME:NAME:mage:mages:mage:START:0] because all spells are available to all wizards they should all share a generic title
[CE_CAN_DO_INTERACTION:PROB:100:START:0:ABRUPT]
[CDI:ADV_NAME:Cast Fireball]
[CDI:USAGE_HINT:ATTACK]
[CDI:INTERACTION:MATERIAL_EMISSION]
[CDI:BP_REQUIRED:BY_CATEGORY:HAND]
[CDI:FLOW:FIREBALL]
[CDI:TARGET:C:LINE_OF_SIGHT]
[CDI:TARGET_RANGE:C:100]
[CDI:MAX_TARGET_NUMBER:C:1]
[CDI:WAIT_PERIOD:300]
[CDI:VERB:cast a ball of flame:casts a ball of flame:NA]
The Sphere-Oriented Single Spell System:This system works like the one above, but classifies spells into spheres rather than leaving them sphereless. This tends to result in fewer magic users overall in my experience but also somewhat fixes the thematic cohesiveness problem by restricting what spells someone can learn to what gods they are familiar with. A nation with a fire god would be able to produce pyromancers, one that doesn't can't.
The downside both the necessity of slab blanking and also that by tying yourself to spheres you need to come up with spells that fit all or most of the spheres to get a good amount of magic out there. It also restricts the kind of schools you can use, since they need to mesh with sphere themes.
The Sphere-Oriented School System:The School system is the clearest-cut one. It takes the vanilla necromancy method and uses it for different themed wizard types. So fire gods bestow a list of spells based around fire to make pyromancers, earth gods bestow earth-themed spells to make geomancers, and so on. As many "schools of magic" as spheres can exist. Because each sphere only has one school associated with it, the slabs will not misinform the user and don't need to be blanked out, which makes it more intuitive. The Spellcrafts mod is an example of this magic system.
The downside of this system is the lack of dynamicism. Because of how percentage-based interactions are weird in worldgen, every member of a specific school will have the exact same list of abilities, making encounters more predictable. In addition, it can be difficult to come up with comphrehensive schools for the less interesting or more abstract spheres, or avoiding overlap between similar spheres.
Here is an example of a sphere-oriented school interaction:
[INTERACTION:PYROMANCY_SECRET]
[I_SOURCE:SECRET]
[IS_NAME:the secrets of pyromancy]
[IS_SECRET_GOAL:IMMORTALITY]
[IS_SPHERE:FIRE] Only fire gods teach this. You can only have one sphere per interaction
[IS_SECRET:SUPERNATURAL_LEARNING_POSSIBLE]
[IS_SECRET:MUNDANE_RESEARCH_POSSIBLE]
[IS_SECRET:MUNDANE_TEACHING_POSSIBLE]
[IS_SECRET:MUNDANE_RECORDING_POSSIBLE:objects/text/book_instruction.txt:objects/text/secret_fireball.txt] remember to have a text name for it, like 'Pyromancy'
[I_SOURCE:INGESTION] I am keeping blood learning in but this is not strictly necessary
[IS_HIST_STRING_1: consumed the magical blood of ]
[IS_HIST_STRING_2: and gained their power]
[I_TARGET:A:CREATURE]
[IT_LOCATION:CONTEXT_CREATURE]
[IT_REQUIRES:CAN_LEARN]
[IT_REQUIRES:CAN_SPEAK]
[IT_CANNOT_HAVE_SYNDROME_CLASS:PYROMANCY] so you don't learn the same school more than once
[I_EFFECT:ADD_SYNDROME]
[IE_TARGET:A]
[IE_IMMEDIATE]
[IE_ARENA_NAME:Pyromancer]
[SYNDROME]
[SYN_CLASS:PYROMANCY]
[CE_BODY_MAT_INTERACTION:MAT_TOKEN:RESERVED_BLOOD:START:0]
[CE:INTERACTION:FIREBALL_SECRET]
[CE:SYNDROME_TAG:SYN_INGESTED]
[CE:SYNDROME_TAG:SYN_INJECTED]
[CE_DISPLAY_NAME:NAME:pyromancer:pyromancers:pyromantic:START:0] because you will probably only learn one school you can keep the title unique
You then add as many interactions as you like below, there's just two here but there could be dozens. Bear in mind an NPC will use all of them at once if it can though.
[CE_CAN_DO_INTERACTION:PROB:100:START:0:ABRUPT]
[CDI:ADV_NAME:Cast Fireball]
[CDI:USAGE_HINT:ATTACK]
[CDI:INTERACTION:MATERIAL_EMISSION]
[CDI:BP_REQUIRED:BY_CATEGORY:HAND]
[CDI:FLOW:FIREBALL]
[CDI:TARGET:C:LINE_OF_SIGHT]
[CDI:TARGET_RANGE:C:100]
[CDI:MAX_TARGET_NUMBER:C:1]
[CDI:WAIT_PERIOD:300]
[CDI:VERB:cast a ball of flame:casts a ball of flame:NA]
[CE_CAN_DO_INTERACTION:PROB:100:START:0:ABRUPT]
[CDI:ADV_NAME:Cast Firejet]
[CDI:USAGE_HINT:ATTACK]
[CDI:INTERACTION:MATERIAL_EMISSION]
[CDI:BP_REQUIRED:BY_CATEGORY:HAND]
[CDI:FLOW:FIREJET]
[CDI:TARGET:C:TOUCHABLE]
[CDI:TARGET_RANGE:C:100]
[CDI:MAX_TARGET_NUMBER:C:1]
[CDI:WAIT_PERIOD:300]
[CDI:VERB:cast a jet of flame:casts a jet of flame:NA]
The Sphereless Single Spell/School Hybrid:This is by far one of the most tedious but, in my opinion, potentially rewarding systems. It merges the thematic cohesiveness of the School system with the dynamicism of the Single Spell system. Essentially, one can prevent someone who learns a certain spell from learning other spell through the use of IT_CANNOT_HAVE_SYNDROME_CLASS. So, let us say there are just two lists of learnable spells, List 1 with all water-themed learnable interactions, and List 2 with fire-themed ones. Let us say that all the spells of List 1 add the tag [SYN_CLASS:WATERSPELL] and List 2 spells add [SYN_CLASS:FIRESPELL]
So what you do is then add [IT_CANNOT_HAVE_SYNDROME_CLASS:WATERSPELL] to List 2, and [IT_CANNOT_HAVE_SYNDROME_CLASS:FIRESPELL] to list 1.
What this means is that if an individual learns a List 1 spell, it can only learn other List 1 spells. Meaning, these individuals will be "locked into" a water-themed spell list, but how many they have is dynamically generated by their actions. Some might only have one spell, others might have all of them.
And you could add even more spell lists to this, but it would work such that every new school you add, you have to go to all the old schools and add a new IT_CANNOT_HAVE_SYNDROME_CLASS category to them, which is the tedious part I mentioned.
This allows for you to add as many different schools as you like, using any kind of theming, and keep it all both thematically cohesive and dynamically generated.
The downside to this is that it is tedious to both add and remove schools, and would have to use slabs with no description so you wouldn't know which school of magic you were locking yourself into until you already read the slab.
The Sphere-Oriented Single Spell/School Hybrid:This is like the Sphereless Single Spell/School Hybrid, but with one additional restriction. All spells of a particular list are tied to one or more spheres, making them even rarer. Pyromancers could only appear in places with a fire god, for example, but would still have to learn their spells individually. The advantage of this is making magic even more cohesive by tying magical schools to a particular god which represents that sphere.
It has the same advantages and downsides of the above hybrid school including needing to make the slab descriptions blank. In the sphereless version of this system, you could have three schools, such as witchcraft, shamanism, and holy magic, and any god could teach any of them, meaning there will be a large amount of magic users belonging to one of the three schools. Here, those three would be tied to specific spheres an you need to fill out all the other ones to have a meaningful population of magic users.
So, Spheres or Sphereless:As you can see the use of spheres is a pretty major distinguishing factor between magic systems. Broadly speaking, the advantages of spheres is that they take advantage of the current religion system by ensuring those who worship a given god are likely to obtain powers associated with that god. On the other hand, sphereless systems let every god bestow any power, which is less thematically cohesive from a divine portfolio perspective but allows for a greater number and wider variety of magic users to appear.
Personally, I prefer sphereless systems for that reason, especially because it allows the player to create their own categories of magic rather than be restricted to the sphere portfolios, but both options have their pros and cons.
AND BEAR THIS IN MIND:Everything I have described above is taking the existing bare-bones filler system and pushing it to its limits, and it will all be replaced and thrown out when the Real Magic Update happens 10 years from now, so if you go making a very big and complicated magic system using these methods accept the fact you will eventually have to throw it all out and start over even if you keep updating it until Myth and Magic.