🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

whats an easy way to implement this behavior?

Started by
10 comments, last by Norman Barrows 8 years, 2 months ago

>> If a creature becomes surrounded by all hostile-controlled space, they will be paralyzed. Don't make the area impassable. Make it cost more, by some reasonable factor. If the only way to escape is through a dangerous area, you should still allow creatures to use that path. Also try not to make things black and white in your passability constraints/path costs. Subtle shades of danger can be a powerful way to represent risky but not impassable areas. Many shades are better than just a couple, because you can then distinguish between "I'd rather not go there" and "that will definitely wreck my shit."

hmm... a good point. so fires should have a flux density field - so to speak. well that's definitely an influence map if i ever heard one.

this is why i like posting before i implement. make sure i don't overlook something.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Advertisement

>> Predators often have their own predators, and prey of course do

i may have managed to get it all down to just two basic types of AI for animals: predator, and non-predator. and predator is just non-predator with a hunting mode. so the two basic driving AIs are "fight or flight" and "hunt", with "graze" as the "i'm not doing anything" or "idle" behavior. and fight or flight or hunt are both "fight/hunt if they aren't bigger (by weight)". so for a non-predator, negative influences on the influence map would be any critter that outweighed them, terrain obstacles, and campfires. and all 50 some odd animal types have unique weights. for predators in hunting mode, it would be any critter that outweighed them, or whose hit points (based on weight) was more than the combined hit points of the pack (also based on weight) for pack attack AI. turns out almost any predator will pack attack if the pack odds are favorable while individual odds are not, and the payoff in food is enough for the whole pack. the pack can even be two different species on rare occasions, such as grouper and moray. but i don't get into inter-species cooperation hunting.

but you see the problem with this. each type of critter will have its own influence maps. fortunately, there's seldom more than half a dozen species in visual range at a time.

i may be able to mark the center of an influence with the critter weight/hit points, and simply ignore those influences that are not heavy/strong enough to worry about. but that would require something more like a bsphere cull than a grid map to work. still lots to think about and figure out.

but its starting to look like i may need to re-engineer the AI around influence maps.

>> So such behavior decisions will be common to many of your animals/intelligent objects

pack hunting (which is rare), and flock are the only two behaviors where critters of the same type share the same goal. all animals of the same type will share the same threats.

but you allude to the goal influencing things. should the influence map just be negatives, or should it also have positive weights, for things like the goal? if positive as well, you'd have a map that did a circular gradient out from the goal as positive influence, and a number of small square or round negative gradient areas scattered across the map, representing things such as dangerous animals, campfires, etc. in general this would seem to make the AI choose "more towards the goal" in the case of ties.

one negative influence map per animal type active is not that bad. but one for each animal? whats the word Dave? is it doable? if anyone around here can answer that one, its you. (or anyone else whose has done this before). is an influence map for each entity, including the influence of a dynamic goal, doable? 500 entities? maybe more? i've hit 500 active in playtesting already.

>> You might be able to do a consolidated/shared 'influence map' for large numbers of certain beasties (for certain different 'threats' types). The granularity can be cruder (bigger grid squares) depending on how accurate it needs to be.

unfortunately, it looks like one map per critter type, and one map for campfires, as the base types from which the final influence maps will be summed. so not a whole lot of sharing there. same species can share maps, they can all use the campfire map to make their maps. that's about it. and campfires aren't really that common. its a lot of work to keep a fire going 24 by 7 ! <g>.

>> It may not change that fast

campfires won't change unless they go out or someone lights a new one. but hostile critter threats (when present) will change continuously as the critters move about.

perhaps this is the question to ask:

given that the AI must look around and determine nearby threats to avoid, is is faster to do it with an influence map, or by iterating through the list of active entities (all of which are in visual range?

if you use a map, you must update it when the entities move, but the lookup is fast. an iteration is required when first constructing the map. updating wouldn't be that bad. you have a single routine add_influence(location, amount). to move a critter you add_influence(old_location,-amount), then add_influence(new_location,amount). and all add influence does is add or subtract weights to the map squares. you could have an automatic falloff rate, or an explicit radius you pass to add_influence, and just lerp from amount to 0 at the cutoff radius. so the hit for update would not be that bad: a bunch of adds with indirect addressing. by using large int values (basically fixed point), it might be possible to use ints instead of floats for even faster updates. so maps are looking pretty good so far.

if you use iteration, you have to loop at least to last_active in the list, if not MAX_LIST_SIZE. and you have to skip over inactive and dead animals. the list is referenced by other lists, so entries can't move without "pointer fixups" required. thus the inactive field, and there you're basically looking for closest threat, so you can defend your space against it, hunt it, or run if its bigger.

but using maps to find closest threat target doesn't really work so well. they are more for once you've got your target and know where you want to go, whats the safest way to get there?

so it would seem that iteration should determine target, then an influence map should be used by A* to determine the path to target. and the influence map would have terrain, hostile critters, and campfires on it. when an entity was added to the simulation you'd call add_influence to add it to the influence map. when it moved, you'd call add_influence(old_location,-amount), then add_influence(new_location,amount) to move it. and call add_influence(location ,-amount) when it died.

whew! influence maps and optimized A*. looks like i got my work cut out for me.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement