Introducing Train Lord

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.

Client

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.

Server

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!

Once my .osm is parsed into .sql, I use MySQL database to store the data. OpenStreetMap recomends to use Postgre though.

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.

14 comments so far

  1. wen November 8, 2012 15:10

    Great concept, great game ! I’m addicted to it.

  2. Jozef Chúťka November 14, 2012 16:08

    @wen, that is good to hear, I think you have a lot of rivals there 😉

  3. febs November 24, 2012 11:22

    Hello dude.
    I started to play, I realized something went wrong so I deleted my account to start over.
    Unfortunately, the trails I bought are now owned by someone else (with my same name – read, owned by my old account now deleted and that is still named as my new one, since I log-on again with twitter).
    Is that normal? thanks!

  4. Jozef Chúťka November 24, 2012 12:33

    hi febs,
    what is your current account username? is that Fabio Spelta? if so can you send me rail id that you think is still assigned to deleted user?

  5. Ariel Sommeria-Klein March 12, 2013 12:53

    Hi,
    if you’d like to use AMF but have trouble with AmfPHP performance, I suggest you have a look at Baguette AMF. It’s a C extension for parsing AMF and integrates seamlessly with AmfPHP
    Please let me know how it goes if you try.
    best,
    Ariel Sommeria-Klein, maintainer of AmfPHP and creator of Baguette AMF

  6. Jozef Chúťka March 12, 2013 15:14

    hi Ariel,
    its good to know things evolves with amf. If I remember correctly, the issue I had with amfphp is that my php run out of memory pretty fast. Also after switching away from amf I realized I will need to use object pool on client side (id based pools to keep just single instance of an object with a specific ids even in multiple requests). I will consider baguette amf for my next project. Thank you for sharing

  7. PensieroL March 18, 2013 22:22

    Hi Jozef, this game is a great idea, and I think OSM has a lot of potentiality for game development.

    The game is already enjoyable, but after a playing it a bit, you realize that it will be useful to have this, that and other featues, now I do not have a Facebook account, so I do not know if there is already some kind of discussion around enhancements or whishlist, in that case, could be possible to have access to them w/o Facebook account?

    Do you plan to publish the code and/or accept contributions? It will improve faster with a community around it, but of course this is your choice 🙂

    Thanks for the nice job done!

  8. Jozef Chúťka March 18, 2013 23:00

    hi PensieroL,
    thank you for your feedback. You can play Train Lord on http://trainlord.com where you can use sso service you want: facebook, twitter, google or kongregate. I am not planning to implement custom registrations for now. I am currently porting the game to android, but it takes some time – thats why there is not much updates in the web game last weeks. For now I am not considering releasing the code but who knows in the future 🙂

  9. Edu GALCERAN September 3, 2013 00:00

    I can’t update game in my iPhone And myIPad, and i can’t play. I like this game but i can’t play, why????

  10. Jozef Chúťka September 3, 2013 09:53

    sorry for this inconvenience. I have uploaded the new version to iTunes, but it is with “Waiting For Review” status for a couple of days already. Its always difficult with apple unlike with android where I can release new version instantly… We both have to be patient in this matter. Last time it took 4 days to pass the review, now its somethinbg like 5 since my upload so it should be ready soon.

  11. […] implementation is taken from TrainLord as it runs on web (flash), android and iOS (AIR) platforms. Facebook’s authentication flows […]

  12. marouy November 21, 2013 15:25

    I have a problem. i play a game but it show Unexpected response from service and then show Login fall and i don’t give a money for rute it hapen more 3 time please fix a problem

  13. DeathKnyte May 8, 2014 05:52

    Hiya Jozef,

    I have been playing your game lately (user name in game same as here), and have some ideas I would like to discuss with you. However, I can’t seem to find a way to contact you, as I don’t do facebook nor twiiter, which are the links provided in the help menu in your game.

    I had to give my own e-mail to comment here, so please send me a message so that I have yours. Thanks.

  14. artemy August 1, 2015 21:01

    The game is great. Sometimes trains it crash, another coming from behind with a diferent speed. Can you set in game some switches to put a train in waiting. If a trais is aproaching too much from another you will just need to find a switcher in front of train and to put him to waiting. Ty, i hope you will reconsider 🙂

Leave a comment

Please be polite and on topic. Your e-mail will never be published.