From Unreal Wiki, The Unreal Engine Documentation Site

Contents

Note: This page represents an idea for a proposed way of coding some particular functionality/behavior in UnrealScript. It does not represent the way that UT/UT2003/UT2004 actually do things in the normal game engine.

I was thinking of way to construct classes that could behave with other classes in a group fasion. I came across the idea of using the C++ ideas of binary trees and linked lists to get the job done. It may be put to good use in forming a hierarchy among classes. It allows us to form "groups" of classes with parents,children, heads, and tails, which can later be used to construct "group" behaviour. Now, linked lists and binary trees can be used, but I feel it depends on the complexity of ones groups. For those of you who don't know of linked lists or binary trees, below is an overview of the linked list and the binary tree idea.

A linked list is basically a list of chunks of data linked together. Each "chunk" of data is known as a node. Each node contains some data and some form of "linking" itself to another node. In C++, usually each node has some data, and a pointer to another node. This form is knows as a singly-linked list. Some linked lists have nodes with pointers to the the next node, and the previous node in the list. These types of lists are known as doubly-linked lists. Each list has a head, and a tail. The head being the first node in the list, and the tail being the last node in the lists. Linked lists are an effective way of storing complex datatypes in an array-like structure.

Generally, a linked list is used when an array-type structure is needed but the final size of the array is not known, or, elements within the array are often moved, added, and removed. Linked lists are generally un-ordered although elements can be efficiently sorted into position as they are added to the list.

Binary trees are ways of storing data in hierarchial structure composed of nodes (elements of the structure that have children) and leaves (elements of the structure that have no children). A binary tree has a parent node, and two child nodes.

Large trees can be constructed by having contain more node elements than leaf elements – imagine having several layers of nodes with child nodes. This provides a good foundation for searching and finding positional status (if the nodes and leaves are ordered).

Say I wanted to create a group of skaarj that had a hierarchy with a leader and a general. I would need two classes, List, and ListNode. List could contain a ListNode head, a ListNode tail, and a name listName. ListNode could contain an instance of a scripted pawn called _skaarj, lowerSkaarj, and higherSkaarj.

This node forms a doubly linked list. We will have to modify the skaarj class a little to include a list if in a group. So lets do that:

class Skaarj extends ScriptedPawn;//added variablevar() List group;

Now we could form a hierarchy by creating a List of Skaarj. Say I created a map and in it I have six skaarj: Larry, George, Matt, Jack, Tarquin, and Mychaeel. All six skaarj have a group since we just added it above. I will now create a list.

Fairly pseudo assuming all this would be done in the map editor by the mapper, but that is what would be happening in code.

As you can see this sets up a hierarchy with Larry at the top, Matt at the bottom, and George, Jack, Tarquin, and Mychaeel down the list. With this you can setup different responsibilities and behaviour:

I didn't want to break your lovely example above with some unweildy hackings and slashings so I thought I'd comment here.

As far as I can tell you are attempting to construct a structre that will allow groups of objects (in this case enemies) to be handled with some sort of priority (superiority) order. Also, that the numbers of objects within these groups can change, or are not known. What is shown below is merely a suggested class definition. The benefit of abstracting the data elements from the actual list element (ListElement) class is that the code can then be re-used every other time you need similar functionality.

// I don't know if you can actually subclass from object - but this class needs to be as light as you can make it.class ListElement extendsObject;var ListElement parent;// A pointer to the parent element of this object -- null if there isn't one.var ListElement child;// A pointer to the _first_ child element of this object -- null if there isn't one.var ListElement next;// A pointer to the next sibling element of this object -- null if there isn't one.var ListElement prev;// A pointer to the previous element of this object -- null if there isn't one.varObject data;// A pointer to the object containing the data to be held in the list -- null if there is no data.// Functions to add, remove, and search for elements go here (see below for more info).

Probably the most vital functions needed within this class are the AddChild() and AddSibling(). These functions must set the parent attribute of the object correctly at the point it is inserted into the list. Personally, I'd have functions to handle just about every operation you can think of on the class simply because it allows the pointer manipulation to be hidden and held all in one place. It also means you can change the way in which the data is stored should you need to.

One thing I would note though. If you know you are going to have very few elements in a list (say less than 10) then consider using an array and handling the null pointers (assuming sparse population). It will be quicker – particularly if the data needs to be replicated to the client.

I think that's all from me.

Foogod: I added the disclaimer at the top, because the way these pages are linked from Artificial Intelligence could confuse some people into thinking this is an explanation of the way that the UT-based games actually do things.