• Tobias Schwarz
  • Compile and install OpenTTD on a Raspberry Pi and run a dedicated server

Compile and install OpenTTD on a Raspberry Pi and run a dedicated server

Mon, Dec 12, 2016

Motivation

From time to time I play OpenTTD with friends. When we do we usually play a map for quite some time. This requires a dedicated server and I had one running on my Raspberry Pi for quite a while. However I reinstalled Raspbian and therefore had to setup the OpenTTD server again.

Since I forgot all the steps and there still is no arm package of the latest release, I had to compile the source code and figure out all the steps for the setup again. Next time I will have this guide to look at.

Compile and install OpenTTD

Open a shell

This guide is based on a fresh raspbian install. Login as the default pi user using SSH or if you do this from within the desktop just start the terminal. Make sure you are in your home directory:

cd ~

Download the OpenTTD source code

wget https://binaries.openttd.org/releases/1.6.1/openttd-1.6.1-source.tar.gz

Extract the OpenTTD source code

tar xvzf openttd-1.6.1-source.tar.gz

Dependencies for compiling OpenTTD

sudo apt-get update
sudo apt-get install build-essential pkg-config libsdl1.2-dev subversion patch zlib1g-dev liblzo2-dev liblzma-dev libfontconfig-dev libicu-dev

Compile OpenTTD as dedicated server from source code

cd openttd-1.6.1/
./configure --enable-dedicated
make --jobs=4

On multicore systems like the Raspberry Pi 2 and Raspberry Pi 3 you should use multiple threads to compile faster. Under Linux the number of logical cores can be obtained using:

getconf _NPROCESSORS_ONLN

Install the OpenTTD binary

sudo make install

Setup and configure the dedicated server

Install init script for OpenTTD server

To automatically start and stop the OpenTTD server I use the OpenTTD Init Script (Archive.org) (an accessible copy might be here) written by Frode Woldsund:

Download and extract the script

cd ~
wget https://bitbucket.org/frodus/openttd-init/downloads/openttd-init-1.2.1.zip
unzip openttd-init-1.2.1.zip

Install dependencies

sudo apt-get install screen

Install the script

sudo ln -s ~/openttd-init/openttd /etc/init.d/openttd
chmod 755 ~/openttd-init/openttd
sudo update-rc.d openttd defaults

Rename and edit the init config file

mv openttd-init/config.example openttd-init/config
nano openttd-init/config

In the config file I only changed the username:

USERNAME="pi"

Install zBase 32bit graphics set

The old OpenTTD graphics don’t look good. There is a 32bit replacement called zBase and I like it a lot. The install can be done like this:

wget http://binaries.openttd.org/bananas/basegraphic/zBase-v5588.tar.gz
gunzip zBase-v5588.tar.gz
mkdir -p .openttd/baseset
mv zBase-v5588.tar .openttd/baseset

Note: If you don’t install a graphics set at this point the server won’t start! You won’t see an error message because of the startup script! If you don’t like zBase you need to install another graphics set instead!

Create a config file for the OpenTTD server

To create a config file I just created an empty config file and started and stopped the OpenTTD server to fill it with the default values:

touch ~/.openttd/openttd.cfg
sudo service openttd start
sudo service openttd stop

Afterwards the config file can be edited

nano ~/.openttd/openttd.cfg

Here are the basic settings I changed:

; set passwords for the server
server_password = letmein
rcon_password = letmein
admin_password = letmein
; set a name for the server
server_name = Noki's Server
; Pause game without active clients
min_active_clients = 1
; increase number of vehicles to maximum
max_trains = 5000
max_roadveh = 5000
max_aircraft = 5000
max_ships = 5000
; set the curreny
currency = EUR
; set map size to 512x512
map_x = 9
map_y = 9
; set start year to 1970
starting_year = 1970
; set autosave to yearly
autosave = yearly

In addition I usually change the cargo distribution to async:

; change the cargo distribution to async
distribution_pax = 1
distribution_mail = 1
distribution_armoured = 1
distribution_default = 1

There is a documentation for the openttd.cfg settings in the OpenTTD wiki.

Setup an autosave

Finally I setup a cronjob that creates a savegame every six hours:

sudo crontab -e

I add this line and save the file:

0 */6 * * * /etc/init.d/openttd autosave

Make gameplay easier

Universal Rail Type

With the Universal Rail Type NewGRF train replacement becomes easier. It allows to use Autoreplace to convert engines and wagons into models of other rail types. This is especially usefull for upgrades to monorail and maglev.

The install is easy:

I usually do it once the server is up and running. I just use the admin console to install it:

rcon letmein "content update"
rcon letmein "content state"
rcon letmein "content select 2699"
rcon letmein "content download"

Then I stop the server:

sudo service openttd stop

Then I enable the railtype in openttd.conf:

[newgrf]
Universal_Rail_Type-2.0.1/universalrailtype.grf =

Then I start the sever:

sudo service openttd start

And finally I start a new game using the console:

rcon letmein "newgame"

Final thoughs

I really wish there would be an debian package for arm that makes installing and updating OpenTTD simpler. However next time I will just look at this post and manage to reinstall OpenTTD in minutes.

Feel free to contact me if you have anything to add to this guide.