Programming Unreal Tournament Joe Manojlovich ([email protected]) University of Pittsburgh School...

43
Programming Unreal Tournament Joe Manojlovich ([email protected]) University of Pittsburgh School of Information Sciences

Transcript of Programming Unreal Tournament Joe Manojlovich ([email protected]) University of Pittsburgh School...

Page 1: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

Programming Unreal Tournament

Joe Manojlovich ([email protected])

University of Pittsburgh

School of Information Sciences

Page 2: 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)

Page 3: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 4: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 5: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 6: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 7: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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…

Page 8: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

How to Program Unreal Tournament

• UnrealScript– Source code level

• Level Programming– Graphics level

• Scenes

• People

• Weapons

Page 9: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 10: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 11: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 12: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

The Unreal Virtual Machine

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

Page 13: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 14: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 15: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 16: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 17: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 18: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

Class Structure in UT

• Objects/Actors

• Pawns

• Info

Page 19: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 20: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 21: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 22: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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++

Page 23: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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)

Page 24: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 25: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

Variables (cont.)

• To declare a variable:

var int a;

var byte Table[64];

var string[32] PlayerName;

var actor Other;

Page 26: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

Language Constructs

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

Page 27: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 28: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

An Example State

auto state Idle {

Begin:

log( "I am idle!" );

sleep( 10 );

goto 'Begin';

}

Page 29: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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!”

Page 30: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 31: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

cd C:\UnrealTournament\System

Page 32: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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.

Page 33: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 34: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 35: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 36: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 37: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 38: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 39: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 40: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 41: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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

Page 42: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

Resources

• http://unreal.epicgames.com

• http://www.planetunreal.com

• http://www.unrealscript.com

Page 43: Programming Unreal Tournament Joe Manojlovich (josephm@sis.pitt.edu) University of Pittsburgh School of Information Sciences.

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