-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
2508 lines (2055 loc) · 103 KB
/
generate.py
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import itertools
import pathlib
from collections import defaultdict
from typing import Optional, Union
from typeguard import typechecked
import grf
from grf import ZOOM_NORMAL, ZOOM_2X, ZOOM_4X, TEMPERATE, ARCTIC, TROPICAL, TOYLAND, ALL_CLIMATES
import lib
cc = lib.MagentaToCC
struct = lib.MagentaToStruct
def animated(name, grid, *args, layers=None, ignore_layers=None, **kw):
grid_args = {}
if isinstance(grid, lib.BaseGrid):
grid_args = {'keep_state': True}
if isinstance(grid, lib.BaseGrid):
if ignore_layers is None:
ignore_layers = grid.get_default('ignore_layers')
if layers is None:
layers = grid.get_default('layers')
if ignore_layers is None:
if layers is None:
ignore_layers = ('ANIMATED',)
elif isinstance(ignore_layers, tuple):
ignore_layers = ignore_layers + ('ANIMATED',)
else:
ignore_layers = (ignore_layers, 'ANIMATED')
assert layers is None or ignore_layers is None
return lib.MagentaAndMask(
grid(name + '_rgb', *args, **kw, layers=layers, ignore_layers=ignore_layers, **grid_args),
grid(name + '_anim', *args, **kw, layers=('ANIMATED',), ignore_layers=None),
name=name,
)
SPRITE_DIR = pathlib.Path('sprites')
TERRAIN_DIR = SPRITE_DIR / 'terrain'
VEHICLE_DIR = SPRITE_DIR / 'vehicles'
INFRA_DIR = SPRITE_DIR / 'infrastructure'
INDUSTRY_DIR = SPRITE_DIR / 'industries'
TOWN_DIR = SPRITE_DIR / 'towns'
STATION_DIR = SPRITE_DIR / 'stations'
TREE_DIR = SPRITE_DIR / 'trees'
EFFECT_DIR = SPRITE_DIR / 'effects'
ICON_DIR = SPRITE_DIR / 'icons'
FACES_DIR = SPRITE_DIR / 'faces'
g = grf.NewGRF(
grfid=b'TODO',
name='BonkyGFX',
description='BonkyGFX',
min_compatible_version=0,
version=0,
)
# TODO (I commented this part out as it was often giving me all vehicles even though the paremeter was set to false)
# g.add_bool_parameter(
# name='Enable vehicles from all climates',
# description='Sets the climate availability for all vehicles (useful for debugging)',
# default=False,
# )
# g.add(grf.If(is_static=False, variable=0x01, condition=0x03, value=1, skip=0, varsize=1)) # skip if vehicle param not enabled
# for feature in (grf.RV, grf.TRAIN, grf.SHIP, grf.AIRCRAFT):
# count = grf.DisableDefault.DISABLE_INFO[feature][0]
# g.add(grf.DefineMultiple(
# feature=feature,
# first_id=0,
# count=count,
# props={
# 'climates_available': [grf.ALL_CLIMATES] * count,
# }
# ))
# g.add(grf.Label(0, b''))
# ------------------------------ Cursors ------------------------------
# TODO Animated "Zzzz" waiting cursor if possible, otherwise use better colors than anim-palette
# TODO compositing icons onto cursor
# TODO sprite width is 104/2=52 to be able to add wider icons such as station
@lib.template(grf.FileSprite)
def tmpl_cursors(func, z, frame):
grid = lib.RectGrid(func=func, width=48 * z, height=32 * z, padding=z)
grid.set_default(frame=frame)
return [grid(str(i), (0, 0))]
for i in range(2):
lib.SpriteCollection(f'cursor{i}') \
.add(ICON_DIR / 'cursor.ase', tmpl_cursors, ZOOM_2X, i + 1) \
.replace_old(i)
# ------------------------------ Ground Tiles ------------------------------
@lib.template(grf.FileSprite)
def tmpl_groundtiles(func, z, frame=1, above=0):
grid = lib.FlexGrid(func=func, padding=z, start=(0, 0), add_yofs=-(z // 2) - above * z, add_height=above * z)
grid.set_default(width=64 * z, height=32 * z - 1, xofs=-31 * z, yofs=0, frame=frame)
return [
grid('flat'),
grid('w'),
grid('s', height=24 * z - 1),
grid('sw', height=24 * z - 1),
grid('e'),
grid('ew'),
grid('se', height=24 * z - 1),
grid('wse', height=24 * z - 1),
grid('n', height=40 * z - 1, yofs=-8 * z),
grid('nw', height=40 * z - 1, yofs=-8 * z),
grid('ns', yofs=-8 * z),
grid('nws', yofs=-8 * z),
grid('ne', height=40 * z - 1, yofs=-8 * z),
grid('enw', height=40 * z - 1, yofs=-8 * z),
grid('sen', yofs=-8 * z),
grid('steep_n', height=48 * z - 1, yofs=-16 * z),
grid('steep_s', height=16 * z - 1),
grid('steep_w', yofs=-8 * z),
grid('steep_e', yofs=-8 * z),
]
def tmpl_groundtiles_extra(name, paths, zoom, *args):
@lib.template(grf.FileSprite)
def tmpl_extra(func, z, frame=1):
assert z == 2
grid = lib.FlexGrid(func=func, padding=z, start=(1235 * z, 0), add_yofs=-(z // 2))
grid.set_default(width=64 * z, height=32 * z - 1, xofs=-31 * z, yofs=0, frame=frame)
return [
grid('extra1'),
grid('extra2'),
grid('extra3'),
grid('extra4'),
]
return tmpl_groundtiles(name, paths, zoom, *args) + tmpl_extra(name, paths, zoom, *args)
def make_ground(name, frame, *, extra=False):
tmpl = tmpl_groundtiles_extra if extra else tmpl_groundtiles
return lib.SpriteCollection(name) \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl, ZOOM_2X, frame, climate=TEMPERATE) \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl, ZOOM_2X, frame + 7, climate=ARCTIC) \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl, ZOOM_2X, frame + 18, climate=TROPICAL) \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl, ZOOM_2X, frame + 27, climate=TOYLAND)
ground = make_ground('ground', 4)
make_ground('ground_bare', 1).replace_old(3924) # 0% grass
make_ground('ground_33', 2).replace_old(3943) # 33% grass
make_ground('ground_66', 3).replace_old(3962) # 66% grass
ground.replace_old(3981) # 100% grass
make_ground('rough', 5, extra=True).replace_old(4000)
make_ground('rocks', 6).replace_old(4023)
for i in range(9):
lib.SpriteCollection(f'farmland{i}') \
.add(TERRAIN_DIR / 'farmtiles.ase', tmpl_groundtiles, ZOOM_2X, i + 1, 5, climate=TEMPERATE) \
.add(TERRAIN_DIR / 'farmtiles.ase', tmpl_groundtiles, ZOOM_2X, i + 10, 5, climate=ARCTIC) \
.add(TERRAIN_DIR / 'farmtiles.ase', tmpl_groundtiles, ZOOM_2X, i + 19, 5, climate=TROPICAL) \
.replace_old(4126 + 19 * i)
for i in range(3):
lib.SpriteCollection(f'snow_{25 * i}') \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl_groundtiles, ZOOM_2X, 15 + i) \
.replace_old(4493 + i * 19, climate=ARCTIC)
lib.SpriteCollection('desert_and_snow_transition') \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl_groundtiles, ZOOM_2X, 26) \
.replace_old(4512)
desert_and_snow = lib.SpriteCollection('desert_and_snow') \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl_groundtiles, ZOOM_2X, 27) \
.add(TERRAIN_DIR / 'groundtiles.ase',
tmpl_groundtiles, ZOOM_2X, 15 + 3, climate=ARCTIC)
desert_and_snow.replace_old(4550)
general_concrete = make_ground('general_concrete', 7)
general_concrete[0].replace_old(1420)
general_concrete[0].replace_old(4675) # Toyland extra concrete
general_concrete[0].replace_old(4676) # Toyland extra concrete
general_concrete[0].replace_old(2022, climate=TOYLAND) # Some toyland industries use coal mine dirt tile, replace it with concrete
@lib.template(grf.FileSprite)
def tmpl_foundations(func, z, frame=1):
grid = lib.RectGrid(func=func, width=64 * z, height=41 * z - 1, padding=z, add_yofs=-(z // 2))
# TODO figure out why it glitches with crop
grid.set_default(xofs=-31 * z, yofs=-9 * z, frame=frame, crop=False)
return (
[grid(f'base_{i}', (i % 7, i // 7)) for i in range(14)] +
[grid(f'new_{i}', (i % 7, i // 7 + 2)) for i in range(74)] +
[
grid('new_74', (4, 12), xofs=-15 * z, yofs=-17 * z),
grid('new_75', (5, 12), yofs=-25 * z),
grid('new_76', (6, 12), xofs=-47 * z, yofs=-17 * z),
grid('new_77', (0, 13), yofs=-9 * z),
grid('new_78', (1, 13), xofs=-15 * z, yofs=-17 * z),
grid('new_79', (2, 13), yofs=-25 * z),
grid('new_80', (3, 13), xofs=-47 * z, yofs=-17 * z),
grid('new_81', (4, 13), yofs=-9 * z),
grid('new_82', (5, 13), xofs=-15 * z, yofs=-17 * z),
grid('new_83', (6, 13), yofs=-25 * z),
grid('new_84', (0, 14), xofs=-47 * z, yofs=-17 * z),
grid('new_85', (1, 14), yofs=-9 * z),
grid('new_86', (2, 14), xofs=-15 * z, yofs=-17 * z),
grid('new_87', (3, 14), yofs=-25 * z),
grid('new_88', (4, 14), xofs=-47 * z, yofs=-17 * z),
grid('new_89', (5, 14), yofs=-9 * z),
]
)
foundations = lib.SpriteCollection('foundations') \
.add(TERRAIN_DIR / 'foundations.ase', tmpl_foundations, ZOOM_2X, 1, climate=TEMPERATE) \
.add(TERRAIN_DIR / 'foundations.ase', tmpl_foundations, ZOOM_2X, 2, climate=ARCTIC) \
.add(TERRAIN_DIR / 'foundations.ase', tmpl_foundations, ZOOM_2X, 3, climate=TROPICAL) \
.add(TERRAIN_DIR / 'foundations.ase', tmpl_foundations, ZOOM_2X, 4, climate=TOYLAND)
foundations[:14].replace_old(990)
foundations[14:].replace_new(0x06, 0)
@lib.template(grf.FileSprite)
def tmpl_water_slopes(func, z, frame=1, above=0):
grid = lib.FlexGrid(func=func, padding=z, start=(0, 0), add_yofs=-(z // 2) - above * z, add_height=above * z)
grid.set_default(width=64 * z, height=32 * z - 1, xofs=-31 * z, yofs=0, frame=frame)
return [
grid('se', height=24 * z - 1),
grid('ne', height=40 * z - 1, yofs=-8 * z),
grid('sw', height=24 * z - 1),
grid('nw', height=40 * z - 1, yofs=-8 * z),
]
# TODO water_slopes, starts at 7206 (20x4)
# for i in range(1):
# lib.SpriteCollection(f'water_slopes{i}') \
# .add(TERRAIN_DIR / 'water_slopes.ase', tmpl_water_slopes, ZOOM_2X, i + 1, 4) \
# .replace_old(7270) # <-- This doesn't work because the sprite ID is too high.
# ------------------------------ Airport Tiles ------------------------------
@lib.template(grf.FileSprite)
def tmpl_airport_tiles(func, z):
grid = lib.FlexGrid(func=func, padding=2, add_yofs=-(z // 2))
grid.set_default(width=64 * z, height=32 * z - 1, xofs=-31 * z, yofs=0)
kw_default = {'ignore_layers': 'ANIMATED/*'}
sprites = [
grid('apron', **kw_default),
grid('stand', **kw_default),
animated('runway_a', grid),
animated('runway_b', grid),
animated('runway_c', grid),
animated('runway_d', grid),
animated('runway_end', grid),
grid('taxi_ns_west', **kw_default),
grid('taxi_ew_south', **kw_default),
grid('taxi_xing_south', **kw_default),
grid('taxi_xing_west', **kw_default),
grid('taxi_ns_ctr', **kw_default),
grid('taxi_xing_east', **kw_default),
grid('taxi_ns_east', **kw_default),
grid('taxi_ew_north', **kw_default),
grid('taxi_ew_ctr', **kw_default),
animated('runway_y_a', grid), # unused
animated('runway_y_b', grid), # unused
animated('runway_y_c', grid), # unused
animated('runway_y_d', grid), # unused
animated('runway_y_end', grid), # unused
animated('helipad', grid, yofs = -15 * z),
grid('new_helipad', **kw_default),
]
# Rearrange to OpenTTD sprite order
return [sprites[k] for k in (0, 1, 7, 8, 9, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 21, 22)]
AIRPORT_COMPOSITION = [(0, None), (1, None)] + [(i, 0) for i in range(2, 11)] + [(i, None) for i in range(11, 18)]
airport_tiles = lib.SpriteCollection('airport_modern') \
.add(INFRA_DIR / 'airport_modern.ase',
tmpl_airport_tiles, ZOOM_2X) \
.compose_on(ground, AIRPORT_COMPOSITION)
airport_tiles[:16].replace_old(2634)
airport_tiles[16].replace_new(0x15, 86)
airport_tiles[17].replace_new(0x10, 12)
def tmpl_tile_selection(name, paths, zoom, *args):
return [grf.MoveSprite(lib.MagentaToSelection(s), yofs=14) for s in tmpl_groundtiles(name, paths, zoom, *args)]
lib.SpriteCollection('tile_selection') \
.add(TERRAIN_DIR / 'selectiontiles.ase', tmpl_tile_selection, ZOOM_2X) \
.replace_old(752)
# ------------------------------ Trees ------------------------------
def tree(name, sprite_id, path, **kw):
@lib.template(grf.FileSprite)
def tmpl(func, z, frame):
# Variation of OpenGFX1 template with 2x zoom and only one tree
return [
func('', 2 + 0 * z, 2, 45 * z, 80 * z, xofs=-24 * z, yofs=-73 * z - (z // 2), frame=frame, **kw)
]
sprites = []
for i in range(7):
sprites.extend(tmpl(f'stage{i}', lib.aseidx(path), ZOOM_2X, i + 1))
lib.SpriteCollection(name).add_sprites(sprites).replace_old(sprite_id)
TREE_RANGES = [
(1576, 19), # temperate
(1709, 8), # arctic
(1765, 8), # arctic-snow
(1821, 18), # tropic
(1947, 9), # toyland
]
for i in range(19):
tree('temperate_tree', 1576 + i * 7, TREE_DIR / 'temperate_tree.ase')
for i in range(8):
tree('arctic_tree', 1709 + i * 7, TREE_DIR / 'arctic_tree.ase', ignore_layers='SNOW/*')
tree('arctic_tree_snow', 1765 + i * 7, TREE_DIR / 'arctic_tree.ase')
for i in range(18):
tree('tropic_tree', 1821 + i * 7, TREE_DIR / 'tropical_tree.ase')
tree('fruit_tree', 1821 + 7 * 11, TREE_DIR / 'fruit_tree.ase')
tree('rubber_tree', 1821 + 7 * 12, TREE_DIR / 'rubber_tree.ase')
tree('cactus', 1821 + 7 * 13, TREE_DIR / 'cactus.ase')
tree('cactus', 1821 + 7 * 14, TREE_DIR / 'cactus.ase')
for i in range(7):
tree('toyland_tree', 1947 + i * 7, TREE_DIR / 'toyland_tree.ase')
tree('toyland_tree', 1947 + 7 * 7, TREE_DIR / 'battery_tree.ase')
tree('toyland_tree', 1947 + 7 * 8, TREE_DIR / 'cotton_candy_tree.ase')
# ------------------------------ Road Vehicles ------------------------------
@lib.template(lib.CCReplacingFileSprite)
def tmpl_vehicle_road_8view(func, z, x, y, frame):
grid = lib.FlexGrid(func=func, padding=2, start=(x * 174 * z, y * 24 * z), add_yofs=-(z // 2))
grid.set_default(frame=frame)
res = [
grid('n', width=8 * z, height=23 * z, xofs=-3 * z, yofs=-15 * z),
grid('ne', width=22 * z, height=19 * z, xofs=-15 * z, yofs=-10 * z),
grid('e', width=31 * z, height=15 * z, xofs=-15 * z, yofs=-9 * z),
grid('se', width=22 * z, height=19 * z, xofs=-7 * z, yofs=-10 * z),
grid('s', width=8 * z, height=23 * z, xofs=-3 * z, yofs=-15 * z),
grid('sw', width=22 * z, height=19 * z, xofs=-15 * z, yofs=-10 * z),
grid('w', width=31 * z, height=15 * z, xofs=-15 * z, yofs=-9 * z),
grid('nw', width=22 * z, height=19 * z, xofs=-7 * z, yofs=-10 * z),
]
return res
def replace_rv_generation(path2x, generation):
def tmpl(suffix, x, y):
return lib.SpriteCollection(f'rv_gen{generation}_{suffix}') \
.add(path2x, tmpl_vehicle_road_8view, ZOOM_2X, x, y, generation)
# base_graphics spr3284(3284, "../graphics/vehicles/64/road_buses_8bpp.png") { template_vehicle_road_8view(0, 0, 1) } // bus
o = {1: 0, 2: -192, 3: 192}[generation]
tmpl('coal_empty', 0, 0).replace_old(3292 + o)
tmpl('mail', 0, 1).replace_old(3300 + o)
tmpl('oil', 0, 2).replace_old(3308 + o)
tmpl('livestock', 0, 3).replace_old(3316 + o)
tmpl('goods', 0, 4).replace_old(3324 + o)
tmpl('food', 0, 5).replace_old(3332 + o)
tmpl('grain_empty', 0, 6).replace_old(3340 + o)
tmpl('wood_empty', 0, 7).replace_old(3348 + o)
tmpl('steel_paper_empty', 0, 8).replace_old(3356 + o)
tmpl('ore_empty', 0, 9).replace_old(3364 + o)
tmpl('armoured', 0, 10).replace_old(3372 + o)
tmpl('coal_loaded', 1, 0).replace_old(3380 + o)
tmpl('grain_loaded', 1, 6).replace_old(3388 + o)
tmpl('wood_loaded', 1, 7).replace_old(3396 + o)
tmpl('steel_loaded', 1, 8).replace_old(3404 + o)
tmpl('iron_ore_loaded', 1, 9).replace_old(3412 + o)
tmpl('paper_loaded', 2, 8).replace_old(3420 + o)
tmpl('copper_ore_loaded', 2, 9).replace_old(3428 + o)
tmpl('water', 0, 11).replace_old(3436 + o)
tmpl('fruit_empty', 0, 12).replace_old(3444 + o)
tmpl('rubber_empty', 0, 13).replace_old(3452 + o)
tmpl('fruit_loaded', 1, 12).replace_old(3460 + o)
tmpl('rubber_loaded', 1, 13).replace_old(3468 + o)
replace_rv_generation(VEHICLE_DIR / 'road_trucks.ase', 1)
replace_rv_generation(VEHICLE_DIR / 'road_trucks.ase', 2)
replace_rv_generation(VEHICLE_DIR / 'road_trucks.ase', 3)
lib.SpriteCollection('bus_gen1') \
.add(VEHICLE_DIR / 'road_buses.ase', tmpl_vehicle_road_8view, ZOOM_2X, 0, 0, 0) \
.replace_old(3284)
lib.SpriteCollection('bus_gen2') \
.add(VEHICLE_DIR / 'road_buses.ase', tmpl_vehicle_road_8view, ZOOM_2X, 0, 1, 0) \
.replace_old(3284 - 192)
lib.SpriteCollection('bus_gen2') \
.add(VEHICLE_DIR / 'road_buses.ase', tmpl_vehicle_road_8view, ZOOM_2X, 0, 2, 0) \
.replace_old(3284 + 192)
def replace_rv_toyland(path2x):
def tmpl(suffix, x, y, frame):
return lib.SpriteCollection(f'rv_toyland_{suffix}') \
.add(path2x, tmpl_vehicle_road_8view, ZOOM_2X, x, y, frame, climate=TOYLAND)
tmpl('passengers', 0, 0, 1).replace_old(3092)
tmpl('sugar_empty', 0, 1, 1).replace_old(3100)
tmpl('sugar_loaded', 0, 1, 2).replace_old(3108)
tmpl('cola_empty', 0, 2, 1).replace_old(3116)
tmpl('cola_loaded', 0, 2, 2).replace_old(3124)
tmpl('cotton_candy_empty', 0, 3, 1).replace_old(3132)
tmpl('cotton_candy_loaded', 0, 3, 2).replace_old(3140)
tmpl('toffee_empty', 0, 4, 1).replace_old(3148)
tmpl('toffee_loaded', 0, 4, 2).replace_old(3156)
tmpl('toys', 0, 5, 1).replace_old(3164)
tmpl('mail', 0, 6, 1).replace_old(3172)
tmpl('candy', 0, 7, 1).replace_old(3180)
tmpl('batteries_empty', 0, 8, 1).replace_old(3188)
tmpl('batteries_loaded', 0, 8, 2).replace_old(3196)
tmpl('fizzy_drinks_empty', 0, 9, 1).replace_old(3204)
tmpl('fizzy_drinks_loaded', 0, 9, 2).replace_old(3212)
tmpl('plastic_empty', 0, 10, 1).replace_old(3220)
tmpl('plastic_loaded', 0, 10, 2).replace_old(3228)
tmpl('bubbles_empty', 0, 11, 1).replace_old(3236)
tmpl('bubbles_loaded', 0, 11, 2).replace_old(3244)
replace_rv_toyland(VEHICLE_DIR / 'road_trucks_toyland.ase')
# ------------------------------ Rail Vehicles ------------------------------
@lib.template(lib.CCReplacingFileSprite)
def tmpl_vehicle_rail_4view(func, z, y, frame, **kw):
grid = lib.FlexGrid(func=func, padding=2, start=(0 * 87 * z, y * 24 * z), add_yofs=-(z // 2))
grid.set_default(frame=frame, **kw)
return [
grid( 'n', width= 8 * z, height=23 * z, xofs=-3 * z, yofs=-13 * z),
grid('ne', width= 22 * z, height=19 * z, xofs=-15 * z, yofs=-12 * z),
grid( 'e', width= 31 * z, height=15 * z, xofs=-16 * z, yofs=-9 * z),
grid('se', width= 22 * z, height=19 * z, xofs=-7 * z, yofs=-12 * z),
]
@lib.template(lib.CCReplacingFileSprite)
def tmpl_vehicle_rail_8view(func, z, y, frame, **kw):
grid = lib.FlexGrid(func=func, padding=2, start=(0 * 174 * z, y * 24 * z), add_yofs=-(z // 2))
grid.set_default(frame=frame, **kw)
x = 0
return [
grid( 'n', width=8 * z, height=23 * z, xofs=-3 * z, yofs=-13 * z),
grid('ne', width=22 * z, height=19 * z, xofs=-15 * z, yofs=-12 * z),
grid( 'e', width=31 * z, height=15 * z, xofs=-16 * z, yofs=-9 * z),
grid('se', width=22 * z, height=19 * z, xofs=-7 * z, yofs=-12 * z),
grid( 's', width=8 * z, height=23 * z, xofs=-3 * z, yofs=-13 * z),
grid('sw', width=22 * z, height=19 * z, xofs=-15 * z, yofs=-12 * z),
grid( 'w', width=31 * z, height=15 * z, xofs=-16 * z, yofs=-9 * z),
grid('nw', width=22 * z, height=19 * z, xofs=-7 * z, yofs=-12 * z),
]
def wagon(name, sprite_id, y, *, frame):
lib.SpriteCollection('wagon_' + name) \
.add(VEHICLE_DIR / 'rail_wagons.ase', tmpl_vehicle_rail_4view, ZOOM_2X, y, frame) \
.replace_old(sprite_id)
wagon('passengers', 2733, 0, frame=1) # temperate rail passenger wagon (full + empty)
wagon('coal_empty', 2737, 1, frame=1 ) # temperate rail coal wagon (empty)
wagon('mail', 2741, 2, frame=1) # temperate rail mail wagon (full + empty)
wagon('oil', 2745, 3, frame=1) # temperate rail oil wagon (full + empty)
wagon('livestock', 2749, 4, frame=1) # temperate rail livestock wagon (full + empty)
wagon('goods', 2753, 5, frame=1) # temperate rail goods wagon (full + empty)
wagon('food', 2757, 6, frame=1) # arctic rail food wagon (full + empty)
wagon('grain_empty', 2761, 7, frame=1) # temperate rail grain wagon (empty)
wagon('wood_empty', 2765, 8, frame=1) # temperate rail wood wagon (empty)
wagon('steel_paper_empty', 2769, 9, frame=1) # temperate rail steel/paper wagon (empty)
wagon('ore_empty', 2773, 10, frame=1) # temperate rail iron/coer ore wagon (empty)
wagon('valuables', 2777, 11, frame=1) # temperate rail valuables wagon (full + empty)
wagon('coal_full', 2781, 1, frame=2) # temperate rail coal wagon (full)
wagon('grain_full', 2785, 7, frame=2) # temperate rail grain wagon (full)
wagon('wood_full', 2789, 8, frame=2) # temperate rail wood wagon (full)
wagon('steel_full', 2793, 9, frame=2) # temperate rail steel wagon (full)
wagon('iron_ore_full', 2797, 10, frame=2) # temperate rail iron ore wagon (full)
wagon('paper_full', 2801, 9, frame=3) # arctic rail paper wagon (full)
wagon('copper_ore_full', 2805, 10, frame=2) # tropical rail copper ore wagon (full)
wagon('water', 2809, 12, frame=1) # tropical rail water wagon (full + empty)
wagon('fruit_empty', 2813, 13, frame=1) # tropical rail fruit wagon (empty)
wagon('fruit_full', 2817, 13, frame=2) # tropical rail fruit wagon (full)
wagon('rubber_empty', 2821, 14, frame=1) # tropical rail rubber wagon (empty)
wagon('rubber_full', 2825, 14, frame=2) # tropical rail rubber wagon (full)
def wagon(name, sprite_id, y, *, frame):
lib.SpriteCollection('wagon_' + name) \
.add(VEHICLE_DIR / 'rail_wagons_toyland.ase', tmpl_vehicle_rail_4view, ZOOM_2X, y, frame, climate=TOYLAND) \
.replace_old(sprite_id)
wagon('passengers', 2733, 0, frame=1)
# wagon('-unused-', 2737, 0, frame=1) # Unused wagon in Toyland.
wagon('mail', 2741, 1, frame=1)
wagon('sugar_empty', 2745, 2, frame=1)
wagon('sugar_loaded', 2749, 2, frame=2)
wagon('cotton_candy_empty', 2753, 3, frame=1)
wagon('cotton_candy_loaded', 2757, 3, frame=2)
wagon('toffee_empty', 2761, 4, frame=1)
wagon('toffee_loaded', 2765, 4, frame=2)
wagon('bubbles_empty', 2769, 5, frame=1)
wagon('bubbles_loaded', 2773, 5, frame=2)
wagon('cola_empty', 2777, 6, frame=1)
wagon('cola_loaded', 2781, 6, frame=2)
wagon('candy', 2785, 7, frame=1)
wagon('toys', 2789, 8, frame=1)
wagon('batteries_empty', 2793, 9, frame=1)
wagon('batteries_loaded', 2797, 9, frame=2)
wagon('fizzy_drinks_empty', 2801, 10, frame=1)
wagon('fizzy_drinks_loaded', 2805, 10, frame=2)
wagon('plastic_empty', 2809, 11, frame=1)
wagon('plastic_loaded', 2813, 11, frame=2)
wagon('passengers_gen2+3', 2829, 0, frame=2)
wagon('mail_gen2+3', 2837, 1, frame=2)
def engine(name, sprite_id, tmpl, y):
lib.SpriteCollection(name) \
.add(VEHICLE_DIR / 'rail_engines_temperate.ase', tmpl, ZOOM_2X, y, 0) \
.replace_old(sprite_id)
engine('jubilee_sh8p', 2905, tmpl_vehicle_rail_8view, 0) # Chaney Jubilee + SH 8P (Steam)
engine('ginzu', 2913, tmpl_vehicle_rail_8view, 1) # Ginzu A4 (Steam)
engine('kirby', 2921, tmpl_vehicle_rail_8view, 2) # Kirby Paul (Steam)
engine('sh25_floss47', 2929, tmpl_vehicle_rail_4view, 3) # SH/Hendry 25 + Floss 47 (Diesel)
engine('uu37', 2933, tmpl_vehicle_rail_4view, 4) # UU/37 (Diesel)
engine('sh30_sh40', 2937, tmpl_vehicle_rail_4view, 5) # SH/30 + SH/40 (Diesel)
engine('sh_125', 2941, tmpl_vehicle_rail_8view, 6) # SH 125 (Diesel)
engine('manley', 2949, tmpl_vehicle_rail_8view, 7) # Manley-Morel VT (Diesel)
engine('dash', 2957, tmpl_vehicle_rail_8view, 8) # Dash (Diesel)
engine('asia', 2965, tmpl_vehicle_rail_8view, 9) # Asia Star (Electric)
engine('tim', 2973, tmpl_vehicle_rail_8view, 10) # T.I.M. (Electric)
# engine('', 2981, tmpl_vehicle_rail_4view, 0, 0) # X2001
# engine('', 2985, tmpl_vehicle_rail_8view, 0, 1) # Millenium
# engine('', 2993, tmpl_vehicle_rail_8view, 0, 2) # Lev3 Pegasus
# engine('', 3001, tmpl_vehicle_rail_8view, 0, 3) # Lev4 Chimaera
# engine('', 3009, tmpl_vehicle_rail_4view, 0, 0) # Lev1 Leviathan
# engine('', 3013, tmpl_vehicle_rail_4view, 0, 1) # Lev2 Cyclops
# ------------------------------ Water Vehicles ------------------------------
@lib.template(grf.FileSprite)
def tmpl_water_ships(func, z):
grid = lib.RectGrid(func=func, width=96 * z, height=(75 * z)+1, padding=z)
grid.set_default(xofs=-20 * z, yofs=-39 * z) # TODO not great
return [
cc(grid('ship1_n', (0, 0))),
cc(grid('ship1_ne', (1, 0))),
cc(grid('ship1_e', (2, 0))),
cc(grid('ship1_se', (3, 0))),
cc(grid('ship1_s', (4, 0))),
cc(grid('ship1_sw', (5, 0))),
cc(grid('ship1_w', (6, 0))),
cc(grid('ship1_nw', (7, 0))),
cc(grid('ship2_n', (0, 1))),
cc(grid('ship2_ne', (1, 1))),
cc(grid('ship2_e', (2, 1))),
cc(grid('ship2_se', (3, 1))),
cc(grid('ship2_s', (4, 1))),
cc(grid('ship2_sw', (5, 1))),
cc(grid('ship2_w', (6, 1))),
cc(grid('ship2_nw', (7, 1))),
cc(grid('ship3_n', (0, 2))),
cc(grid('ship3_ne', (1, 2))),
cc(grid('ship3_e', (2, 2))),
cc(grid('ship3_se', (3, 2))),
cc(grid('ship3_s', (4, 2))),
cc(grid('ship3_sw', (5, 2))),
cc(grid('ship3_w', (6, 2))),
cc(grid('ship3_nw', (7, 2))),
cc(grid('ship4_n', (0, 3))),
cc(grid('ship4_ne', (1, 3))),
cc(grid('ship4_e', (2, 3))),
cc(grid('ship4_se', (3, 3))),
cc(grid('ship4_s', (4, 3))),
cc(grid('ship4_sw', (5, 3))),
cc(grid('ship4_w', (6, 3))),
cc(grid('ship4_nw', (7, 3))),
]
water_ships = lib.SpriteCollection('water_ships') \
.add(VEHICLE_DIR / 'water_ships.ase', tmpl_water_ships, ZOOM_2X) \
.replace_old(3669)
# ------------------------------ Air Vehicles ------------------------------
@lib.template(grf.FileSprite)
def tmpl_air_planes(func, z):
grid = lib.RectGrid(func=func, width=80 * z, height=(60 * z)+1, padding=z)
grid.set_default(xofs=-40 * z, yofs=-30 * z)
return [
cc(grid('small_plane1_n', (0, 0), frame=1)),
cc(grid('small_plane1_ne', (1, 0), frame=1)),
cc(grid('small_plane1_e', (2, 0), frame=1)),
cc(grid('small_plane1_se', (3, 0), frame=1)),
cc(grid('small_plane1_s', (4, 0), frame=1)),
cc(grid('small_plane1_sw', (5, 0), frame=1)),
cc(grid('small_plane1_w', (6, 0), frame=1)),
cc(grid('small_plane1_nw', (7, 0), frame=1)),
cc(grid('small_plane2_n', (0, 0), frame=2)),
cc(grid('small_plane2_ne', (1, 0), frame=2)),
cc(grid('small_plane2_e', (2, 0), frame=2)),
cc(grid('small_plane2_se', (3, 0), frame=2)),
cc(grid('small_plane2_s', (4, 0), frame=2)),
cc(grid('small_plane2_sw', (5, 0), frame=2)),
cc(grid('small_plane2_w', (6, 0), frame=2)),
cc(grid('small_plane2_nw', (7, 0), frame=2)),
cc(grid('concorde_n', (0, 0), frame=3)),
cc(grid('concorde_ne', (1, 0), frame=3)),
cc(grid('concorde_e', (2, 0), frame=3)),
cc(grid('concorde_se', (3, 0), frame=3)),
cc(grid('concorde_s', (4, 0), frame=3)),
cc(grid('concorde_sw', (5, 0), frame=3)),
cc(grid('concorde_w', (6, 0), frame=3)),
cc(grid('concorde_nw', (7, 0), frame=3)),
cc(grid('medium_plane1_n', (0, 1), frame=1)),
cc(grid('medium_plane1_ne', (1, 1), frame=1)),
cc(grid('medium_plane1_e', (2, 1), frame=1)),
cc(grid('medium_plane1_se', (3, 1), frame=1)),
cc(grid('medium_plane1_s', (4, 1), frame=1)),
cc(grid('medium_plane1_sw', (5, 1), frame=1)),
cc(grid('medium_plane1_w', (6, 1), frame=1)),
cc(grid('medium_plane1_nw', (7, 1), frame=1)),
cc(grid('medium_plane2_n', (0, 1), frame=2)),
cc(grid('medium_plane2_ne', (1, 1), frame=2)),
cc(grid('medium_plane2_e', (2, 1), frame=2)),
cc(grid('medium_plane2_se', (3, 1), frame=2)),
cc(grid('medium_plane2_s', (4, 1), frame=2)),
cc(grid('medium_plane2_sw', (5, 1), frame=2)),
cc(grid('medium_plane2_w', (6, 1), frame=2)),
cc(grid('medium_plane2_nw', (7, 1), frame=2)),
cc(grid('medium_plane3_n', (0, 1), frame=3)),
cc(grid('medium_plane3_ne', (1, 1), frame=3)),
cc(grid('medium_plane3_e', (2, 1), frame=3)),
cc(grid('medium_plane3_se', (3, 1), frame=3)),
cc(grid('medium_plane3_s', (4, 1), frame=3)),
cc(grid('medium_plane3_sw', (5, 1), frame=3)),
cc(grid('medium_plane3_w', (6, 1), frame=3)),
cc(grid('medium_plane3_nw', (7, 1), frame=3)),
cc(grid('big_plane1_n', (0, 2), frame=1)),
cc(grid('big_plane1_ne', (1, 2), frame=1)),
cc(grid('big_plane1_e', (2, 2), frame=1)),
cc(grid('big_plane1_se', (3, 2), frame=1)),
cc(grid('big_plane1_s', (4, 2), frame=1)),
cc(grid('big_plane1_sw', (5, 2), frame=1)),
cc(grid('big_plane1_w', (6, 2), frame=1)),
cc(grid('big_plane1_nw', (7, 2), frame=1)),
cc(grid('big_plane2_n', (0, 2), frame=2)),
cc(grid('big_plane2_ne', (1, 2), frame=2)),
cc(grid('big_plane2_e', (2, 2), frame=2)),
cc(grid('big_plane2_se', (3, 2), frame=2)),
cc(grid('big_plane2_s', (4, 2), frame=2)),
cc(grid('big_plane2_sw', (5, 2), frame=2)),
cc(grid('big_plane2_w', (6, 2), frame=2)),
cc(grid('big_plane2_nw', (7, 2), frame=2)),
cc(grid('big_plane3_n', (0, 2), frame=3)),
cc(grid('big_plane3_ne', (1, 2), frame=3)),
cc(grid('big_plane3_e', (2, 2), frame=3)),
cc(grid('big_plane3_se', (3, 2), frame=3)),
cc(grid('big_plane3_s', (4, 2), frame=3)),
cc(grid('big_plane3_sw', (5, 2), frame=3)),
cc(grid('big_plane3_w', (6, 2), frame=3)),
cc(grid('big_plane3_nw', (7, 2), frame=3)),
]
air_planes = lib.SpriteCollection('air_planes') \
.add(VEHICLE_DIR / 'air_planes.ase', tmpl_air_planes, ZOOM_2X)
air_planes[:8].replace_old(3773) # small
air_planes[8:16].replace_old(3805) # small
air_planes[16:24].replace_old(3757) # concorde
air_planes[24:32].replace_old(3741) # medium
air_planes[32:40].replace_old(3765) # medium
air_planes[40:48].replace_old(3781) # medium
air_planes[48:56].replace_old(3749) # big
air_planes[56:64].replace_old(3789) # big
air_planes[64:72].replace_old(3797) # big
# ------------------------------ Road Infrastructure ------------------------------
@lib.template(grf.FileSprite)
def tmpl_roadtiles(func, z, frame, **kw):
grid = lib.FlexGrid(func=func, padding=2, add_yofs=-(z // 2))
grid.set_default(frame=frame, width=64 * z, height=32 * z - 1, xofs=-31 * z, yofs=0, ignore_layers='RAMPS/*', **kw)
return [
grid('y'),
grid('x'),
grid('full'),
grid('t_y_ne'),
grid('t_x_nw'),
grid('t_y_sw'),
grid('t_x_se'),
grid('w'),
grid('n'),
grid('e'),
grid('s'),
grid('sw'),
grid('nw'),
grid('ne'),
grid('se'),
grid('slope_ne', height=40 * z - 1, yofs=-8 * z),
grid('slope_se', height=24 * z - 1),
grid('slope_sw', height=24 * z - 1),
grid('slope_nw', height=40 * z - 1, yofs=-8 * z),
]
road_town = lib.SpriteCollection('road_town') \
.add(lib.aseidx(INFRA_DIR / 'roads.ase'),
tmpl_roadtiles, ZOOM_2X, 2)
road = lib.SpriteCollection('road') \
.add(lib.aseidx(INFRA_DIR / 'roads.ase'),
tmpl_roadtiles, ZOOM_2X, 1) \
.add(INFRA_DIR / 'roads.ase',
tmpl_roadtiles, ZOOM_2X, 3, climate=TROPICAL)
ROAD_COMPOSITION = list(zip(range(11), [0] * 11)) + list(zip(range(15, 19), (12, 6, 3, 9))) + list(zip(range(11, 15), [0] * 4))
road_town.compose_on(general_concrete, ROAD_COMPOSITION).replace_old(1313)
road.compose_on(ground, ROAD_COMPOSITION).replace_old(1332)
desert_and_snow_road = road.compose_on(desert_and_snow, ROAD_COMPOSITION)
desert_and_snow_road.unspecify(climate=ARCTIC).replace_old(1351) # default sprite - snowy road
desert_and_snow_road.replace_old(1351, climate=TROPICAL) # in tropic - desert road
@lib.template(grf.FileSprite)
def tmpl_road_ramps(func, z, **kw):
assert z == 2
grid = lib.RectGrid(func=func, width=64 * z, height=40 * z - 1, padding=z)
grid.set_default(xofs=-31 * z, yofs=-17, layers=('ASPHALT/*', 'MARKINGS/*', 'RAMPS/*'), **kw)
return [
struct(grid('y_slope_sw', (1, 0), frame=1)),
struct(grid('y_slope_ne', (1, 0), frame=2)),
struct(grid('x_slope_se', (0, 0), frame=1)),
struct(grid('x_slope_nw', (0, 0), frame=2)),
struct(grid('ramp_slope_ne', (15, 0), yofs=-17, frame=1)),
struct(grid('ramp_slope_sw', (17, 0), yofs=-1, frame=1)),
struct(grid('ramp_slope_nw', (18, 0), yofs=-17, frame=1)),
struct(grid('ramp_slope_se', (16, 0), yofs=-1, frame=1)),
]
lib.SpriteCollection('road_ramps') \
.add(INFRA_DIR / 'roads.ase',
tmpl_road_ramps, ZOOM_2X) \
.replace_old(2445)
@lib.template(lib.CCReplacingFileSprite)
def tmpl_road_depot(func, z):
# bb values are (dx, dy) from https://github.com/OpenTTD/OpenTTD/blob/master/src/table/road_land.h
grid = lib.HouseGrid(func=func, height=75, z=z)
back_kw = {'layers': ('Behind', 'Spriteborder')}
front_kw = {'ignore_layers': ('Behind',)}
return [
grid('se_back', (0, 0), bb=(0, 0), **back_kw),
grid('se_front', (0, 0), bb=(15, 0), **front_kw),
grid('sw_back', (1, 0), bb=(0, 0), **back_kw),
grid('sw_front', (1, 0), bb=(0, 15), **front_kw),
grid('ne', (2, 0), bb=(0, 15), **front_kw),
grid('nw', (3, 0), bb=(15, 0), **front_kw),
]
lib.SpriteCollection('road_depot') \
.add(STATION_DIR / 'road_depots.ase',
tmpl_road_depot, ZOOM_2X) \
.replace_old(1408)
@lib.template(lib.CCReplacingFileSprite)
def tmpl_truck_stop(func, z):
# TODO cut front wals out of the back sprites for better transparency
# bb values are (dx, dy) from https://github.com/OpenTTD/OpenTTD/blob/master/src/table/station_land.h
grid = lib.HouseGrid(func=func, height=75, z=z)
ne_pos, se_pos, sw_pos, nw_pos = (2, 0), (0, 0), (1, 0), (3, 0)
return [
grid('ne_ground', ne_pos, layers='Tile/*'),
grid('se_ground', se_pos, layers='Tile/*'),
grid('sw_ground', sw_pos, layers='Tile/*'),
grid('nw_ground', nw_pos, layers='Tile/*'),
grid('ne_wall_se', ne_pos, bb=(0, 15), layers='FacingNE/SE/*'),
grid('se_wall_sw', se_pos, bb=(15, 3), layers='FacingSE/SW/*'),
grid('sw_wall_nw', sw_pos, bb=(3, 0), layers='FacingSW/NW/*'),
grid('nw_wall_ne', nw_pos, bb=(0, 0), layers='FacingNW/NE/*'),
grid('ne_wall_sw', ne_pos, bb=(13, 0), layers='FacingNE/SW/*'),
grid('se_wall_nw', se_pos, bb=(0, 0), layers='FacingSE/NW/*'),
grid('sw_wall_ne', sw_pos, bb=(0, 0), layers='FacingSW/NE/*'),
grid('nw_wall_se', nw_pos, bb=(0, 13), layers='FacingNW/SE/*'),
grid('ne_wall_nw', ne_pos, bb=(2, 0), layers='FacingNE/NW/*'),
grid('se_wall_ne', se_pos, bb=(0, 3), layers='FacingSE/NE/*'),
grid('sw_wall_se', sw_pos, bb=(3, 15), layers='FacingSW/SE/*'),
grid('nw_wall_sw', nw_pos, bb=(15, 2), layers='FacingNW/SW/*'),
grid('dt_y_wall_s', (4, 0), bb=(13, 0), layers='DriveTroughY NW-SE/S/*'),
grid('dt_y_wall_n', (4, 0), bb=(0, 0), layers='DriveTroughY NW-SE/N/*'),
grid('dt_x_wall_n', (5, 0), bb=(0, 0), layers='DriveTroughX SW-NE/N/*'),
grid('dt_x_wall_s', (5, 0), bb=(0, 13), layers='DriveTroughX SW-NE/S/*'),
]
truck_stops = lib.SpriteCollection('truck_stop') \
.add(STATION_DIR / 'truck_stop.ase', tmpl_truck_stop, ZOOM_2X)
truck_stops[:16].replace_old(2708)
truck_stops[16:].replace_new(0x11, 4)
@lib.template(lib.CCReplacingFileSprite)
def tmpl_bus_stop(func, z):
# TODO cut front wals out of the back sprites for better transparency
# bb values are (dx, dy) from https://github.com/OpenTTD/OpenTTD/blob/master/src/table/station_land.h
# NOTE it's different from truck stop in bb and wall order (same in x/y views though)
grid = lib.HouseGrid(func=func, height=75, z=z)
ne_pos, se_pos, sw_pos, nw_pos = (2, 0), (0, 0), (1, 0), (3, 0)
return [
grid('ne_ground', ne_pos, layers='Tile/*'),
grid('se_ground', se_pos, layers='Tile/*'),
grid('sw_ground', sw_pos, layers='Tile/*'),
grid('nw_ground', nw_pos, layers='Tile/*'),
grid('ne_wall_nw', ne_pos, bb=(2, 0), layers='FacingNE/NW/*'),
grid('se_wall_ne', se_pos, bb=(0, 3), layers='FacingSE/NE/*'),
grid('sw_wall_se', sw_pos, bb=(3, 15), layers='FacingSW/SE/*'),
grid('nw_wall_sw', nw_pos, bb=(15, 2), layers='FacingNW/SW/*'),
grid('ne_wall_sw', ne_pos, bb=(13, 0), layers='FacingNE/SW/*'),
grid('se_wall_nw', se_pos, bb=(0, 0), layers='FacingSE/NW/*'),
grid('sw_wall_ne', sw_pos, bb=(0, 0), layers='FacingSW/NE/*'),
grid('nw_wall_se', nw_pos, bb=(0, 13), layers='FacingNW/SE/*'),
grid('ne_wall_se', ne_pos, bb=(0, 13), layers='FacingNE/SE/*'),
grid('se_wall_sw', se_pos, bb=(13, 3), layers='FacingSE/SW/*'),
grid('sw_wall_nw', sw_pos, bb=(3, 0), layers='FacingSW/NW/*'),
grid('nw_wall_ne', nw_pos, bb=(0, 0), layers='FacingNW/NE/*'),
grid('dt_y_wall_s', (4, 0), bb=(13, 0), layers='DriveTroughY NW-SE/S/*'),
grid('dt_y_wall_n', (4, 0), bb=(0, 0), layers='DriveTroughY NW-SE/N/*'),
grid('dt_x_wall_n', (5, 0), bb=(0, 0), layers='DriveTroughX SW-NE/N/*'),
grid('dt_x_wall_s', (5, 0), bb=(0, 13), layers='DriveTroughX SW-NE/S/*'),
]
bus_stops = lib.SpriteCollection('bus_stop') \
.add(STATION_DIR / 'bus_stop.ase', tmpl_bus_stop, ZOOM_2X)
bus_stops[:16].replace_old(2692)
bus_stops[16:].replace_new(0x11, 0)
# ------------------------------ Rail infrastructure ------------------------------
@lib.template(grf.FileSprite)
def tmpl_rails(func, z, layers, frame):
grid = lib.FlexGrid(func=func, padding=2, add_yofs=-(z // 2))
grid.set_default(width=64 * z, height = 32 * z - 1, xofs=-31 * z, yofs=0, layers=layers, frame=frame)
return list(map(grid, ('y', 'x', 'n', 's', 'e', 'w', 'cross')))
@lib.template(grf.FileSprite)
def tmpl_ballast(func, z, layers, frame):
grid = lib.FlexGrid(func=func, padding=2, start=(910, 0), add_yofs=-(z // 2))
grid.set_default(width=64 * z, height = 32 * z - 1, xofs=-31 * z, yofs=0, layers=layers, frame=frame)
return list(map(grid, ('ground_tne', 'ground_tsw', 'ground_tnw', 'ground_tse', 'ground_x')))
@lib.template(grf.FileSprite)
def tmpl_slope_rails(func, z, layers, frame):
grid = lib.FlexGrid(func=func, padding=2, start=(1560, 0), add_yofs=-(z // 2))
grid.set_default(width=64 * z, xofs=-31 * z, yofs=0, layers=layers, frame=frame)
return [
grid('ne', height=40 * z - 1),
grid('se', height=24 * z - 1),
grid('sw', height=24 * z - 1),
grid('nw', height=40 * z - 1),
]
def replace_climate_rail_sprites(rails, slope_rails, ballast, ground, first_id):
rails.compose_on(ground[0]).replace_old(first_id)
ballast.compose_on(ground[0]).replace_old(first_id + 7)
rails.pick(3, 5, 4, 2, 4, 3, 5, 2).compose_on(
ground.pick(8, 4, 1, 2, 14, 7, 11, 13),
exact_size=False,
offsets=((0, 16), None, None, None, None, (0, -16), None, None),
).replace_old(first_id + 12)
slope_rails.compose_on(ground.pick(12, 6, 3, 9)).replace_old(first_id + 20)
rails[3].compose_on(rails[2]).compose_on(ground[0]).replace_old(first_id + 24) # double diagonal tile Y
rails[5].compose_on(rails[4]).compose_on(ground[0]).replace_old(first_id + 25) # double diagonal tile X
def replace_rail_type(name, frame, first_id):
rails = lib.SpriteCollection(name) \
.add(INFRA_DIR / 'rail.ase', tmpl_rails, ZOOM_2X, ('RAILS/*','SLEEPERS/*'), frame)
rail_overlays = lib.SpriteCollection(f'{name}_overlay') \
.add(INFRA_DIR / 'rail.ase', tmpl_rails, ZOOM_2X, ('RAILS/*',), frame)
slope_rails = lib.SpriteCollection(f'{name}_slope') \
.add(INFRA_DIR / 'rail.ase', tmpl_slope_rails, ZOOM_2X, ('RAILS/*','SLEEPERS/*'), frame)
# sleepers = lib.SpriteCollection('rail_overlays') \
# .add(INFRA_DIR / 'rail.ase', tmpl_rails, ZOOM_2X, (SLEEPERS/*'))
ballast = lib.SpriteCollection(f'{name}_ballast') \
.add(INFRA_DIR / 'rail.ase', tmpl_ballast, ZOOM_2X, ('BALLAST/*',), frame)
rail_overlays.pick(1, 0, 2, 3, 4, 5).replace_old(first_id)
replace_climate_rail_sprites(rails, slope_rails, ballast, ground, first_id + 6)
replace_climate_rail_sprites(rails, slope_rails, ballast, desert_and_snow, first_id + 32)
replace_rail_type('rail', 1, 1005)
replace_rail_type('mono', 2, 1087)
replace_rail_type('maglev', 3, 1169)
@lib.template(grf.FileSprite)
def tmpl_rail_fences(func, z):
assert z == 2 # xofs/yofs are fixed
relative = 2
x_xofs, x_yofs = -59 - relative, -12 - relative // 2
y_xofs, y_yofs = -3 + relative, -12 - relative // 2
grid = lib.FlexGrid(func=func, padding=2, add_yofs=-(z // 2))
return [
cc(grid('flat_x', width=33 * z, height=22 * z, xofs=x_xofs, yofs=x_yofs)),
cc(grid('flat_y', width=33 * z, height=22 * z, xofs=y_xofs, yofs=y_yofs)),
cc(grid('vert', width=4 * z, height=38 * z, xofs=-1, yofs=-20 * z)),
cc(grid('hor', width=65 * z, height=7 * z, xofs=-61, yofs=-6 * z)),
cc(grid('low_x', width=33 * z, height=14 * z, xofs=x_xofs, yofs=x_yofs + 0)),
cc(grid('low_y', width=33 * z, height=14 * z, xofs=y_xofs, yofs=y_yofs + 0)),
cc(grid('high_x', width=33 * z, height=30 * z, xofs=x_xofs, yofs=x_yofs - 16)),
cc(grid('high_y', width=33 * z, height=30 * z, xofs=y_xofs, yofs=y_yofs - 16)),
]
lib.SpriteCollection('rail_fence') \
.add(INFRA_DIR / 'rail_fences.ase', tmpl_rail_fences, ZOOM_2X) \
.replace_old(1301)
# ------------------------------ Water ------------------------------
@lib.template(grf.FileSprite)
def tmpl_water_full(func, z):
x = y = 0
grid = lib.FlexGrid(func=func, padding=z, start=(0, 0), add_yofs=-(z // 2))
grid.set_default(width=64 * z, xofs=-31 * z)