Determining effect order
First idea is to have a preset list of categories. Every effect/spell is assigned to a category and the categories are all processed in a certain order. There's two downsides to this: If I have an effect that needs to be applied between "category A" and "category B", there's no way to do that without introducing another category. The other issue is, if two effects are both in "category B" and I now have an effect that needs to happen between them, I'm out of luck.
Second idea is to assign a priority to each effect/spell as a float value. Effects/spells with a higher value are applied first. The problem with this one is that if I have "effect B" that needs to be applied after "effect A" and before "effect C", but A has a value of 5, and C has a value of 10, no value assigned to B will create that order.
And the last idea, which is downright awful, is to have each effect (optionally) define every effect that needs to be applied before (or after) it. Aside from the issue of creating circular dependencies, this would really get out of hand if you tried to make an effect that always has to be applied last. Either it would have to specify every single effect must occur before it, or every other effect would have to specify that that effect must come after it.
I feel like the 2nd idea is the most workable, but I want to be as accommodating to modding as possible, so people don't run into issues like "oh well, they set the priority of this spell too high, there's no way to have my effect run in the proper order". Basically all of these work in a closed system when you know every spell/effect that could be applied, but are problematic when mixed with mods. Thoughts?
A fourth approach would be to ask for a total order statement. I.e. all possible effects are presented in a chain (or perhaps a tree), and a new effect needs to be inserted into this chain to become available in the game. This pushes the responsibility to the designer.
Second idea is to assign a priority to each effect/spell as a float value. Effects/spells with a higher value are applied first. The problem with this one is that if I have "effect B" that needs to be applied after "effect A" and before "effect C", but A has a value of 5, and C has a value of 10, no value assigned to B will create that order.
The example shows a design mistake: If C has a priority of 10, and A has a priority of 5, then this is already a statement about the order of A and C. If now B comes into play and contradicts the already established order, then there is a break in the logic.
Now, because you can't have both A before C and A after C, you perhaps wanted to say that the order of A and C is arbitrary until B comes into play. This may be expressed by letting A and C have the same priority first, but requires automatic priority adaption. This solution is a mix of both the category as well as the priority solution, because it allows to shift the category of a particular effect a bit towards another category, so that is is mainly category 1 but a bit also category 2.
On the other hand, if the above situation may occur legally, then obviously you need to cancel either the one or the other effect. Either the second effect cannot take place until the former situation has been settled, or else the new situation overrides the older one.
A fourth approach would be to ask for a total order statement. I.e. all possible effects are presented in a chain (or perhaps a tree), and a new effect needs to be inserted into this chain to become available in the game. This pushes the responsibility to the designer.
What makes this different from solution 3? And how does it handle the case where Mod A adds 5 effects and then Mod B adds another 10 effects. It seems like each mod would have to know about every other mod.
Now, because you can't have both A before C and A after C, you perhaps wanted to say that the order of A and C is arbitrary until B comes into play. This may be expressed by letting A and C have the same priority first, but requires automatic priority adaption.
That is exactly the situation I wanted to express with that example. How would you code/design such an automatic priority adaption system? It seems to just end up with solution 3.
If you have impossible ordering constraints (A before B, but B before A), it's a mistake regardless of how they are represented.
Of the three representations in the original posts, the third one is by far the most appropriate one because it represents an order relationship correctly; in particular, new "effects" can be added anywhere in the dependency graph, without running into trouble with missing gaps between "layers" or "priorities".
It isn't awful; realistically, a few dependencies imply a node's position with respect to all nodes that matter. For example, many different attack types, with various precedences among themselves, can be specified to happen before explosion rendering; then if you say that the two "final" steps of creating debris objects and swapping in damaged sprites and models take place after explosions, they automatically take place after all attacks too.
The actual game engine should probably process a list of "pass" objects in sequence, but turning a direct acyclic graph of precedences into a processing order is a computer's job; avoid unneeded bookkeeping for game content authors.
If you have impossible ordering constraints (A before B, but B before A), it's a mistake regardless of how they are represented.
Of course. I didn't state this but in that example, effects A and C don't actually care what order they're in, but since the system would require a priority be assigned for all effects, they were arbitrarily assigned those orders. When just A and C are used, it made no difference, but when B came into the equation, it caused a problem.
Of the three representations in the original posts, the third one is by far the most appropriate one because it represents an order relationship correctly; in particular, new "effects" can be added anywhere in the dependency graph, without running into trouble with missing gaps between "layers" or "priorities".
It isn't awful; realistically, a few dependencies imply a node's position with respect to all nodes that matter. For example, many different attack types, with various precedences among themselves, can be specified to happen before explosion rendering; then if you say that the two "final" steps of creating debris objects and swapping in damaged sprites and models take place after explosions, they automatically take place after all attacks too.
Correct me if I'm wrong, but I think we're thinking about where the order is assigned in two different ways. You seem to be thinking of it in terms of the spell specifying the order of each of its effects. I was thinking about it in more global terms, as in "effect C" always occurs before "effect B" regardless of whether its applied by a "spell A", "spell B" or "spell C". I'm not sure there would be a case where you'd want to have the order be one way for one spell and then entirely different for another spell given the same effects.
Also, I think the order is far more important when considering the effects currently on an entity. Entities can have effects like "damage reduction" or "fire resistance" applied to them from separate spells. Now when the entity is attacked, these effects will inspect the incoming damage and modify it. This is where I feel the order is important.
Consider a zombie that has the following two effects applied to it: "Converts healing spells to 'harm' spells, and 'harm' spells to healing spells" and "All damage is reduced by 50%". If you cast a 'harm' spell on the zombie, one of two things can happen, depending on the order those effects are applied. If the damage reduct is applied first, the zombie will be healed by 50%. If the conversion is applied first, then the damage reduct won't apply (since it's now a heal instead of a damage spell), and the zombie will be healed for 100%.
How would you specify the order in this case?
On top of that you might also want to create processing groups to batch process different effect types before others. Effects that convert effects to other effects should probably come first so that before other effects are applied, conversions are made so that later effects can be applied to the conversions.
IMHO a reliable non-compromise solution doesn't exist as soon as you want to mix the input from 2 independent sources and the criteria isn't already defined for both sources.
Could you please give an example of how an effect should work, and how 2 effects from unaware sources have to be integrated?
I agree that there probably isn't a perfect solution to this. But just because I can't think of one doesn't mean one doesn't exist . I wanted to see if anyone could come up with "better" solutions. DrEvil's idea is pretty good and I may end up going with that.
It's difficult to give an exact answer without knowing exactly what effects can... well... affect in your game, but ideally, you don't want effect order to matter. There are ways to design such a system so that effects can be applied in an arbitrary order, and an intermediary layer can sort out the side-effects and make sure objects are actually affected in a sane manner.
The analog is a graphics engine which renders in two phases: the first phase collecting all the objects that need to render (or in your case, all the effects that need to be applied), and then breaking down the objects into their component pieces and rendering them in the correct order to minimize state changes, handle transparency properly, etc. (which in your case is breaking down a high-level effect into its low-level state changes and sorting them appropriately).