Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School...

Post on 12-Jan-2016

217 views 0 download

Transcript of Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School...

Programming Unreal Tournament

Joe Manojlovich (josephm@sis.pitt.edu)

University of Pittsburgh

School of Information Sciences

Points of Contact

• Usability Study Lab, 2nd floor, Information Sciences Building

• Meetings every Tuesday, Thursday 3pm to 7pm (all are welcome)

• (Unofficial) Pittsburgh Unreal Research Group– There is a surprisingly large amount of UT hacking for

research purposes going on in the Pittsburgh area• University of Pittsburgh (several schools)

• Carnegie Mellon University (several schools)

What is Unreal Tournament?

• UT is a multiplayer video game

• Produced by Epic games (http://www.epicgames.com)

• Runs on Windows, Linux, Macintosh, PlayStation, and soon Xbox

• http://www.unrealtournament.com

Old/Current Versions of Unreal

• Unreal I– The original Unreal game– Single player– Obsolete and unsold now (?)

• Unreal Tournament– Multiplayer Unreal game– Obsolete and unsold as of a month or 2 ago

New Versions of Unreal

• Unreal 2– Single player– Due 2003

• Unreal Tournament 2003– Multiplayer– Due summer 2002 (any day now…)

• Unreal Forever– Xbox– Due 2003

Why Program UT?

• By using UT as a basis for other research, you can avoid needless reinventing while benefiting from a proven development platform

• UT is designed for programming, and many tools and resources are available to assist you

Research Being Done with UT

• Gamebots– This is a modification to UT that allows one to control

UT bots remotely over a standard network connection (www.gamebots.org)

• CaveUT– This project uses multiple UT clients to create

el-cheapo 3D visualization (http://www2.sis.pitt.edu/~jacobson/ut/CaveUT.html)

• Many others…

How to Program Unreal Tournament

• UnrealScript– Source code level

• Level Programming– Graphics level

• Scenes

• People

• Weapons

UT Source Code

• Since UT is based on a virtual machine model like Java, most of the game is actually written in UnrealScript

• You can read the source code to most of the game, except the low level graphics rendering components and a few other bits

• UnrealEd will let you browse and edit the game source code

• Also available online: http://usl.sis.pitt.edu/trurl/unrealdocs

Common Terms

• Bots – Players in game under human or AI control

• Level – self-contained environment containing bots and their surroundings

• Maps – a level, without the bots

• Game – a level, with active bots, running on a UT server

Types of Games

DeathMatch•Free for all

TeamGame•Team free for all

Domination•Control of level points

Assault•Task-oriented

Capture the Flag•Goal of returning

enemy flag to home base

The Unreal Virtual Machine

• UT is divided up into several components: – Server– Client– Rendering engine– Engine support code

The Unreal Virtual Machine

Game Type

Game Code

OpenGL, DirectX, etc.

Level

Actor(s)

Engine Network

Client(s)Death Match

DM-Tutorial

Tournament Male

Underlying Hardware/Operating System

Unreal Network Architecture

ClientClient

UT is a client/server based game

Server

Client

•Currently supports 32 players on a server•This may increase with the new version of UT

Java/C++ vs. UT

• If you have some knowledge of any object-oriented language, then learning UnrealScript itself is easy

• UnrealScript is much simpler than “real” object-oriented languages which are burdened with complex features unnecessary for game development

Object-Oriented Programming

• Objects– Function code and data combined in one unit

• Classes– Templates for production of objects

• Inheritance– Classes arranged in a hierarchy, where children

classes start with properties of its parents

InheritanceAnimal•Reproduces•Consumes

Bird•Has Wings•Flies

Fish•Has Fins•Swims•Gills to Breath

Robin•Small•Red Chest

Ostrich•Large•Doesn’t Fly

Great White•Large

Goldfish•Small

Class Structure in UT

• Objects/Actors

• Pawns

• Info

Object/Actor Classes

• Object is the basic superclass for every Unreal class

• Actor class, subclass of Object, defines basic game functionality– Players– Weapons– AI– Most of the UT game itself

Pawn Class

• Subclass of Actor

• Defines the living entities of a level

• PlayerPawn, a subclass of Pawn, is used for all players in the game

• ScriptedPawn, another subclass of Pawn, is used to drive the built-in game players

Info Class

• Info classes maintain game data• GameInfo manages game related

information• ZoneInfo handles the composition of spaces

in levels, such as water, lava, etc.• PlayerReplicationInfo is used for network

games, to minimize network traffic between Unreal clients and the server

UnrealScript Syntax

• UnrealScript is a full programming language solely used for the Unreal series of video games

• Most of its syntax is very similar to other high-level programming languages such as Java or C++

Variables

• byte: A single-byte value ranging from 0 to 255.• int: A 32-bit integer value• bool: A boolean value: either "true" or "false" • float: A 32-bit floating point number• string: A string of characters• name: The name of an item in Unreal (such as the

name of a function, state, class, etc)

Variables (cont.)

• Enumeration: A variable that can take on one of several predefined name values

• Object and actor references: A variable that refers to another object or actor in the world

• Structs: Similar to C structures, UnrealScript structs let you create new variable types that contain sub-variables

Variables (cont.)

• To declare a variable:

var int a;

var byte Table[64];

var string[32] PlayerName;

var actor Other;

Language Constructs

• UT supports all the standard loops, like those in Java or C++– If – For– While– Do-While

UnrealScript States

• States are unique to game programming languages like UnrealScript

• Allow one to define functionality based time and state of a bot

• For example, a bot could have a “Running” state that will cause the bot to flip while jumping, but only while running, and not while standing still or walking

An Example State

auto state Idle {

Begin:

log( "I am idle!" );

sleep( 10 );

goto 'Begin';

}

An Example State (cont.)

• All this state does is override a built-in inherited state that is active when a bot isn’t doing anything, i.e., idle

• Every 10 seconds of idle time, this code will print to the log “I am idle!”

Modifications

• Mutators– Used to make slight changes to the game– Subclass parts of the game, and redefine game

code– Can be mixed with other mutators at run-time

• Gametypes– Used to change large parts of the game– Cannot combine with other gametypes

Using the Command Line ToolsStart->Programs->Accessories->Command Prompt

cd C:\UnrealTournament\System

An Example Mutator

• Remember that mutators simply take some built-in functionality of UT and modify it slightly

• Mutators subclass the UT Mutator class• For this example, we’ll create a low gravity

mutator. The game already has one built in, but it makes a good example, as it’s very simple.

The Low Grav Mutator

• In the UnrealTournament directory, create a directory named “MyPackage” and inside that a directory named “Classes”

• Create a text file named LowGrav.uc in the Classes directory

• Edit the UnrealTournament.ini file, in the System directory, and add your package name to the EditPackages list

The Low Grav Mutator (cont.)

• class LowGrav expands Mutator; – Each source file will have this class declaration,

and only one class can be in each source file

The Low Grav Mutator (cont.)

• function bool CheckReplacement(Actor Other, out byte bSuperRelevant) {

if( Other.IsA('ZoneInfo')) {ZoneInfo(Other).ZoneGravity =

vect(0,0,-200); }return true;

}

• An inherited function, used to replace or modify actors in a level

The Low Grav Mutator (cont.)

• In the command prompt, enter the UnrealTournament/System directory

• Type ucc make all • Create a text file named MyPackage.int in this

directory, with the contents (one line): Object=(Name=MyPackage.LowGrav,Class=Class,

MetaClass=Engine.Mutator,Description=“My Low

Gravity, My Low Gravity") • This will make your mutator show up in the game

menus

The Low Grav Mutator (cont.)

• To run your mutator, start UT

• Start a new practice session

• Click on the Mutators button

• Scroll down to “My Low Gravity” and double click on it

• Close the window, and start the practice session

UnrealEd

• UT comes with a dedicated 3D level modeling and source code editing program

• Most do actual coding outside of UnrealEd, since many prefer to use other source code development tools such as Microsoft Developer Studio

• Most source code work done by UnrealEd can also be done from the command line

Using UnrealEd

• Start program UnrealEd.exe in the UnrealTournament/System directory

• Most people design maps in more mature 3D modeling program, such as Maya or 3D Studio Max

• UnrealEd is fine for doing pure UT design that is not too complex

An Example Level

• I was planning to show an example of creating a level here, using UnrealEd, but it’s not something that lends itself well to a presentation

• This is also a cheap way for me to get out of admitting that I don’t know much about level programming

Unreal Graphics

• Meshes– These are the skeletons that form the bodies of

UT creatures– Have no defined surface

• Textures– Applied to meshes to provide a surfaces

Resources

• http://unreal.epicgames.com

• http://www.planetunreal.com

• http://www.unrealscript.com

Questions

• Questions, concerns, comments, sarcasm, insults?

• Please email or come to the group meetings on Tuesdays and Thursdays… there are just so many little tips and tricks that are best learned in person