Artifical intelligence and character controllers

This describes the artifical inteligence and character controllers.

They are using the fact, that game world is divided to squares, using position modulation. path finding and path node grid system is also used to carry out any movement tasks.


Top

1 What does AI do?

The AI here reffers to some logic, which allows to control the character (Player / Monster). So basically, even if user clicks on screen to move the character, there is AI which takes the command, and executes it.

2 The objective

We want to be able to control the character (move here, attack this character, use item -> navigate to item and use it), and also make sure that ongoing command will be interrupted correctly.


2.1 Moving the character

We want to move character from path node \(A\) to path node \(B\).
For simplicity consider, that there exists direct link between \(A\) and \(B\).
This boils down to following actions:

Obviously, if the action shall be cancelled in the middle, the character will end up having position which is between nodes, and entire system breaks, since it is not implemented for that.
Therefore we must make sure that movement action will always be interrupted correctly (with exception, where directly after interruption, new position is set (teleport, etc.))

3 The waiting queue

The waiting queue is realized using simple linked list.
It is located in the CombatController, and there are commands being inserted. Each command inherits from the CharacterCommandBase class.

4 Command

A command is always in one of the following states:

State Description
NEW The command has not yet been worked with at all
EXECUTING unpack() hasbeen called upon the command instance
ABORT_REQUESTED Abort for the command was reuested
TERMINATED It is safe to remove the command. It ended / suspended its work successfully

When command is added to quue, it has the NEW state.
When it is about to get executed for the first time, unpack is called, and state is chnged to EXECUTING.
When abort is called, the class instance is supposed to finish important work, and then set state to TERMINATED. Command witth such state is then removed from queue

5 Combat

Combat (how to attack melee, ranged, chase target) is explained here.