ID:151803
Mar 7 2009, 1:15 pm
|
|
How should I go about this? In an older project, I set up a massive list of all attacks and their ranges, etc. and had the AI follow that list. However, I found it rather annoying to constantly have to update it, and I always disliked having giant lists at compile time. Any more efficient, easy to maintain methods?
|
In response to The Magic Man
|
|
Interesting ideas, though I wish to make it even more flexible than that, to the point where you could create new NPCs with different sets of attacks on the fly. That's the good thing about my old system, even though it was extremely annoying to keep up to date.
|
In response to Jeff8500
|
|
I don't see why a system like that could not be done with the method I use.
Though, I'd imagine it would require the use of lists, a lot, but I doubt there is a method of doing this that would not require the use of lists extensively. For example, the Mage obj in my example could when created pick a skill to be used from a list, fireball, iceball or lightning bolt. (maybe these would be some sort of datum stored in a list somewhere, which the mage references) The rest would work basically the same from there on, but it would result in the mage knowing a different skill each time a new one is created (again, referencing a datum and executing a proc the datum has to cast a spell would be an easy way of doing this without having to add an if condition for each possible spell the mage could use). |
The basic AI works like...
Start loop
Find target
If get target, move to it
If close to target, attack it
If no target, wander randomly
loop proc again
Each of those steps (except for the loop) is a very basic, and general proc, incapable of doing anything unique or special.
However, the whole point of this is so that I can define more unique behaviour for specific enemies.
A normal enemies attack proc might just consist of attack and nothing else. A Mage enemies might be "if got mp, use fireball, otherwise just attack".
Here is an example of the sort of code I use (though, this code was never intended to be read by anyone else, is not the best code ever and is only being posted so you get an idea of how this system works). (I am more or less just copying and pasting this code, so there is a lot of things in it that are not relivent here)
That would be the "base" AI, so to say. Then for a mage I would do something like...
This basically means, whenever /mob/Mage activates the proc AI_Action, it will use fireball if it has enough MP, otherwise it will simply attack.
In a similar fashion, I could overwrite the find target proc, so it only returns players that are for example weakened. (by adding a if(hp<50) return target)
A system like this might not be the best ever, but I find it is much better than trying to use one huge proc for AIs. It is much easier to add and change unique actions for specific mobs, and allows for much more flexible and customizable AIs in general, without having to use one huge AI which you constantly have to add new conditions and what not to each time you add a new enemy.