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
- Wander - Ped will aimlessly walk along pavement areas, occasionally looking for activities to perform (such as attacking rival faction members). No AI targets are required for this mode.
- Go - The ped will attempt to reach a location, or follow a moving target. One AI target will be required for this mode. It is unclear whether this will involve walking, running, driving, or all three.
- Protect - The ped will protect a list of one or more peds/cars/objects from attack/theft. This involves the use of weapons, but it is unclear whether it involves the ped following the target or not, especially in the case of there being multiple targets.
- Kill - The ped will attempt to kill a list of peds/cars/objects. This may involve travelling to them; typically by running, but potentially by stealing cars also. It is unclear how this is to be specified (potentially by a set of flags indicating available movement modes?)
- Jack - The ped will attempt to steal the indicated car (or a random nearby car if no target is given). In particular, this AI mode is used to guide the player ped towards a car to steal. Naturally, the ped will not attempt to use any other cars along the way in order to reach its target.
- Exit - The ped will get out of the current car.
- Ride - The ped will get into a specific car (or the same car as a specific ped), travelling as a passenger.
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:
- The different types of vehicle - car, bike, boat, plane, tank, train, etc.
- A flag to restrict the ped to only using its "natural" vehicles - the ones which its peddef indicate that it can drive or ride in
- A flag to restrict the ped to only using its last-used vehicle (which is not currently something tracked by the engine)
- Also, there is scope for a flag to indicate whether a ped is allowed to run (else just walk) to its target
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:
- Wander - the car will drive the streets, obeying the rules of the road, occasionally looking for nearby rival faction members to attack.
- Go - the car will attempt to drive to a certain location, or follow a target. It is unclear whether this involves breaking the law or not (i.e. driving fast or slow) - this issue strengthens the argument for including a 'go fast' movement ability flag for the current AI goal.
- Protect - Any vehicle-mounted weapons will be used to protect the target; failing that, the vehicle itself will be used as a weapon, or potentially even a shield
- Kill - As above, any vehicle-mounted weapons will be used to attack the target, or the vehicle itself. This may also entail the introduction of an 'on foot' movement flag, indicating that in certain circumstances the driver is allowed to leave the vehicle and attack its target.
- Jack - has no relevance (unless the target vehicle is different to the current)
- Exit - The ped will leave the vehicle
- Ride - The ped will merely stay in the vehicle until told to leave (or circumstances force it to leave, such as the car catching fire - providing the movement flags allow it to move on foot?)
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!