|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface for monsters that want to participate in the AI decision process. The interface allows monsters to determine various parameters that the AI uses for choosing what to do.
Method Summary | |
int |
getLocationHeuristic(GameMap map,
int x,
int y,
Commandable[] targets)
Returns how badly the monster wants to avoid this square when chasing a player. |
Method Detail |
public int getLocationHeuristic(GameMap map, int x, int y, Commandable[] targets)
It's important to understand the scale that we use, so you can choose a cost that makes sense. The cost you return here is added to a "heuristic" value, which is the square of the distance between this location and the target nearest this location. So if the nearest target is 4 squares away, the heuristic value is 16. You'll want to assign a cost that makes your monster behave in some predictable but intelligent manner. For instance, if you want your monster to avoid going through fire, you could assign a cost of 20 if the terrain is lava or if it has a firewall in it. The monster will go through the fire as a last resort, but a cost of 20-30 will make it walk around the fire if possible. If you assign a cost of 100 or more, the monster is very unlikely to move into this square, and a cost of 1000 would pretty much guarantee it'll never move here. You can assign negative numbers if you want the monster to give preference to this square.
You should try to minimize the amount of computation that you do in your implementation of this method, since it's called every time your monster is about to move, and it's easy to want to try to do things that are expensive. It's OK to check the values of various properties for the objects in the square, but you should avoid searching areas (more than one square) or doing lots of other processing in this method, since you'll be taking away from the CPU available to other monsters.
This method is called on an "AI Thread", which does NOT have the "map exclusive" when it's running. You should put your entire method body in a try/catch block, since it's common (and expected) for you to get exceptions when you're iterating over objects in the map data structures and they change out from under you on another thread. This is great because it means AIs can take all the time they want to do their thinking without locking the game up, but it increases the amount of exception handling you have to do. If you get an exception, you should probably exit (returning a reasonable heuristic) and let the method get called again, rather than retrying over and over.
map
- the map to move to (usually the same as the monster's map).x
- proposed map x locationy
- proposed map y locationtargets
- a list of possible target players (or monsters)
in the vicinity.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |