AI

Ped AI

Ped AI operates on a simple goal-based system. Each ped has a goal, which it will try to obtain; such as walking aimlessly, following an object/walking to a location, or killing an object. This means that, as well as the goal, the ped also has a list of one or more target entities.

List of AI goals/modes

AI events

There are only likely to be two AI-related events required: Success and failure. However, since not all AI modes have clearcut success/fail criteria, it cannot always be guaranteed that an event will fire for a specific ped.

Movement flags

Based around the above discussion, it is forseen that each ped may require a set of bitflags indicating which modes of transport it is allowed to use in order to obtain its goal. Potential flags include:

Sub-goals

There is scope for the introduction of sub-goals (or actions), to allow for more complex ped movement, or cleaner implementation. For example, a ped may maintain a short list of waypoints, indicating part of an A* path towards a target, whether that is another ped on the other side of the map, or the waypoints it must use to navigate around a car it is trying to enter (or avoid). In more advanced combat AI, the waypoints could be used to lead the ped to cover, or a weapon/health pickup.

A sub-goal also entail the ped stealing a car in order to reach a destination much quicker; in this case, the sub-goal is a full AI goal, indicating that some more advanced goal management system may be required, such as a small array or linked-list

Car AI

Cars by themselves have no AI; instead, if a car has a driver, its movement is dictated by the AI goal of that driver ped. This means that, the original AI goals have the following interpretation:

Car movement

In order to help prevent traffic accidents, each car has a short list (4-5 entries) of road tiles which it has 'claimed'. These tiles are the ones in the movement path of the car, and are to be used exclusively by that car (unless another car which is breaking the law appears - in which case standard collision-avoidance code will take affect). Normally, if a car is driving lawfully, it will only be allowed to continue its journey if it has one or more claimed tiles ahead of it. This system is designed to avoid problems with cars crashing into each other in intersections, or creating traffic jams because the cars do not give way to one another.

TODO:
MUST-DOCS: UNKNOWN: Decide on movement abilities; "use natural cars", "use any cars", "use previous cars", "use feet", "drive fast", and "run" seem like good choices. May also need extra flags to control whether VIPs are allowed to drive their own cars, though.
MUST-DOCS: UNKNOWN: How peds react to nearby faction members. Just look for them when AI wander goal is completed, and let panic/etc. events warn nearby people? i.e. if one ped attacks another, the panic event will automatically warn everyone else in the vicinity, and they'll respond accordingly
MUST-CODE: LONG: Implement the AI goal execute functions!
CODE: QUICK: Improve stuck-avoidance code to sometimes jump instead of punch (e.g. if a car is in the way). Also, tweak to enable punching earlier (i.e. before full movement blockage is reported)
MUST-DOCS: MED: Panic(/criminal flagging) system. Does any damage event result in panic? Who should panic? (attacker, victim, bystanders, similar/dissimilar faction members, etc.)
CODE: MED: Improve AI mvar code to use the same mvar multiple times where possible
MUST-CODE: MED: Improve car AI. Need to tweak scan forward for objects, hold line better when braking (aim for angle if on straight, not point?), stop before blockage not inside it, use foot break as well as/instead of hand brake, and tweak carphysics helper functions to be more accurate.
MUST-CODE: QUICK: Fix AI cars not moving until bumped by player.
MUST-CODE: MED: Fix ped AI to not wander off cliffs!
MUST-CODE: MED: Fix ability to carjack on slopes!
???
Profit!