summaryrefslogtreecommitdiff
path: root/tw/packages/games.scm
blob: ca6d6308575ed33d12947613e63ce821c4fcd078 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
(define-module (tw packages games)
  #:use-module (guile)   ; for `geiser-eval-buffer-and-go' to work properly
  #:use-module ((ice-9 string-fun) #:select (string-replace-substring))
  #:use-module (gnu packages audio)
  #:use-module (gnu packages base)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages fonts)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages image)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages textutils)
  #:use-module (guix build utils)
  #:use-module (guix build-system copy)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages))

(define-public simutrans-pak128
  ;; Install paks as propagated-inputs of simutrans, so they go in
  ;; Simutrans' data directory, where Simutrans expects them.
  (package
   (name "simutrans-pak128")            ; note: needs simutrans >= 123
   (version "2.8.2")
   (source (origin
            (method url-fetch)
            (uri (string-append
                  "mirror://sourceforge/simutrans/pak128/"
                  "pak128%202.8.2%20for%20ST%20123up/simupak128-2.8.2-for123.zip"))
            (sha256 (base32 "0hzpb6bh1lh0fdcpxlbfw5j74xz65gxl8yx5094rqf5zflvz10py"))))
   (native-inputs (list unzip))   ; shouldn't copy-build-system / origin handle this?
   (build-system copy-build-system)
   (arguments '(#:install-plan '(("pak128" "share/games/simutrans/pak128"))))
   (home-page "https://forum.simutrans.com/index.php?board=26.0")
   (synopsis "Graphical pak set for Simutrans, 128x128 tile size")
   (description
    (string-append
     "When Simutrans could only support 64px size graphics, pak128 already started.  "
     "First pak to feature a complex economy and have a very wide variety of objects.  "
     "It contains roughly 7 times more graphic data than pak64 and thus requires by far "
     "the largest amount of RAM and processing power of all Simutrans sets."))
   (license license:artistic2.0)))

(define simutrans-paths-patch
  (plain-file "simutrans-paths.patch" "\
This patch stores user-specific config in $XDG_CONFIG_HOME/simutrans
rather than ~/simutrans.

--- a/sys/simsys.cc	2022-09-25 01:36:18.951636483 +0200
+++ b/sys/simsys.cc	2022-09-25 01:36:44.615457050 +0200
@@ -395,7 +395,11 @@
 #elif defined __ANDROID__
 	tstrncpy(buffer,SDL_GetPrefPath(\"Simutrans Team\",\"simutrans\"),lengthof(buffer));
 #else
-	sprintf(buffer, \"%s/simutrans\", getenv(\"HOME\"));
+	if (getenv(\"XDG_CONFIG_HOME\") == NULL) {
+		sprintf(buffer, \"%s/.config/simutrans\", getenv(\"HOME\"));
+	} else {
+		sprintf(buffer, \"%s/simutrans\", getenv(\"XDG_CONFIG_HOME\"));
+	}
 #endif
 
 	// create directory and subdirectories
"))

(define simutrans-desktop-entry "\
[Desktop Entry]
Name=Simutrans
Comment=Transportation simulator
Exec=simutrans
Icon=simutrans
Terminal=false
Type=Application
Categories=Game;Simulation;
")

(define simutrans-appdata-xml "\
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<component type=\"desktop-application\">
<id>com.simutrans.simutrans</id>
<launchable type=\"desktop-id\">simutrans.desktop</launchable>
<name>Simutrans</name>
<summary>Transportation simulator</summary>
<metadata_license>CC0-1.0</metadata_license>
<project_license>Artistic-1.0</project_license>
<description>
<p>Simutrans is a free transportation simulator: the player operates a transportation \
company and has to transport goods and passengers between factories and different cities.</p>
</description>
<screenshots>
<screenshot type=\"default\">
<image>https://screenshots.debian.net/screenshots/000/001/205/large.png</image>
</screenshot>
</screenshots>
<url type=\"bugtracker\">https://forum.simutrans.com/index.php?board=8.0</url>
<url type=\"homepage\">https://www.simutrans.com/</url>
</component>
")

(define-public simutrans/pak128
  ;; Based off the Arch Linux package:
  ;; https://github.com/archlinux/svntogit-community/blob/packages/simutrans/trunk/PKGBUILD
  ;; I took the idea of a wrapper script from the Nix package:
  ;; https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/simutrans/default.nix
  (package
   (name "simutrans")
   (version "123.0.1")
   (source (origin
            (method url-fetch/zipbomb)
            (uri (let ((version/- (string-replace-substring version "." "-")))
                   (string-append "mirror://sourceforge/simutrans/simutrans/"
                                  version/- "/simutrans-src-" version/- ".zip")))
            ;; Use `guix hash -H sha256 <file>'.
            (sha256 (base32 "0sgl2hrgjd2cyw3fbcvpq29dwf0w2sdlpp8ccic5bys1vv43iswd"))
            (patches (list simutrans-paths-patch))))
   (build-system gnu-build-system)
   (arguments
    `(#:make-flags
      '("VERBOSE=1" "OPTIMISE=1" "OSTYPE=linux" "BACKEND=sdl2" "MULTI_THREAD=1"
        "USE_ZSTD=1" "USE_FREETYPE=1" "USE_FLUIDSYNTH_MIDI=1")
      #:tests? #f           ; tests don't work as SDL2 can't find a video device
      #:test-target "test"  ; run "make test" for tests
      #:phases
      (modify-phases %standard-phases
        (replace 'bootstrap
          (lambda _
            (invoke "find" "." "-type" "f" "-exec" "dos2unix" "-q" "{}" ";")
            (substitute* "Makefile"
              (("\\\\#define") "#define"))))
        (replace 'configure
          (lambda _
            (copy-file "config.template" "config.default")))

        (replace 'install
          (lambda* (#:key inputs outputs #:allow-other-keys)
            (let ((out (assoc-ref outputs "out")))
              ;; Install "real" simutrans executable into libexec, as we need a wrapper script.
              (with-directory-excursion "build/default"
                (rename-file "sim" "simutrans"))
              (install-file "build/default/simutrans"
                            (string-append out "/libexec"))
              ;; Install wrapper script to pass the right workdir to simutrans.
              (mkdir-p (string-append out "/bin"))
              (with-output-to-file (string-append out "/bin/simutrans")
                (lambda ()
                  (format #t "#! ~a/bin/guile --no-auto-compile\n!#\n~s\n"
                          (assoc-ref inputs "guile") 
                          `(apply execl ,(string-append out "/libexec/simutrans") "simutrans"
                                  "-set_workdir" ,(string-append out "/share/games/simutrans")
                                  (cdr (command-line))))))
              (chmod (string-append out "/bin/simutrans") #o755)

              ;; Install game data bundled with simutrans (not the pak).
              (mkdir-p (string-append out "/share/games/simutrans"))
              (copy-recursively
               "simutrans" (string-append out "/share/games/simutrans"))
              ;; Install a symlink to our pak, as simutrans needs all its data in one directory.
              (let ((pak (assoc-ref inputs "simutrans-pak128")))
                (symlink (string-append pak "/share/games/simutrans/pak128")
                         (string-append out "/share/games/simutrans/pak128")))

              ;; Install extra helper files.
              (install-file "simutrans.svg"
                            (string-append out "/share/icons/hicolor/scalable/apps"))
              (mkdir-p (string-append out "/share/applications"))
              (with-output-to-file
                  (string-append out "/share/applications/simutrans.desktop")
                (lambda () (display ,simutrans-desktop-entry)))
              (mkdir-p (string-append out "/share/metainfo"))
              (with-output-to-file
                  (string-append out "/share/metainfo/simutrans.appdata.xml")
                (lambda () (display ,simutrans-appdata-xml)))))))))

   (inputs `(,zlib ,bzip2 ,libpng ,sdl2               ; these are required
             (,zstd "lib") ,freetype ,fluidsynth      ; these are technically optional
             ,guile-3.0 ,simutrans-pak128))
   (native-inputs (list pkg-config findutils dos2unix)) ; build-time deps
   (home-page "https://www.simutrans.com/")
   (synopsis "Transportation simulation game")
   (description
    (string-append
     "Simutrans is a freeware and open-source transportation simulator.  "
     "Your goal is to establish a successful transport company.  "
     "Transport passengers, mail and goods by rail, road, ship, and even air.  "
     "Interconnect districts, cities, public buildings, industries and tourist "
     "attractions by building a transport network you always dreamed of.  "
     "This package comes bundled with simutrans-pak128."))
   (license
    (license:non-copyleft
     (string-append
      "https://raw.githubusercontent.com/aburch/simutrans/"
      "8593f5b1248d03f907a149f7abc41ae6512009e1/simutrans/license.txt")
     "This is Simutrans' custom artistic license."))))