Beruflich Dokumente
Kultur Dokumente
Chapter 1
1.1 Introduction
Games have been an entertainment factor for human being from early ages, computer games
are the digital entertainment from recent years and are increasingly entertaining with more
and more realistic in nature as the technology and hardware capabilities are increasing day by
day. There are lot of techniques and new ideas which are being implemented in present
games; Artificial intelligence (AI) is one of such technique that helps to enhance the game
experience to its fullest. Elements of artificial intelligence used in computer games have come
a long way.
In the broadest sense, most of games incorporate some form of Artificial Intelligence (AI); it
has been a core module in the game development process. In the beginning, the developed
systems were based on set of rules written directly in the code of the game or on the
behaviour scripts interpreted by the code. Game developers have used AI for years to give
seemingly intelligent life to countless game characters. Fast technical progress and rapid
increase of processing power of home computers were also a catalyst for the development of
applications using artificial intelligence in computer games. The game which came in the
early time of gaming industry began the artificial intelligence algorithms had to settle for
limited capabilities of machines available at that time, with the processor frequencies no
higher than 2 MHz (Steve Rabin, 2002).
Prior to this revolution in game, the importance for AI in games is least considered. Game
developers used to perform a last minute rush job mostly implemented in the final two or
three months of development which results in poor and unsatisfying game output with lifeless characters in their games. A lot of commercial and successful game tends to ignore the
-importance of Non-Playing Character (NPC) mostly in Role-Playing Games (RPG) thereby
decreasing the overall feeling and realism in games. Most of the developers concentrate their
NPCs behaviour on static or un-realistic animation techniques for that particular situation
(Alex.J, 2003). Even this method of settle animation and low-level AI has been hardcoded,
and has been repeating in all the games. There are plenty of best sellers evolved over the time
and every game has been following the same basic state-machines rule and repetitive AI for
their NPCs character in the game. The game developers tend to think that amount of time
1
spent by the player with the NPC character in the game is making the player unnoticed the
intelligence of that character and the behaviour of the character (Woodcock, S. 2000).
However the usage of game AI has been brewing, the past few years have witnessed game AI
vastly richer and more entertaining than the simplistic AI done in the past. Animation
techniques and 3D rendering hardware has been improved and the detailed quality of game
graphics is being more steering new heights in the visual representations. AI has increasingly
become one of the critical factors in a game success scale.
The main underlining point of this work is to draw out the importance of AI experience for a
game player, especially when the player is in non-combat situations and to enhance the
behavioural characteristics of an NPC in RPGs. Specifically in a leading game NeverWinter
Nights2(NWN2). So the game play would feel much more realistic in nature when interacted
with an NPC.
1.3 Objectives
1.4 Deliverables
Improve realism in RPGs through enhancing the NPCs AI using Smart Terrain
technique.
Implementation of Smart Terrain using different event-handling scripts in NWscript,
1.5 Hypothesis
As far as the research done for this project, most of the successful games in the commercial
market tend to ignore the importance of AI for non-combat NPCs, those are not involved in
any kind of aggressive combat situations in the in-game mainly in case of an RPG games.
Keeping in mind the problems identified from the research, the hypothesis constructed is that
a higher sense of realistic behaviour in NPCs will contribute to a higher sense of realism in
game play. The project is to explore if Smart Terrain technique will be contributing factor in
this process.
On advance research in to the realism of a games and Smart Terrain further sub divisions in
the research question has been deduced. Following are the research question for this project.
Can realistic behaviour of the NPCs in non-combat situations does really affect the
player experience?
Does an advanced AI technique like Smart Terrain really helps in enhancing the
experience?
The project report has been divided into various chapters and sub-divided into sections
explaining different elements involved in the AI techniques and the background research
based on these techniques.
Chapter 2: Describes the literature review for this project and also the background
information required for the doing the research.
Chapter 3: Describes the methodological part involved in this project and also what
techniques that are being used to fulfil the research questions.
Chapter 4: Describes the implementation part of the methodology that been discussed in the
earlier chapter.
Chapter 5: Describes evaluation of the implementation and testing analysis.
Chapter6: Describes the result and outcome of the testing and analysis of the results using
statistical methods and graph charts.
1.7 Conclusion
This chapter merely described about the introduction part of the projects that is intended to do
and also the project aims and deliverables is also mentioned. It is important to outline the aims
and deliverables of the project before starting the project as this will help to achieve the goal
and results that is originally intended for this project.
part
lies
in
extracting
appropriate
behaviour
from
the
poll
of
In the early stages game developers used cheating as a means of improving the skills of an
agent (Steve Rabin, 2002). In the context of artificial intelligence in video games, cheating
refers to the programmer giving agents access to information that is unavailable to the
player. In a simple example, if the agents want to know if the player is nearby they can either
be given complex, human-like sensors (seeing, hearing, etc.), or they can cheat by simply
asking the game engine for the player's position. The use of cheating in AI shows the
limitations of the "intelligence" achievable artificially; generally speaking, in games where
strategic creativity is important, humans could easily beat the AI after a minimum of trial and
error if it were not for this advantage. Cheating is often implemented for performance reasons
where in many cases it may be considered acceptable as long as the effect is not obvious to
the player. While cheating refers only to privileges given specifically to the AI, it does not
include the inhuman swiftness and precision natural to a computer, a player might call the
computer's inherent advantages "cheating" if they result in the agent acting unlike a human
player (Steve Rabin, 2002).
There are different methods that game developers will follow to extract the wow factor in a
game. There are a number of underlying principles behind video game AI, the major one
being that of having a rule based system whereby information and rules are entered into a
database, and when the video game AI is faced with a situation, it finds appropriate
information and acts on it according to the set of rules that apply to the situation. If the AI
database is large enough, then there is sufficient unpredictability in the database to produce a
simulation of human choice. Earlier game development used Finite state machine (FSM)
method in to describing the behaviour of computer-controlled enemies. A* is also used as a
best alternative to pathfinding problems of AI. Many of present day games are still using FSM
and A* algorithms as their basic algorithm and are creating new advanced algorithms.
The AI in most modern games addresses three basic needs: the ability to move characters,
ability to make decisions about where to move, and the ability to think tactically or
strategically (Millington.I, Funge.J, 2009).
2.2 AI Techniques
There are many AI techniques which are being used by developers to create life-like
characters in their games depending on the game genre. There is no specific algorithm or a
specific AI technique that are used for a particular genre, but instead using according to the
game requirement. Many computer game researchers have came up with different generic
algorithm which are been derived from basic AI and are being used as a game AI in the
present game.
AI techniques are primarily distilled in to two sections: Deterministic and Non-deterministic
(David.M, Glenn.S, 2004).
2.2.1 Deterministic AI
Deterministic behaviour or performance is specific and predictable, there is no uncertainty. An
example of deterministic behaviour is a simple chasing algorithm. This type of AI is explicitly
coded for a Non-Playing Character (NPC) to move from towards a target point by advancing
along the X and Y coordinates axes until the characters X and Y coordinates coincide with
the target location.
2.2.2 Non-deterministic AI
Non-deterministic behaviour has a degree of uncertainty and is somewhat unpredictable (the
degree of uncertainty depends on the AI method employed and how well that method is
understood). An example of nondeterministic behaviour is a NPC learning to adapt to the
fighting tactics of a player. Such learning could use a neural network, a Bayesian technique,
or genetic algorithms.
As for the present research is concerned, this project work is only going to consider
deterministic AI techniques as this techniques are more related to the work that is being done
in this research. There are many algorithms techniques and basic AI (Deterministic AI in case
of this project work) methods that are being implemented in the game development world.
The most common of them are chasing & evading, Rule-Based AI, pattern movement,
flocking, path finding and waypoint, A* algorithm, A-life algorithms (David.M, Glenn.S,
2004).
9
Of all the AI techniques path-finding, A-life and A* algorithms are three most popular
techniques which are still being used in current games. Keeping in mind the requirements of
this project, these three techniques are proven to be the best alternative to the smart-terrain AI
implementation for the sake of this project. The details of the choice of these alternatives are
explained further in the document along with the benefits and flaws involved in each of those
techniques.
10
In the above example the position of the game characters is specified by positionX and
positionY variables. The positionX and positionY coordinates are either increased or
decreased so that the game character's position moves closer to the destinationX and
destinationY coordinates. This is a simple and fast solution to a basic pathfinding problem
(David.M, Glenn.S, 2004).
Figure 2(b): showing basic path movement of pathfinding algorithm (David.M,Glenn.S, 2004)
The figurative version of the algorithm is shown above for better understanding of the
algorithm. In the figure the game character moves diagonally toward the goal until it reaches
the point where it is on the same x- or y-axis as the destination position. It then moves in a
straight horizontal or vertical path until it reaches its destination. As mentioned earlier there
are many variations to the basic pathfinding algorithms, these variations are generated
depending upon the usage situations of the basic algorithm in a particular game. Nevertheless
it is very much important to specify the basic algorithm of pathfinding.
The later versions of pathfinding algorithm generated in the process of refinement includes
the game characters dealing with obstacles in the way of axis and line of sight path
movements. The algorithms proceeded which are adapted on basic pathfinding have effective
methods of obstacle avoidance and wall tracing. The problem of way finding from an initial
point to desired destination on a map is a key problem in almost all computer games.
Algorithms which come under this section as a refinement process belongs to lower level of
games AI, serving as a base for generating more constructive and complicated intelligent type
of behaviour. Algorithms which are designed as a solution for the pathfinding problems are
differentiated individually according to the approach that the algorithm is following. The
simplest approach of the problem is to ignore the obstacle until the game character bumps in
to another. Overshadowing all the algorithms that came as a solution for pathfinding problem
11
A* comes out to the best algorithm. The A* algorithm continues to reign as the preferred
pathfinding algorithm, although everybody has their own variations and adaptations for their
particular project. Every developer present who had needed pathfinding in their game had
used some form of the A* algorithm. Most had also used influence maps, attractor-repulsor
systems, and flocking to one degree or another (Woodcock, S. 2000).
2.4 A* algorithm
Pathfinding is one of the basic problems of game AI, inadequate problem will leads to seem
the game character unintelligent and artificial. A better handling of pathfinding problem can
make the game more enjoyable and immersive for the player. A* is one algorithm that fulfils
all these requirements.
A* (Pronounced A-Star) is a best established algorithm for general searching of optimal
paths. The A* algorithm is a venerable technique which was originally applied to various
mathematical problems and was adapted to pathfinding during the early years of artificial
intelligence research (Bryan Stout, 1999). A* is best in handling varying terrain costs well and
it is the faster in most of graph searching algorithm.
The basic algorithm, when applied to a grid-based pathfinding problem, is as follows: Start at
the initial position (node) and place it on the Open list, along with its estimated cost to the
destination, which is determined by a heuristic. The heuristic is often just the geometric
distance between two nodes. Then perform the following loop while the Open list is
nonempty:
Pop the node off the Open list that has the lowest estimated cost to the destination.
If the node is the destination, we've successfully finished (quit).
Examine the node's eight neighbouring nodes.
For each of the nodes which are not blocked, calculate the estimated cost to the goal of
the path that goes through that node. (This is the actual cost to reach that node from
12
In the end, the nodes along the chosen path, including the starting and ending position, are
called the waypoints. The A* algorithm is guaranteed to find the best path from the origin to
the destination (Marco Pinter, 2001). The typical formula version if the heuristic search
algorithm is expressed in nodes to find the best route, this heuristic search ranks each node by
an estimate of the best route that goes through that node. The typical formula is expressed as:
f(n) = g(n) + h(n)
Where:
f(n)
g(n)
h(n)
One of the more difficult parts in solving A* is creating a good heuristic function to determine
h'(n). A heuristic function differs from an algorithm in that a heuristic is more of an estimate
and is not necessarily provably correct. An algorithm is a set of steps which can be proven to
halt on a particular given set of input, the heuristic function in A* is arbitrary, however the
better the heuristic function, the faster and more accurate the solution will become. There lays
the problem, deciding a good heuristic. Even with a shortest path example, the heuristic can
change depending on the implementation of the search and how easy or complicated the
heuristic function is going to be.
13
Following is a proper A* algorithm, some node may be proceeded more than once for finding
better paths.
A* search algorithm
Priorityqueue Open
list
Closed
AStarSearch
s.g = 0
s.h = GoalDistEstimate( s )
s.f = s.g + s.h
s.parent = null
push s on Open
while Open is not empty
pop node n from Open // n has the lowest f
if n is a goal node
construct path
return success
for each successor n' of n
newg = n.g + cost(n,n')
if n' is in Open or Closed,
14
wouldn't be the best alternative if CPU cycles are at a minimum. The A* algorithm is
efficient, but it still can consume quite a few CPU cycles, especially if you need to do
simultaneous pathfinding for a large number of game characters. The more or less real-time
requirements of games, plus the limitations of the available memory and processor time in
some of them, may make it hard even for A* to work well. A large map may require
thousands of entries in the Open and Closed list, and there may not be room enough for that.
Even if there is enough memory for them, the algorithms used for manipulating them may be
inefficient (Bryan Stout, 1999).
One of the failings of the A* algorithm is that it assumes the terrain over which it has
calculated a path doesn't change, this is a bad side effect should the bridge you were planning
to cross get blown up by an artillery round. To solve this problem, some developers were
using D*, a dynamic A* variant tuned to handle changeable terrain, but none were happy with
it due to the CPU hit required to recalculate paths.
The possibilities of whether A* can be used or not will be discussed in the later part of the
document, along with some more considerations for using of better AI Technique in the
module NeverWinter Nights 2(NWN2).
16
Strong A-Life is something which is related to academic part and always deals with the realtime applications within the science felid, but where as Weak A-life is purely used for video
games purpose. A weak A-Life is used for modelling the behaviour of life-like characters
rather than creating a real life in an artificial world. Strong A-life can make synthetic life
possible and that weak A-Life only models life like behaviour (Guy,W, Lecky,T. 2008). A-life
is a young discipline and is still under development, more and more advances are made in the
A-life day by day.
17
18
Modelling
Calculated A-Life
Synthesized A-Life
Granularity
19
2.5.7 Granularity
The term granularity here means the level at which we are going to model the processes that
give rise to A-Life (be it synthesized or calculated). Granularity really needs to be designed in
from the very beginning; it is not easy to start at one level and move up (coarser) or down
(finer) during the actual implementation. It is, though, possible to layer different levels of ALife granularity (grain) as well as allow them to occupy the same game space. Some facets of
the game universe will be based on coarse granularity, while others will have fine granularity.
20
Windows Dressing : which has no functional purpose but to make game look pretty
Simulation: Which has an impact on the flow of events in the game behaviour
Both ads importance to the game experience, but windows dressing has very few
consequences. As for the simulation are concerned most of the game developers tend to use
this as because simulation requires very less resources or the CPU cycles. Windows dressing
demands lot of pre-allocated resources to start with (graphics chips, powerful CPU systems)
to share the load. Looking at todays technological advances of hardware developers are more
inclined towards the windows dressing concept. Nevertheless the importance of simulation
methods is always going to be the same with more and more advances are made within the
simulation techniques.
A-Life uses all kind of AI techniques as building block- such as neural nets, finite state
machines, fuzzy logic, and daemon organization. Daemon organization, in this case, means
allocating specific algorithms to specific entities (daemons), which manage their interaction
with each other and the game universe while they carry out other tasks that are predetermined.
One of them which are worth mentioning for the sake of this project consideration is
Flocking.
action has to be taken to make the game real. The flocking algorithm doesnt need the
hardcode method of developer for each individual character, instead the flock will modify
them self to fit to the situation.
22
Figure 2(c): Figure showing Global Game software architecture Chow,y (2006)
In the figure mentioned the definition file, commonly called as Game Data is the main
component and depending on which the behaviour of the game, it also acts as a game database
resource. It controls game status and triggers all the other components to work. With the
supplementary of physics engine, logic engine, even handler and other conflagration parts
linked to this game data core. The entire system will then handles the game play. Simulates
the works and responds to the users input. The request is then passed to the hardware
abstraction layer for the input, graphics and audio handler and finally processed the hardware.
23
2.7.1 Scripting
Most RPGs are heavily scripted because most of these games follow a very specific storyline.
Scripts are used for a verity of game constructs, including dialogues, game events flags,
specific enemy or NPC behaviour. How the player can interact with the environment and
many others. The main reason scripting is used in RPGs is because the linear pattern followed
by RPG game designs. This type of pattern always works well with the scripting methods.
The scripting is done almost as a part of the game to play out almost exactly as designed. The
check points and flags embedded in to the scripts so that the player are forced to follow from
point A to point B, even if the player first wandered over the points C,D,E and F in the
meantime. In a generic sense the scripting is somewhat data based way of hard coding the
assorted events that come up during the overall story (Brain.S, 2004).
24
having many sets of rules and with an untrained AI. However, it can be solved by training the
agents through a learning period before the release of the game so that a sufficiently
intelligent behaviour gets achieved. Based on the conditions, priorities and weights a set of
these rules is picked to be used to achieve the agents goals. When a goal has been reached, a
fitness function evaluates how well or bad the agent performed, and based on the result of this
function, the weights of the rules are adjusted. Higher weight if the rule resulted in good agent
behaviour and lower weight if the agent performed badly. The new weights for these rules will
therefore be picked more frequently when being higher and less often if they worked poorly
Bertil Jeppsson(2008).
Figure 2(d): Figure 4 showing the Generic finite state machine diagram (David.M, Glenn.S,
2004).
25
In the figure each potential state is illustrated with a circle, and there are four possible states
{Si, S1, S2, S3}. Of course, every finite state machine also needs a means to move from one
state to another. In this case, the transition functions are illustrated as {t1, t2, t3, t4, t5}. The
finite state machine begins with the initial state Si. It remains is this state until the t1 transition
function provides a stimulus. Once the stimulus is provided, the state switches to S1. At this
point, it's easy for you to see which stimulus is needed to move from one state to another. In
some cases, such as with S1, only the stimulus provided by t5 can change the machine's state.
However, notice that in the case of S3 and S2 two possible stimuli result in a state change
(David.M, Glenn.S, 2004).
Finite state machines are useful in RPGs just as they are useful in any other game. By using
FSM the developers have an opportunity to spilt the game in to particular states so that it
becomes easy to manage each state rather than managing the entire game. Especially when
debugging. Each state has explicit characters and will perform differently and manage these
with discrete code blocks.
2.8 Conclusion
This chapter described about the basic AI and Ai techniques that are used in game and in what
genre of games in particular. The main reason of this chapter is to figure out the appropriate
AI technique for the implementation in to NWN2, because not all the AI techniques will
support the requirements that are put up for this research. This chapter helped the author to
elaborate the research in the AI techniques area where he can search for the better AI
technique to implement which suits better for the research.
26
Chapter 3: Methodology
3.1 Introduction
This chapter will discuss about the methodology and techniques that this project is going to
use in depth. Most of the discussion is related to the particular methods and implementation
process about the prototype. Basic methodology and the testing is a purely experimental and
the implementation is done using the documentation provided my NWN2 community forums.
The details of background information of the game NWN2 can be found in this chapter, and
also the AI techniques that are previously implemented in this game is also discussed in detail
with more stress on the flaws of the default implementation in this game.
As NWN2 is a RPG game which is originated from famous Dungeon & Dragon (D&D)
settings. An introduction about D&D settings can be found in the first section, it is very much
important to know the details of background of the NWN2 game as most of the concept and
methodology used in the NWN2 is barrowed from the D&D framework with some changes in
the story line of the game.
27
commonly known as a campaign and the location where the adventure occurs is called a
campaign setting or in more general terms simply a campaign. One such campaign setting is a
forgotten realms or in the developers terminology the realms. NWN uses such adventurous
settings as its game theme. Some of the popular settings of D&D include Greyjawk,
Dragonlance, Forgotten Realms, Mystra, Spellhammer, Ravenloft, DarkSun, Planescape
The Forgotten Realms is one campaign settings that is going to be used in this project as the
NWN2 game uses same campaign setting as its core and basic platform game setting. Most of
the game used forgotten realms as their core settings previously, but NWN game is the one
which has enhanced the capabilities of this setting.
Icewind Dale
Baldurs Gater
Pool of Radiance
Neverwinter Nights / Neverwinter Nights 2
28
29
need to know the basic default AI implemented for AI in NWN2 game. This help to build
more facts about the default game and also to know what other parts of the game is in need of
enhancement.
30
situation involving those NPC). When compared with the other game genre where the NPCs
AI much more advanced, the NPCs in RPG has very less projection of AI within them.
NWN2 when looked at the non-combat NPCs AI prospective is a bit low to its quality
standards that the rest of the game has setup. This research project is mainly concerned with
the non-hostile and non-combat NPCs AI and to bring out realism in the game by
implementing the AI for the NPCs which are bound to terrain part of the game.
31
Dynamic scripting is one technique which came close to being implemented in to this project
because of the flexibility this technique is offering in modifying the behaviour of an NPC. The
much elaborated discussion of this technique was explained in the previous chapter of this
document. Yet the non-deterministic scripting technique fail to satisfy the need of the project
when comes to the non-combat situations. Dynamic scripting seems to be more of a combat
AI; the player will be very watchful and aware of an enemys action in a fight because it very
much affects the player and the game-play. For a non-combat NPC however, its quite
different since their action doesnt affect the player in such an obvious way. This is one of the
reasons of ruling out dynamic scripting. And the other reason is being its complexity in
implementing a fitness function to evaluate the realistic behaviour of the NPC agent would be
difficult. After conducting different types of research on choice of AI technique the smart
terrain is considered to be best and apt technique to implement.
33
The NPCs in the terrain is provided with a set of basic need to be satisfied and these
needs will increase from time to time depending on the work that the NPC is
performing.
Let every NPC to fulfil its currently highest need by listening for ht events from
nearby objects in the terrain that offers services that helps that satisfies the specific
need.
The object which satisfies these needs of NPCs is called Smart Objects. And they are
responsible for broadcasting events to all NPCs in their corresponding area about what
need they it can satisfy.
Below Figure shows the picture format of the method that is going to be implemented.
34
Figure 3(a): Figure showing the smart objects broadcasting to its nearest NPCs in the terrain.
As discussed each Smart object will broadcast to its nearest NPC about what needs that it can
satisfy. This is where the On-Spawn and On-Heartbeat event comes in to picture. On-Spawn
event is where the NPC generates starting values for its needs and desires. Now that every
NPC is provided with its basic needs, the needs also have to be updated and increased by
time. This is done by the On-heartbeat event handler and it also evaluates which one of them
is at highest priority.
When the NPC receives the smart object event broadcast. The NPC has to check whether the
broadcasted received can satisfy its highest match in their priority list. Once and event of
satisfying match is received then the NPC has to move to the location where the smart object
is situated to interact with the smart object and fulfil its needs and move on to the next task on
its priority list. Below figure will describe how the NPC will interact with the Smart Object.
Figure 3(b): Figure showing the interaction of NPC with Smart object
During this process of NPC interacting with the smart object. The NPC has to choose the best
path to find the smart object. When an NPC has found a smart object to satisfy its highest
need, it has to get there. Getting close to the destination is crucial if any interaction is to be
35
made since the need can't be satisfied without interacting with the object. Note that normally
in games, this would just involve a pathfinding algorithm like A* mentioned earlier in chapter
2 to find the closest path to the destination. However, is that really the most realistic way for a
citizen to move to a location? Of course, taking long detours is not realistic, but if the closest
path to the destination involves walking across some, for the public forbidden area. Or
perhaps crossing a muddy and dirty path that none would cross unless the NPC really had to.
To appear realistic the NPC should follow the city's roads until it reaches the destination, so in
this approach it a bit different. The game engine used in this work is only providing a
pathfinding algorithm taking the shortest route to its destination without considering the fabric
of the ground beneath. Therefore using a combination of the pathfinding and waypoints to
mark out the roads of the city seemed like the best way to be able to simulate how a citizen in
a town moves between two locations realistically.
Figure 3(c): The figure showing how an NPC can achieve realistic movement through
waypoint consideration by reaching its destination through following the waypoint traces
which can be embedded in the script. Hear in the figure two NPCs heading towards different
goals. The line between the waypoint marks the path each of them will take. The black dot
mentioned in the figure depicts the waypoints.
36
37
Figure 3(d): Figure showing the decrease in search space using waypoints in combination
with pathfinding opposed to just pathfinding over the entire distance.
The combined effect of waypoint and A* will pull out the realistic features in the NPCs
behaviour. The final step is to make the Smart object fulfil the needs of a NPCs, the Smart
Terrain technique has rich in behavioural animations according to the situation.
3.11 Conclusion
As explained earlier in this chapter the procedure will be implemented in the game with the
help of NWN2toolset. This toolset is provided as a developer console from the original game
developers.
38
Chapter 4: Implementation
4.1 Introduction
This chapter describes technical details of internal working of NWN2 toolset and
implementation of smart terrain in to NWN2. The implementation part for the methodology
that been discussed in chapter-2 will be explained. The basic scripting methods and handling
of script using NWN2 toolset will be discussed in detail. NWScript is main scripting tool
which is being used to develop this prototype.
39
It is been said previously in the document that the hardcode methods is not the best way to
implement the NPCs AI and doesnt really have much realistic behaviour, but for the sake of
this project it is too left no choice than hard coding the NPCs AI and explaining the process of
how the AI should be in NWN2 game and what effect will be there on the user after having
interacted with the prototype. As this project is mainly dependent on the users feel and
experience, the prototype is developed to extract the feel and to calculate the realistic effect of
user in how he felt about the NPCs being real in the game. The prototype will feature all the
factors that are needed to fulfil the methodology and the concept and will answer the research
questions that this project is working on.
40
perfectly at the first sight (see figure 4(a)). All the characters that are used in the toolset are
designed using character design plug-in which is one of the features of the toolset editor.
Fig 4(a): figure showing the initial game module that is created to incorporate all the
charterers in to the area.
An exterior area in a module generally comes with laid out grid surface with definite
dimensions that are set up during initialization. The surface of area is well edited with
textured terrain and tiles, various structures at places that is required to generate the feel of the
module. Exterior can generally have obstructing terrain features and obstacles that channel
movement, while interior area uses walls and doors to control flow within the game.
The area toolset is well equipped with the environment editing features that are helpful to
maintain the look and feel of the game. The appropriate music is selected for each and every
character in the game. The property of the area is properly selected to bring out the effect of
the terrain environment using the area editor. (See figure-4(b)/ Figure-4(c)). It is very much
41
important to maintain the look and feel of the game using the environment, it environment
may not be a important factor for the player who have already played RPG games before but
as this research is also emphasising the result based on non-game player or first time game
player. It is very much needed to maintain the environment realistic in nature.
Figure 4(b): Figure showing the properties of the module that is created.
42
43
Figure 4(d): Figure showing the NPCs camp and the nearest Smart objects which can fulfil
the needs of NPCs.
4.4 Conversations
Once the environment is properly laid out to get the exterior feeling in the game the next step
is to make the NPCs interact with the player. The interaction is basically done using
conversation interface in the editor. A conversation consists of a branching tree of dialogue
strings that are used to perform social interactions with creatures or objects in the game. They
can be used to yield information to the players, to provide personalities to the various
inhabitants, initiate trade and to control the plot. Within the game, a conversation is typically
displayed using a cut-scene interface that shows the alternating speakers at varying camera
angles.
Most of this project made use of conversation script to explain to the user about the game and
the idea of NPCs interacting. As because of this implementation is a merely a prototype is it
decided to be beneficial to the whole implementation if the conversation scripting is used
whenever a NPCs is interacting with an object or whenever the player is interacting with the
NPCs.
44
A conversation cut scene will pop up whenever a player interacts with the NPC that is mapped
with the conversation script; a cut scene can have a questioned version or just information that
is useful for the player. A conversation structure can be drawn within the conversation script
between the player and the NPCs in the area and specific actions and default conditions are
inserted in to the module (See Figure 4(e))
Figure 4(e): Figure showing the conversation script between Player and NPC
45
Figure 4(f): Figure showing in-game conversation between the NPC and player
Question nodes format is utilised in the situations where there is a question node required, and
a specific animations and action nodes is selected at the particular instance where the NPCs
has to perform some action at the point of time in between conversation. Lip-sync is one of
the features in toolset where the player or NPCs will do lip-sync when the cut scenes are
playing. This functionality is also used in the conversation panel of this module.
In the game mode normally a player cannot see what is going on in the backend with the
NPCs, what are they doing at the point, or where are they going. To make the player
understand all this process involved in this research over head conversations are used (see fig4()). And also a message is displayed in the debug panel whenever an event is occurred like
for instance if the NPCs have found a smart object then it will give a message in the debug
panel. This functionality is done using the triggers in the area. The triggers are designed in the
area such that is the player enters one particular area that is flagged as a smart object area then
the NPCs has to send a message to the debug panel that they have found the smart object and
they are about to satisfy their needs(see figure 4(g) / 4(f)).
46
Figure 4(g): Figure showing the debug message sent by the NPCs when they found the smart
object in the area and the needs have been satisfied.
Figure 4(h): Figure showing the debug message sent by the smart object when it is performing
the signalling task to the nearest NPCs in the area.
47
Figure 4(i): Figure showing the NPCs overhead message about his need at that point of time.
The above script will give a message when player is entered in to area. To make this script
work, it has to be linked to the scriptonenter event in the properties panel.
At first in the process of implementation the NPCs has to raise some basic needs that should
be fulfilled by smart objects. These needs should be updated at every instant depending upon
the rate at which the needs are fulfilled by smart objects after the NPCs interact with the smart
object. To do this the NPCs attributes are listed with some basic needs like hunger, energy,
and faith, these needs are updated by using a default repetitive attribute called heartbeat this
heartbeat attribute will raise the flag of each attribute at every 6 seconds or after one need is
fulfilled.
Next the smart object have been given some basic need flags(Hunger, energy, faith) that they
can satisfy and their objective is to broadcast those needs to the nearest NPCs that are present
in that area. To broadcast the needs from the smart objects at first the smart objects has to
locate them self in the area, locating the smart object will also helps the NPCs to find the path
quickly. This is explained in the next section in brief. When the Smart object signals their
particular needs, the NPCs have to listen that broadcast and find the shortest way to that smart
object which it had listened to. The NPCs basically doesnt have listening attributes by default
in their properties. Some speak triggers have been used for this purpose. Basically a trigger
acts as an ignition for any event that is linked to that action. In the next scenario the NPCs has
to choose the best path to go to the smart object which are called for. Some default waypoint
mapping is done in the area to guide the NPCs to the smart objects, it is also used to help the
NPCs to stay in the boundary of the region and to find shortest path within the waypoints
boundary.
As discussed earlier there are some areas in the module where it needs scripting and one of
them was at the point where the smart objects has to be found in the terrain and the NPCs has
to move to them to get their need satisfied (See appendix). Another script is also written for
the heartbeat event to broadcast the smart objects need to the nearby NPCs (See Appendix B).
Both the scripts are triggered using the triggering methods when the NPCs are spawned in the
terrain. Following are the some of the scripts that is been written for the purpose of this
project, the requirements that these scripts satisfies is also mentioned, for more information on
scripting refer appendix B.
49
custom_area_enter.ncs: This script is written to locate the smart objects in that location/area
and storing the nearest waypoint for this smart object, so that it will be easy for the NPCs to
find the smart object rather than NPCs wandering around the terrain aimlessly. This script is
called when all the objects in the area is spawned for the first time. Once the nearest waypoint
is stored in, then its up to NPCs script to find the shortest route for the particular waypoint
that is been flagged as a nearest to the smart object.
custom_area_heartbeat.ncs: This script is written for the purpose of heartbeat event (a
default event in the NWN2, which will execute at every 6 seconds). The custom heartbeat
script is utilised to signal the events of the smart object in the area to the NPCs so that the
NPCs could satisfy their needs. This script is included in the OnSpawninscript event of the
default NWNscripts so that this script can be used to all instances of the smart objects if
created any in the area.
4.6 Conclusion
The implementation of the prototype was a successful with respect to the author. There are lot
of issues that was raised in between the implementation which are discussed in the critical
evaluation section of the document. Most of the implementation of the methodology was done
as a prototype and the will be explained to the tester before he/she test the implementation in
the form of texts in the game. This is because of lack of time and the short span for
implementation cycle, all necessary precautionary measures and taken before the
implementation is going to testing phase.
50
51
Figure 5(a): Figure showing the diagrammatical format of the analysis and implementation
done for this research.
The above design shows the main resource used (NWN2) for the development of the
prototype and also what are the techniques and tools that are used to produce the final
module/ area as output for the user to test the implementation.
52
53
follow and reach the smart objects in the area. Unfortunately by default the NWN2 toolset
fallows A* algorithm as its default pathfinding algorithm for the NPCs so, to make the NPCs
more intelligent the concept of waypoint finding is researched which is a part of basic
pathfinding algorithm. This method of waypoint finding will find the shortest path.
More time is spent in AI implementation and the procedure of the implementation in the
NWN2 and the custom made scripts that are need to achieve the deliverables of this research.
As because there are no enough documentation provided by the game developers on the
scripting methods and the NWN2 toolset the author have decided to go with the prototype in
which he explained about the effect of NPC behaviour by using the hardcode methods and
animation procedure. The author has to depend merely on the forums created by enthusiastic
game players to do the custom made scripts and the user generated forums are not always
worth depending for a project. The time factor effected the development of the
implementation as there is a very limited to research and learn the new scripting language.
The author has to learn all the custom made methods and events merely depending on the fan
forums.
5.3 Testing
In the final phase the working version of the smart terrain AI in a NWN2 module is tested.
Before going to testing a self-evaluation is done and the implementation is finally checked for
any functionality issues. A group of twelve people has been selected depending on their
experience of gaming and experience on RPG games in general from university of
Wolverhampton and international students at the university. However some of the people that
are selected have varying experience previously in RPG and NWN2, and some of them
havent got any experience in game. This is because as this research involves the user
experience measuring. It is been considered best to select a couple of non-game experience
persons, so that the results of the outcome will be precise to fulfil the aim of this research.
The layout of the test consists of five sections; all of them are well advised to the tester,
In the first section the tester gets an introduction about the NWN2 game and the
intension of this research to make the tester understand the purpose of the research and
to let them know of about what they are going to do and in what circumstances.
54
In the second section the tester is informed of what part he is going to test in the game
specifically and what does he have to observe in the test, though there are some
questions related to the test at the end of the testing phase, but still it is the better
practice to let the tester know about what he is going to test in this module.
In the third section the tester is been given a quick tutorial to inform the tester how to
proceed between the different steps in the game and what are the game functionalities
and key combinations to navigate between the characters and the worlds that they are
dealing with, this will help the new players to know about the game architecture and
functionalities in the game so that they can test the module properly without hassles
Once the tester has completed testing the module, then he is handed over a final questionnaire
set-2 to answer some questions relating to the experience that he had in the developed
module. While this might limit the testers form answering the questions with their own exact
words. It makes it easier to draw conclusions from the results. Since the author of the research
was present during all of the rests, oral results for additional responses, alternatives has been
taken and added if needed at the time of testing.
One part of the questionnaire aims to first categorise the test subject depending on his/her
background with RPGs, and also to make the subject experience the effect of NPCs in the
default module. This is because background might have an impact on expectations as well as
impressions of realism and thereby might affect the results slightly. And also to make the
55
subject get acquainted with the game if he/she hasnt got experiences with the game
previously.
The second part of the questionnaire will be rather direct and pointed to the experience of the
tester with the new module asking him/her the different aspects if the NPCs behaviour
compares to the original NWN2 NPCs. Finally the tester gets to say whether he/she fins the
smart terrain AI more realistic than the original campaign.
56
both the versions they got to rare the original NWN AI as well as the smart terrain AI in that
order. The result of this is illustrated in the figure 5(d).
57
Figure 5(b): Figure shows the bar chart of the results that obtained from questionnaire.
58
Figure 5(c): Figure showing pie diagrams of all the testers on NPCs AI.
59
Figure 5(d): Figure showing the AI comparison between both the AIs
The graph illustrates where the testers put their votes for the two version of the AI. The Y-axis
marks the number of testers, and the X-axis represents the score. The local maximum values
represents where most of the testers put their scores. It means to give an indication of the
average opinion of testers as a group.
In the above figure we can see how the smart terrain AI overall have been rated higher in
comparison to the original campaign one, the curves maximums represents in the average
score rating from the testers as a group for the two, and a clear difference can be read from it.
It appears from it.
60
Chapter 6
6.1 Introduction
In this chapter the author is going to discuss the critical evaluation part of the research and
also the answers to the research questions that are set up for this research, the change of
research implementation is also mentioned backing up with the reason of development of a
prototype instead of an actual artefact. The time schedule changes are also discussed in this
section, thereafter concluding the research project.
61
complete scripting in scheduled time. The change in the implementation procedure is been
informed to the authors supervisor.
Original deliverables
Improve realism in RPGs through enhancing the NPCs AI using Smart Terrain
technique.
Implementation of Smart Terrain technique in NWscript, which is a good scripting
tool for NWN2.
Altered deliverables
The second part is mainly altered to suit the new implementation process. And the new
deliverable is
62
63
Following Gantt chart will explain the actual project management as it has gone through.
64
Figure 6(d): Figure showing the tasks involved in the actual Gantt chart.
65
Can realistic behaviour of the NPCs does really affect the gamers experience?
This is a very difficult question to answer, with the results obtained. It can be said that it
will indeed improve it for most users. Its something that is opinion related and varies
from person to person. However the author can safely assume that none would feel that
the game feelings would suffer from the improved NPCs AI. Therefore judging by the test
results of the testers who felt it increased the realism. We could consider that answer Yes
for this question if we look at gamers as a group of people instead of individualistic
perspective.
Basing on the research implementation, clearly it can be said that the NPCs part of the
game AI has to improve more to make the game successful in all respects. The testers who
participated in the test have expressed their feelings on the game on a whole as very good
in graphics and more rich visuals but lack the realistic behaviours of NPCs AI.
Does an advanced AI technique like Smart Terrain really helps in enhancing the
experience?
With the test results analysed and discussed. The author thinks by now it is very much safe
to say that the above statement is true. Smart terrain did improve the realism among the
NPCs in the NWN2 and would probably for the same for most of the RPGs.
66
6.4 Discussion
In tests like this one, there are always lots of factors that can affect the outcome. Words like
realism and game-feeling is something that is interpreted in different ways by different
people. Their background and previous experiences affects what they expect from the game
and the AI, as well as what they find entertaining. In an attempt to minimize error margins
from these kinds of factors, some questions in the tests purpose was to categorize the different
test subjects by their previous experiences. Thereby patterns and conclusions can easier be
drawn from the results.
6.5 Conclusion
As said earlier all the main concepts of the testing and analysis of the testing is dicussed
67
Woodcock.
(2000). Game
AI:
The
State
of
the
Industry. Available:
http://www.gamasutra.com/view/feature/3570/game_ai_the_state_of_the_industry.php.
Last
Stout
(2001). Smart
Move:
Intelligent
Path-Finding. Available:
Pinter
(2001).Toward
More
Realistic
Pathfinding. Available:
http://www.gamasutra.com/view/feature/3096/toward_more_realistic_pathfinding.php.
Last
68
Chow ying Kit Ricky (2006) AI Role Playing Game Development. BEng. Thesis, City
University of Hong Kong
Spronck, Pieter, (2006). Dynamic scripting. In: Steve rabin AI Game Programming wisdom
vol3. 3rd ed. USA: Charles river media,inc. P200-300.
Bertill jeppsson(2008) AI- Controlled life in Role-Playing Games. BEng. Thesis, Blenkinge
institute of technology.
Matt
Barron.
(2007). The
History
of
Computer
Role-Playing
Games. Available:
Last
for
NWscript.
[Online].[acceded
4th
sep
2010],
Available
at:
<www.nwnlexicon.com>.
Bioware,
Builder
Forum,
[online],[Acceded
4th
sep
2010]
Available
at
<http://nwn2forums.bioware.com/forums/>
Aadarsh, P. (2007) AI in games. [Online]. [Accessed on 4th sep 2010], Available at: <
http://www.slideshare.net/wuzziwug/ai-in-games>.
Kirby, N. (2002) Solving the Right Problem. In: Rabin, Steve AI Game Programming wisdom.
USA: Charles river media,inc. p21-40.
69