Shemar
Educated
- Joined
- Oct 16, 2010
- Messages
- 260
Alex said:I may be very wrong here, but I think it is possible to restrict the special cases that apply to any single method before method invocation (at least if I create the predicates smartly enough) and what is the optimal order to test them. This means that the rules should run as quickly (asymptotically speaking) as if they were written by hand. There will be an overhead for all methods, but this may be set off by the fact that rule calculation is hardly as costly as other parts of the game, such as graphics or sound.
I am not sure how exactly you imagine it, but if yout pool of predicates is global, then no you will have to run through all of them. Of course you can have a list of attack predicates, a list of detection/stealth ones, a list of damage ones etc so you will only have to run through the relevant ones, but that is nowhere near as efficient as only testing for those that specifically apply to the given objects by linking them directly to these objects.
This is usually solved by adding these characteristicts to an encounter type class, a pointer to which you can also pass as a parameter, so any conditions that are global to the specific battle can also be taken into account.By the way, I don`t think that multiple inheritance alone can solve the problem. Well, it can solve a lot of the rules, but a few predicates aren't inherent about the object, just circumstantial. Stuff like "are you over forested terrain" or "is this an important battle". So, these would need to still be checked separated in each function.
Class inheritance is hard coded... sort of. This is where function pointers come in. The attack function for example can be just a pointer to a function passed on to every specific object, not the entire class. The result is that you can choose from a (possibly expandable via plugins) library af attack functions to assign to a newely created object at run time (or during level design via a toolset for the game).By the way, I have about the C++ multiple inheritance. Do I need to declare each possible combination of classes in the source code, or is it possible to create them dynamically? Like, if I have a Dwarf class and a warrior class and I want to create a warrior dwarf, do I need to create a class that inherits from both by hand? I think I read about a way using generics to create the class on the spot, but I think they still needed to be created during compile time.