Train Lord is a live massively multiplayer game (MMOG) using real world data and maps. The goal is simple. Become the richest lord in the world by buying rails, stations, trains, creating rail sets and dispatching trains. I have been developing this game and learning a lot of technologies to put all the stuff together since February 2012. Starting November I was able to release the first version live. Click here to play, here to see help page, or here for Communuty page. I would like to describe and give credits to some technologies I have used, so it may help other developers as well as myself somewhere in the future ;-).
First, I would like to share gameplay / manual screencast video with captions. In this video you can see the main objectives you have to accomplish in order to rule the game.
The client application (game) was completly written in ActionScript. I am using a Flex framework for ui components and for performance reasons I write directly .as (no .mxml) even for components and skins.
I have utilized my YCanvas project – an open source ActionScript 3 library that provides stage3D (GPU) engine for perfectly overlapping grid based zooming projects like world maps or onBoard or simply a tile maps renderer.
YCanvas is based on Starling – The Open Source Game Engine for Flash. Using stage3D you can achieve really smooth 60fps gaming experience.
Once experienced I never start a project with IoC other than Robotlegs – a pure AS3 micro-architecture (framework) with a light footprint and limited scope. Simply put, Robotlegs is there to help you wire your objects together. It provides the glue that your application needs to easily function in a decoupled way. Through the use of automated metadata based dependency injection Robotlegs removes boilerplate code in an application.
Most of the eventing is handled by Signals – a new approach for AS3 events, inspired by C# events and signals/slots in Qt.
A great lightweight and fast tweening lib you all already know is from Greensock.
While looking for train models all over the internet I found there are a lot of available already for Microsoft Train Simulator created by indie modellers. Here are some of them in Czech Republic doing a great job – Skura, Duuso, Jacek, Ondraj, Kank…
As I only needed a top view and a side view, I used Shape Viewer – displays an entire shape on screen without having to load up MSTS itself enabling you to examine the entire model and lets you see exactly what it looks like in the sim.
As often as I work with services I always use Charles Proxy – an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information). If you have not had the pleasure to meet this tool, now its right time to do so.
The game uses a real world data from OpenStreetMap project, especialy I took advantage of Planet.osm – an XML file that contains all the data you can see on the generated maps (streets, buildings, lakes, countries…). Currently it contains more than 25GB of bz-ed data in total. I recommend downloading the file via torrents from torres.voyager.hr.
To parse that much data and extract just rails and stations takes some time. There is a great tool for this called Osmosis – a command line Java application for processing OSM data. The tool consists of a series of pluggable components that can be chained together to perform a larger operation. For example, it has components for reading from database and from file, components for writing to database and to file, components for deriving and applying change sets to data sources, components for sorting data, etc. Even with this tool it takes hours to parse a whole world. There is a way osmosis would pass the data directly into database, but I did not have that luck to make it running.
To put this data from .osm file to a database I tried XSL – Extensible Stylesheet Language (XSL) is used to refer to a family of languages used to transform and render XML documents. But it soon appeared that it can not handle big files.
So I discovered STX – Streaming Transformations for XML (STX) is a one-pass transformation language for XML documents. STX is intended as a high-speed, low memory consumption alternative to XSLT, using the W3C XQuery 1.0 and XPath 2.0 Data Model. Since STX does not require the construction of an in-memory tree, it is suitable for use in resource constrained scenarios. Oh yeah this beast can handle 4GB .osm file like nothing!
To transfer the data to client I decided to use AMF – a binary format used to serialize objects graphs such as ActionScript objects and XML, or send messages between an Adobe Flash client and a remote service. At first I tried ZendAMF but I did not get the performance as good as what AMFPHP provides. It seems this project has been reborn after few years of hibernating. It appeared that none of amf libs in php were capable of handling large datasets and while I ended up exceeding php memory limits too often I decided to switch to JSON gateway.
I decided to implement 3rd party login services so users do not have to create an account (and forget a password every time) when playing. Facebook, Twitter and Google logins are implemented for a better comfort and running nicely on the backend.
… almost forgotten to mention Ip Address Locator – a service (IP Address Map lookup service) provided by Geobytes, inc to assist you in locating the geographical location of an IP Address. It does the black magic behind locating the initial position on the map – your home city.
As you can see a lot of technologies were involved to prepare and run the game. And I did not even mention the common ones. Having smooth user experience playing a game with real world data, flash remains to be a perfect technology. I hope you like the game and please leave me some feedback.