Files @ r28356:5479dee3539c
Branch filter:

Location: cpp/openttd-patchpack/source/src/object_cmd.cpp - annotation

Patric Stout
Fix: [CI] patch in SHF_COMPRESSED symbol for our Linux Generic binaries (#11651)
  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
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r17269:69ce9f105ed6
r15942:04a4b4326c6c
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15797:444e01a3fa29
r15734:ae8e2e185874
r15797:444e01a3fa29
r15965:8a2d779d217c
r15940:064272152529
r27148:4e041ae27b9d
r16027:6ca2121f471f
r18904:c513941a76eb
r26006:f409c56041d2
r26094:7572e88decb3
r26102:502baaa2877d
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r21383:942c32fb8b0e
r21383:942c32fb8b0e
r15797:444e01a3fa29
r15797:444e01a3fa29
r27737:728d55b97775
r15797:444e01a3fa29
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r15797:444e01a3fa29
r15797:444e01a3fa29
r15797:444e01a3fa29
r15797:444e01a3fa29
r15797:444e01a3fa29
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r26931:7d5bce03e821
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r15797:444e01a3fa29
r15797:444e01a3fa29
r15797:444e01a3fa29
r15958:ff98c5749e5e
r15797:444e01a3fa29
r15797:444e01a3fa29
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r27737:728d55b97775
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r16710:faf33b3a6228
r15797:444e01a3fa29
r20789:45a4140665bf
r15960:9a2091bc3647
r23607:36c15679007d
r27148:4e041ae27b9d
r16710:faf33b3a6228
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15960:9a2091bc3647
r15797:444e01a3fa29
r15963:24e1c8cf074d
r27737:728d55b97775
r18302:ea9dfce7b13f
r18302:ea9dfce7b13f
r18302:ea9dfce7b13f
r18302:ea9dfce7b13f
r15963:24e1c8cf074d
r15963:24e1c8cf074d
r23607:36c15679007d
r15797:444e01a3fa29
r25451:917146b539af
r15941:6fe2ebbf99a4
r18558:0017880a5972
r27072:def58df3d822
r18558:0017880a5972
r18558:0017880a5972
r18558:0017880a5972
r26006:f409c56041d2
r20789:45a4140665bf
r26006:f409c56041d2
r15734:ae8e2e185874
r15734:ae8e2e185874
r15958:ff98c5749e5e
r15958:ff98c5749e5e
r15964:69583adf1ac1
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15797:444e01a3fa29
r15734:ae8e2e185874
r15797:444e01a3fa29
r15734:ae8e2e185874
r15797:444e01a3fa29
r25451:917146b539af
r15924:f5bba173626e
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15924:f5bba173626e
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r17099:f140f6165f35
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r23464:c4ffa5badecc
r23464:c4ffa5badecc
r23464:c4ffa5badecc
r23464:c4ffa5badecc
r23464:c4ffa5badecc
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r23968:689ddfd1479d
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r16208:fb601446b60b
r18125:7bcadab93511
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r26095:00c14d52e378
r15734:ae8e2e185874
r26119:a6e64747fa5d
r26119:a6e64747fa5d
r15734:ae8e2e185874
r15734:ae8e2e185874
r27737:728d55b97775
r15734:ae8e2e185874
r26059:8050c4d61d9d
r15734:ae8e2e185874
r27036:80cf2fa850d3
r15949:1632bafb6884
r20836:386f9b9a07a7
r20836:386f9b9a07a7
r15734:ae8e2e185874
r20836:386f9b9a07a7
r20836:386f9b9a07a7
r16710:faf33b3a6228
r15734:ae8e2e185874
r15797:444e01a3fa29
r15797:444e01a3fa29
r15797:444e01a3fa29
r16710:faf33b3a6228
r16710:faf33b3a6228
r15734:ae8e2e185874
r25954:e87b796d96fd
r25954:e87b796d96fd
r25954:e87b796d96fd
r15734:ae8e2e185874
r15945:f572606fc341
r15943:830b62bff1b4
r26118:2b515956558b
r15734:ae8e2e185874
r18156:39cce251f480
r18156:39cce251f480
r18156:39cce251f480
r16011:47a273f42c2c
r15966:03ba57f3cc75
r25451:917146b539af
r16552:2145cf9259fa
r15966:03ba57f3cc75
r16041:12e6e13120e4
r16041:12e6e13120e4
r16041:12e6e13120e4
r26118:2b515956558b
r17842:ab6110362c1d
r17842:ab6110362c1d
r17842:ab6110362c1d
r17842:ab6110362c1d
r18904:c513941a76eb
r18904:c513941a76eb
r18904:c513941a76eb
r16041:12e6e13120e4
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r24586:b65203f44ad9
r24586:b65203f44ad9
r24586:b65203f44ad9
r24586:b65203f44ad9
r24586:b65203f44ad9
r24586:b65203f44ad9
r26118:2b515956558b
r24586:b65203f44ad9
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r16574:0699a6196cb8
r18260:9616113792ef
r16574:0699a6196cb8
r25451:917146b539af
r27737:728d55b97775
r16574:0699a6196cb8
r15966:03ba57f3cc75
r23607:36c15679007d
r15966:03ba57f3cc75
r16574:0699a6196cb8
r16574:0699a6196cb8
r18125:7bcadab93511
r18295:a0485c95d085
r18295:a0485c95d085
r18295:a0485c95d085
r21154:68958e5391ae
r18390:50db44cea821
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r18156:39cce251f480
r18156:39cce251f480
r18156:39cce251f480
r18156:39cce251f480
r25451:917146b539af
r18156:39cce251f480
r18156:39cce251f480
r26118:2b515956558b
r18156:39cce251f480
r18156:39cce251f480
r26118:2b515956558b
r18156:39cce251f480
r18156:39cce251f480
r18156:39cce251f480
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15970:ac24acccce19
r25451:917146b539af
r21736:0da55aa599c8
r15970:ac24acccce19
r18251:23e77d038c74
r15970:ac24acccce19
r15970:ac24acccce19
r15970:ac24acccce19
r15970:ac24acccce19
r15734:ae8e2e185874
r26438:10f21bbdb775
r15734:ae8e2e185874
r15943:830b62bff1b4
r15943:830b62bff1b4
r20805:06eb3eae002c
r15943:830b62bff1b4
r15943:830b62bff1b4
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r20788:280f8541e5dc
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r26396:15ac6a0992ff
r26396:15ac6a0992ff
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r15966:03ba57f3cc75
r26438:10f21bbdb775
r15966:03ba57f3cc75
r15734:ae8e2e185874
r15734:ae8e2e185874
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r15734:ae8e2e185874
r25987:b9d33db7c49f
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r15734:ae8e2e185874
r15734:ae8e2e185874
r26438:10f21bbdb775
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r27737:728d55b97775
r26438:10f21bbdb775
r26787:a51c38e4aac5
r26438:10f21bbdb775
r27036:80cf2fa850d3
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26743:251d411d633a
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26493:38e5eba360e8
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r26438:10f21bbdb775
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15949:1632bafb6884
r15949:1632bafb6884
r26769:9b8215567de1
r15949:1632bafb6884
r15734:ae8e2e185874
r15734:ae8e2e185874
r15968:f5c3da224c32
r23607:36c15679007d
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15734:ae8e2e185874
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15734:ae8e2e185874
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15968:f5c3da224c32
r15734:ae8e2e185874
r15734:ae8e2e185874
r15968:f5c3da224c32
r15734:ae8e2e185874
r15734:ae8e2e185874
r20715:c31b5ec3cb3e
r15734:ae8e2e185874
r15734:ae8e2e185874
r27942:f7389062d120
r15734:ae8e2e185874
r20788:280f8541e5dc
r18260:9616113792ef
r18245:fb370bf5a3c0
r15734:ae8e2e185874
r18245:fb370bf5a3c0
r15734:ae8e2e185874
r18245:fb370bf5a3c0
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r20788:280f8541e5dc
r15734:ae8e2e185874
r15734:ae8e2e185874
r16005:93d924c75210
r16005:93d924c75210
r16005:93d924c75210
r16005:93d924c75210
r16005:93d924c75210
r16005:93d924c75210
r20789:45a4140665bf
r25451:917146b539af
r28112:bca7556a6bb6
r16027:6ca2121f471f
r16027:6ca2121f471f
r16027:6ca2121f471f
r16005:93d924c75210
r16005:93d924c75210
r16005:93d924c75210
r23538:8df50944b27a
r16026:de6f171ab049
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r23607:36c15679007d
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r23536:ce42deb0b32d
r23536:ce42deb0b32d
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r23607:36c15679007d
r16550:b9e4f67cdda1
r16550:b9e4f67cdda1
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15797:444e01a3fa29
r15797:444e01a3fa29
r15734:ae8e2e185874
r20789:45a4140665bf
r20789:45a4140665bf
r20789:45a4140665bf
r15967:3dd2b98d8db1
r15967:3dd2b98d8db1
r15967:3dd2b98d8db1
r18976:82f432f25f0a
r18976:82f432f25f0a
r18976:82f432f25f0a
r15734:ae8e2e185874
r15734:ae8e2e185874
r16039:578be62e0a41
r16039:578be62e0a41
r16039:578be62e0a41
r16039:578be62e0a41
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r20835:bb008984e499
r20835:bb008984e499
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15967:3dd2b98d8db1
r15734:ae8e2e185874
r24751:166b026340d2
r24751:166b026340d2
r24751:166b026340d2
r24751:166b026340d2
r15967:3dd2b98d8db1
r15967:3dd2b98d8db1
r15967:3dd2b98d8db1
r15734:ae8e2e185874
r16018:501dedc50595
r16018:501dedc50595
r16018:501dedc50595
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r27106:2d95beb51290
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r26059:8050c4d61d9d
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15797:444e01a3fa29
r15797:444e01a3fa29
r15797:444e01a3fa29
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r23532:dc91fcd293f5
r17889:aa8ff5edab32
r16005:93d924c75210
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r22867:9bff1c966805
r15734:ae8e2e185874
r20788:280f8541e5dc
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r24597:afde5721a3b6
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r24597:afde5721a3b6
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r23910:01534f33b186
r23910:01534f33b186
r23910:01534f33b186
r23910:01534f33b186
r23910:01534f33b186
r23910:01534f33b186
r23910:01534f33b186
r23910:01534f33b186
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15965:8a2d779d217c
r15965:8a2d779d217c
r15734:ae8e2e185874
r15797:444e01a3fa29
r15965:8a2d779d217c
r23607:36c15679007d
r15965:8a2d779d217c
r15965:8a2d779d217c
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15964:69583adf1ac1
r15971:c045a48c36b4
r17762:129a62225055
r15971:c045a48c36b4
r15971:c045a48c36b4
r15971:c045a48c36b4
r15964:69583adf1ac1
r15942:04a4b4326c6c
r15942:04a4b4326c6c
r20788:280f8541e5dc
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r16430:b3f65f9bc976
r27106:2d95beb51290
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r16430:b3f65f9bc976
r27106:2d95beb51290
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r27942:f7389062d120
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r20788:280f8541e5dc
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15964:69583adf1ac1
r15964:69583adf1ac1
r15964:69583adf1ac1
r15964:69583adf1ac1
r15964:69583adf1ac1
r16742:db1dd4012898
r16742:db1dd4012898
r16742:db1dd4012898
r16742:db1dd4012898
r16742:db1dd4012898
r27942:f7389062d120
r15734:ae8e2e185874
r20788:280f8541e5dc
r15734:ae8e2e185874
r15734:ae8e2e185874
r20826:53320f73e54f
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r26787:a51c38e4aac5
r26787:a51c38e4aac5
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r26787:a51c38e4aac5
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20827:fbaf747b87eb
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r23607:36c15679007d
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r20826:53320f73e54f
r15734:ae8e2e185874
r15734:ae8e2e185874
r20832:34bd0d1c35f9
r27036:80cf2fa850d3
r15734:ae8e2e185874
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r26787:a51c38e4aac5
r15734:ae8e2e185874
r26787:a51c38e4aac5
r15734:ae8e2e185874
r26787:a51c38e4aac5
r15734:ae8e2e185874
r26787:a51c38e4aac5
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r20832:34bd0d1c35f9
r27037:fd6e1ed8dd82
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r27037:fd6e1ed8dd82
r20832:34bd0d1c35f9
r27737:728d55b97775
r15734:ae8e2e185874
r20832:34bd0d1c35f9
r27037:fd6e1ed8dd82
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r26787:a51c38e4aac5
r27037:fd6e1ed8dd82
r26787:a51c38e4aac5
r20832:34bd0d1c35f9
r26787:a51c38e4aac5
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r26787:a51c38e4aac5
r27037:fd6e1ed8dd82
r20894:85e7745481b5
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20894:85e7745481b5
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r27737:728d55b97775
r27037:fd6e1ed8dd82
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20832:34bd0d1c35f9
r20826:53320f73e54f
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r22449:b12e71e436c7
r22449:b12e71e436c7
r23593:8664f868a761
r23593:8664f868a761
r15734:ae8e2e185874
r23593:8664f868a761
r15797:444e01a3fa29
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r22449:b12e71e436c7
r15734:ae8e2e185874
r15734:ae8e2e185874
r15788:b6c01baeb166
r15734:ae8e2e185874
r22449:b12e71e436c7
r22449:b12e71e436c7
r22449:b12e71e436c7
r22449:b12e71e436c7
r16005:93d924c75210
r23838:bfeaabaa7b1d
r22449:b12e71e436c7
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r18261:0aa61ca7490f
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15943:830b62bff1b4
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15943:830b62bff1b4
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r18247:d176683304d1
r15969:082e0c2709a6
r18254:b88bdaaa822b
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r27737:728d55b97775
r18301:0c1dfbaba57a
r26769:9b8215567de1
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15969:082e0c2709a6
r15734:ae8e2e185874
r15734:ae8e2e185874
r26118:2b515956558b
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r18245:fb370bf5a3c0
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
r15964:69583adf1ac1
r18314:21a3c3233272
r18314:21a3c3233272
r23910:01534f33b186
r23607:36c15679007d
r15734:ae8e2e185874
r15734:ae8e2e185874
r15734:ae8e2e185874
/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file object_cmd.cpp Handling of object tiles. */

#include "stdafx.h"
#include "landscape.h"
#include "command_func.h"
#include "viewport_func.h"
#include "company_base.h"
#include "town.h"
#include "bridge_map.h"
#include "genworld.h"
#include "autoslope.h"
#include "clear_func.h"
#include "water.h"
#include "window_func.h"
#include "company_gui.h"
#include "cheat_type.h"
#include "object.h"
#include "cargopacket.h"
#include "core/random_func.hpp"
#include "core/pool_func.hpp"
#include "object_map.h"
#include "object_base.h"
#include "newgrf_config.h"
#include "newgrf_object.h"
#include "timer/timer_game_calendar.h"
#include "newgrf_debug.h"
#include "vehicle_func.h"
#include "station_func.h"
#include "object_cmd.h"
#include "landscape_cmd.h"

#include "table/strings.h"
#include "table/object_land.h"

#include "safeguards.h"

ObjectPool _object_pool("Object");
INSTANTIATE_POOL_METHODS(Object)
uint16_t Object::counts[NUM_OBJECTS];

/**
 * Get the object associated with a tile.
 * @param tile The tile to fetch the object for.
 * @return The object.
 */
/* static */ Object *Object::GetByTile(TileIndex tile)
{
	return Object::Get(GetObjectIndex(tile));
}

/**
 * Gets the ObjectType of the given object tile
 * @param t the tile to get the type from.
 * @pre IsTileType(t, MP_OBJECT)
 * @return the type.
 */
ObjectType GetObjectType(Tile t)
{
	assert(IsTileType(t, MP_OBJECT));
	return Object::GetByTile(t)->type;
}

/** Initialize/reset the objects. */
void InitializeObjects()
{
	Object::ResetTypeCounts();
}

/**
 * Actually build the object.
 * @param type  The type of object to build.
 * @param tile  The tile to build the northern tile of the object on.
 * @param owner The owner of the object.
 * @param town  Town the tile is related with.
 * @param view  The view for the object.
 * @pre All preconditions for building the object at that location
 *      are met, e.g. slope and clearness of tiles are checked.
 */
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8_t view)
{
	const ObjectSpec *spec = ObjectSpec::Get(type);

	TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4));
	Object *o = new Object();
	o->type          = type;
	o->location      = ta;
	o->town          = town == nullptr ? CalcClosestTownFromTile(tile) : town;
	o->build_date    = TimerGameCalendar::date;
	o->view          = view;

	/* If nothing owns the object, the colour will be random. Otherwise
	 * get the colour from the company's livery settings. */
	if (owner == OWNER_NONE) {
		o->colour = Random();
	} else {
		const Livery *l = Company::Get(owner)->livery;
		o->colour = l->colour1 + l->colour2 * 16;
	}

	/* If the object wants only one colour, then give it that colour. */
	if ((spec->flags & OBJECT_FLAG_2CC_COLOUR) == 0) o->colour &= 0xF;

	if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) {
		uint16_t res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile);
		if (res != CALLBACK_FAILED) {
			if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res);
			o->colour = GB(res, 0, 8);
		}
	}

	assert(o->town != nullptr);

	for (TileIndex t : ta) {
		WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID);
		/* Update company infrastructure counts for objects build on canals owned by nobody. */
		if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(t, OWNER_NONE) || IsTileOwner(t, OWNER_WATER))) {
			Company::Get(owner)->infrastructure.water++;
			DirtyCompanyInfrastructureWindows(owner);
		}
		bool remove = IsDockingTile(t);
		MakeObject(t, owner, o->index, wc, Random());
		if (remove) RemoveDockingTile(t);
		MarkTileDirtyByTile(t);
	}

	Object::IncTypeCount(type);
	if (spec->flags & OBJECT_FLAG_ANIMATION) TriggerObjectAnimation(o, OAT_BUILT, spec);
}

/**
 * Increase the animation stage of a whole structure.
 * @param tile The tile of the structure.
 */
static void IncreaseAnimationStage(TileIndex tile)
{
	TileArea ta = Object::GetByTile(tile)->location;
	for (TileIndex t : ta) {
		SetAnimationFrame(t, GetAnimationFrame(t) + 1);
		MarkTileDirtyByTile(t);
	}
}

/** We encode the company HQ size in the animation stage. */
#define GetCompanyHQSize GetAnimationFrame
/** We encode the company HQ size in the animation stage. */
#define IncreaseCompanyHQSize IncreaseAnimationStage

/**
 * Update the CompanyHQ to the state associated with the given score
 * @param tile  The (northern) tile of the company HQ, or INVALID_TILE.
 * @param score The current (performance) score of the company.
 */
void UpdateCompanyHQ(TileIndex tile, uint score)
{
	if (tile == INVALID_TILE) return;

	byte val = 0;
	if (score >= 170) val++;
	if (score >= 350) val++;
	if (score >= 520) val++;
	if (score >= 720) val++;

	while (GetCompanyHQSize(tile) < val) {
		IncreaseCompanyHQSize(tile);
	}
}

/**
 * Updates the colour of the object whenever a company changes.
 * @param c The company the company colour changed of.
 */
void UpdateObjectColours(const Company *c)
{
	for (Object *obj : Object::Iterate()) {
		Owner owner = GetTileOwner(obj->location.tile);
		/* Not the current owner, so colour doesn't change. */
		if (owner != c->index) continue;

		const ObjectSpec *spec = ObjectSpec::GetByTile(obj->location.tile);
		/* Using the object colour callback, so not using company colour. */
		if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) continue;

		const Livery *l = c->livery;
		obj->colour = ((spec->flags & OBJECT_FLAG_2CC_COLOUR) ? (l->colour2 * 16) : 0) + l->colour1;
	}
}

extern CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge);
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags);

/**
 * Build an object object
 * @param flags type of operation
 * @param tile tile where the object will be located
 * @param type the object type to build
 * @param view the view for the object
 * @return the cost of this operation or an error
 */
CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, uint8_t view)
{
	CommandCost cost(EXPENSES_CONSTRUCTION);

	if (type >= ObjectSpec::Count()) return CMD_ERROR;
	const ObjectSpec *spec = ObjectSpec::Get(type);
	if (_game_mode == GM_NORMAL && !spec->IsAvailable() && !_generating_world) return CMD_ERROR;
	if ((_game_mode == GM_EDITOR || _generating_world) && !spec->WasEverAvailable()) return CMD_ERROR;

	if ((spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT) != 0 && ((!_generating_world && _game_mode != GM_EDITOR) || _current_company != OWNER_NONE)) return CMD_ERROR;
	if ((spec->flags & OBJECT_FLAG_ONLY_IN_GAME) != 0 && (_generating_world || _game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;
	if (view >= spec->views) return CMD_ERROR;

	if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS);
	if (Town::GetNumItems() == 0) return_cmd_error(STR_ERROR_MUST_FOUND_TOWN_FIRST);

	int size_x = GB(spec->size, HasBit(view, 0) ? 4 : 0, 4);
	int size_y = GB(spec->size, HasBit(view, 0) ? 0 : 4, 4);
	TileArea ta(tile, size_x, size_y);
	for (TileIndex t : ta) {
		if (!IsValidTile(t)) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map
	}

	if (type == OBJECT_OWNED_LAND) {
		/* Owned land is special as it can be placed on any slope. */
		cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
	} else {
		/* Check the surface to build on. At this time we can't actually execute the
		 * the CLEAR_TILE commands since the newgrf callback later on can check
		 * some information about the tiles. */
		bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
		bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
		for (TileIndex t : ta) {
			if (HasTileWaterGround(t)) {
				if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
				if (!IsWaterTile(t)) {
					/* Normal water tiles don't have to be cleared. For all other tile types clear
					 * the tile but leave the water. */
					cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_NO_WATER & ~DC_EXEC, t));
				} else {
					/* Can't build on water owned by another company. */
					Owner o = GetTileOwner(t);
					if (o != OWNER_NONE && o != OWNER_WATER) cost.AddCost(CheckOwnership(o, t));

					/* However, the tile has to be clear of vehicles. */
					cost.AddCost(EnsureNoVehicleOnGround(t));
				}
			} else {
				if (!allow_ground) return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
				/* For non-water tiles, we'll have to clear it before building. */

				/* When relocating HQ, allow it to be relocated (partial) on itself. */
				if (!(type == OBJECT_HQ &&
						IsTileType(t, MP_OBJECT) &&
						IsTileOwner(t, _current_company) &&
						IsObjectType(t, OBJECT_HQ))) {
					cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_EXEC, t));
				}
			}
		}

		/* So, now the surface is checked... check the slope of said surface. */
		int allowed_z;
		if (GetTileSlope(tile, &allowed_z) != SLOPE_FLAT) allowed_z++;

		for (TileIndex t : ta) {
			uint16_t callback = CALLBACK_FAILED;
			if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) {
				TileIndex diff = t - tile;
				callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t), TileY(diff) << 4 | TileX(diff), spec, nullptr, t, view);
			}

			if (callback == CALLBACK_FAILED) {
				cost.AddCost(CheckBuildableTile(t, 0, allowed_z, false, false));
			} else {
				/* The meaning of bit 10 is inverted for a grf version < 8. */
				if (spec->grf_prop.grffile->grf_version < 8) ToggleBit(callback, 10);
				CommandCost ret = GetErrorMessageFromLocationCallbackResult(callback, spec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
				if (ret.Failed()) return ret;
			}
		}

		if (flags & DC_EXEC) {
			/* This is basically a copy of the loop above with the exception that we now
			 * execute the commands and don't check for errors, since that's already done. */
			for (TileIndex t : ta) {
				if (HasTileWaterGround(t)) {
					if (!IsWaterTile(t)) {
						Command<CMD_LANDSCAPE_CLEAR>::Do((flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, t);
					}
				} else {
					Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DC_NO_MODIFY_TOWN_RATING, t);
				}
			}
		}
	}
	if (cost.Failed()) return cost;

	/* Finally do a check for bridges. */
	for (TileIndex t : ta) {
		if (IsBridgeAbove(t) && (
				!(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) ||
				(GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
			return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
		}
	}

	int hq_score = 0;
	uint build_object_size = 1;
	switch (type) {
		case OBJECT_TRANSMITTER:
		case OBJECT_LIGHTHOUSE:
			if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
			break;

		case OBJECT_OWNED_LAND:
			if (IsTileType(tile, MP_OBJECT) &&
					IsTileOwner(tile, _current_company) &&
					IsObjectType(tile, OBJECT_OWNED_LAND)) {
				return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
			}
			break;

		case OBJECT_HQ: {
			Company *c = Company::Get(_current_company);
			if (c->location_of_HQ != INVALID_TILE) {
				/* Don't relocate HQ on the same location. */
				if (c->location_of_HQ == tile) return_cmd_error(STR_ERROR_ALREADY_BUILT);
				/* We need to persuade a bit harder to remove the old HQ. */
				_current_company = OWNER_WATER;
				cost.AddCost(ClearTile_Object(c->location_of_HQ, flags));
				_current_company = c->index;
			}

			if (flags & DC_EXEC) {
				hq_score = UpdateCompanyRatingAndValue(c, false);
				c->location_of_HQ = tile;
				SetWindowDirty(WC_COMPANY, c->index);
			}
			break;
		}

		case OBJECT_STATUE:
			/* This may never be constructed using this method. */
			return CMD_ERROR;

		default: // i.e. NewGRF provided.
			build_object_size = size_x * size_y;
			break;
	}

	/* Don't allow building more objects if the company has reached its limit. */
	Company *c = Company::GetIfValid(_current_company);
	if (c != nullptr && GB(c->build_object_limit, 16, 16) < build_object_size) {
		return_cmd_error(STR_ERROR_BUILD_OBJECT_LIMIT_REACHED);
	}

	if (flags & DC_EXEC) {
		BuildObject(type, tile, _current_company == OWNER_DEITY ? OWNER_NONE : _current_company, nullptr, view);

		/* Make sure the HQ starts at the right size. */
		if (type == OBJECT_HQ) UpdateCompanyHQ(tile, hq_score);

		/* Subtract the tile from the build limit. */
		if (c != nullptr) c->build_object_limit -= build_object_size << 16;
	}

	cost.AddCost(spec->GetBuildCost() * build_object_size);
	return cost;
}

/**
 * Construct multiple objects in an area
 * @param flags of operation to conduct
 * @param tile end tile of area dragging
 * @param start_tile start tile of area dragging
 * @param type the object type to build
 * @param view the view for the object
 * @param diagonal Whether to use the Orthogonal (0) or Diagonal (1) iterator.
 * @return the cost of this operation or an error
 */
CommandCost CmdBuildObjectArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal)
{
	if (start_tile >= Map::Size()) return CMD_ERROR;

	if (type >= ObjectSpec::Count()) return CMD_ERROR;
	const ObjectSpec *spec = ObjectSpec::Get(type);
	if (view >= spec->views) return CMD_ERROR;

	if (spec->size != OBJECT_SIZE_1X1) return CMD_ERROR;

	Money money = GetAvailableMoneyForCommand();
	CommandCost cost(EXPENSES_CONSTRUCTION);
	CommandCost last_error = CMD_ERROR;
	bool had_success = false;

	const Company *c = Company::GetIfValid(_current_company);
	int limit = (c == nullptr ? INT32_MAX : GB(c->build_object_limit, 16, 16));

	std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
	for (; *iter != INVALID_TILE; ++(*iter)) {
		TileIndex t = *iter;
		CommandCost ret = Command<CMD_BUILD_OBJECT>::Do(flags & ~DC_EXEC, t, type, view);

		/* If we've reached the limit, stop building (or testing). */
		if (c != nullptr && limit-- <= 0) break;

		if (ret.Failed()) {
			last_error = ret;
			continue;
		}

		had_success = true;
		if (flags & DC_EXEC) {
			money -= ret.GetCost();

			/* If we run out of money, stop building. */
			if (ret.GetCost() > 0 && money < 0) break;
			Command<CMD_BUILD_OBJECT>::Do(flags, t, type, view);
		}
		cost.AddCost(ret);
	}

	return had_success ? cost : last_error;
}

static Foundation GetFoundation_Object(TileIndex tile, Slope tileh);

static void DrawTile_Object(TileInfo *ti)
{
	ObjectType type = GetObjectType(ti->tile);
	const ObjectSpec *spec = ObjectSpec::Get(type);

	/* Fall back for when the object doesn't exist anymore. */
	if (!spec->IsEnabled()) type = OBJECT_TRANSMITTER;

	if ((spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) == 0) DrawFoundation(ti, GetFoundation_Object(ti->tile, ti->tileh));

	if (type < NEW_OBJECT_OFFSET) {
		const DrawTileSprites *dts = nullptr;
		Owner to = GetTileOwner(ti->tile);
		PaletteID palette = to == OWNER_NONE ? PAL_NONE : COMPANY_SPRITE_COLOUR(to);

		if (type == OBJECT_HQ) {
			TileIndex diff = ti->tile - Object::GetByTile(ti->tile)->location.tile;
			dts = &_object_hq[GetCompanyHQSize(ti->tile) << 2 | TileY(diff) << 1 | TileX(diff)];
		} else {
			dts = &_objects[type];
		}

		if (spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) {
			/* If an object has no foundation, but tries to draw a (flat) ground
			 * type... we have to be nice and convert that for them. */
			switch (dts->ground.sprite) {
				case SPR_FLAT_BARE_LAND:          DrawClearLandTile(ti, 0); break;
				case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1); break;
				case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2); break;
				case SPR_FLAT_GRASS_TILE:         DrawClearLandTile(ti, 3); break;
				default: DrawGroundSprite(dts->ground.sprite, palette);     break;
			}
		} else {
			DrawGroundSprite(dts->ground.sprite, palette);
		}

		if (!IsInvisibilitySet(TO_STRUCTURES)) {
			const DrawTileSeqStruct *dtss;
			foreach_draw_tile_seq(dtss, dts->seq) {
				AddSortableSpriteToDraw(
					dtss->image.sprite, palette,
					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
					dtss->size_x, dtss->size_y,
					dtss->size_z, ti->z + dtss->delta_z,
					IsTransparencySet(TO_STRUCTURES)
				);
			}
		}
	} else {
		DrawNewObjectTile(ti, spec);
	}

	DrawBridgeMiddle(ti);
}

static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y, bool)
{
	if (IsObjectType(tile, OBJECT_OWNED_LAND)) {
		int z;
		Slope tileh = GetTilePixelSlope(tile, &z);

		return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
	} else {
		return GetTileMaxPixelZ(tile);
	}
}

static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
{
	return IsObjectType(tile, OBJECT_OWNED_LAND) ? FOUNDATION_NONE : FlatteningFoundation(tileh);
}

/**
 * Perform the actual removal of the object from the map.
 * @param o The object to really clear.
 */
static void ReallyClearObjectTile(Object *o)
{
	Object::DecTypeCount(o->type);
	for (TileIndex tile_cur : o->location) {
		DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur.base());

		MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
	}
	delete o;
}

std::vector<ClearedObjectArea> _cleared_object_areas;

/**
 * Find the entry in _cleared_object_areas which occupies a certain tile.
 * @param tile Tile of interest
 * @return Occupying entry, or nullptr if none
 */
ClearedObjectArea *FindClearedObject(TileIndex tile)
{
	TileArea ta = TileArea(tile, 1, 1);

	for (ClearedObjectArea &coa : _cleared_object_areas) {
		if (coa.area.Intersects(ta)) return &coa;
	}

	return nullptr;
}

static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
{
	/* Get to the northern most tile. */
	Object *o = Object::GetByTile(tile);
	TileArea ta = o->location;

	ObjectType type = o->type;
	const ObjectSpec *spec = ObjectSpec::Get(type);

	CommandCost cost(EXPENSES_CONSTRUCTION, spec->GetClearCost() * ta.w * ta.h / 5);
	if (spec->flags & OBJECT_FLAG_CLEAR_INCOME) cost.MultiplyCost(-1); // They get an income!

	/* Towns can't remove any objects. */
	if (_current_company == OWNER_TOWN) return CMD_ERROR;

	/* Water can remove everything! */
	if (_current_company != OWNER_WATER) {
		if ((flags & DC_NO_WATER) && IsTileOnWater(tile)) {
			/* There is water under the object, treat it as water tile. */
			return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
		} else if (!(spec->flags & OBJECT_FLAG_AUTOREMOVE) && (flags & DC_AUTO)) {
			/* No automatic removal by overbuilding stuff. */
			return_cmd_error(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY);
		} else if (_game_mode == GM_EDITOR) {
			/* No further limitations for the editor. */
		} else if (GetTileOwner(tile) == OWNER_NONE) {
			/* Owned by nobody and unremovable, so we can only remove it with brute force! */
			if (!_cheats.magic_bulldozer.value && (spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0) return CMD_ERROR;
		} else if (CheckTileOwnership(tile).Failed()) {
			/* We don't own it!. */
			return_cmd_error(STR_ERROR_OWNED_BY);
		} else if ((spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0 && (spec->flags & OBJECT_FLAG_AUTOREMOVE) == 0) {
			/* In the game editor or with cheats we can remove, otherwise we can't. */
			if (!_cheats.magic_bulldozer.value) {
				if (type == OBJECT_HQ) return_cmd_error(STR_ERROR_COMPANY_HEADQUARTERS_IN);
				return CMD_ERROR;
			}

			/* Removing with the cheat costs more in TTDPatch / the specs. */
			cost.MultiplyCost(25);
		}
	} else if ((spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0) {
		/* Water can't remove objects that are buildable on water. */
		return CMD_ERROR;
	}

	switch (type) {
		case OBJECT_HQ: {
			Company *c = Company::Get(GetTileOwner(tile));
			if (flags & DC_EXEC) {
				c->location_of_HQ = INVALID_TILE; // reset HQ position
				SetWindowDirty(WC_COMPANY, c->index);
				CargoPacket::InvalidateAllFrom(SourceType::Headquarters, c->index);
			}

			/* cost of relocating company is 1% of company value */
			cost = CommandCost(EXPENSES_CONSTRUCTION, CalculateCompanyValue(c) / 100);
			break;
		}

		case OBJECT_STATUE:
			if (flags & DC_EXEC) {
				Town *town = o->town;
				ClrBit(town->statues, GetTileOwner(tile));
				SetWindowDirty(WC_TOWN_AUTHORITY, town->index);
			}
			break;

		default:
			break;
	}

	_cleared_object_areas.push_back({tile, ta});

	if (flags & DC_EXEC) ReallyClearObjectTile(o);

	return cost;
}

static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
{
	if (!IsObjectType(tile, OBJECT_HQ)) return;

	/* HQ accepts passenger and mail; but we have to divide the values
	 * between 4 tiles it occupies! */

	/* HQ level (depends on company performance) in the range 1..5. */
	uint level = GetCompanyHQSize(tile) + 1;

	/* Top town building generates 10, so to make HQ interesting, the top
	 * type makes 20. */
	acceptance[CT_PASSENGERS] += std::max(1U, level);
	SetBit(*always_accepted, CT_PASSENGERS);

	/* Top town building generates 4, HQ can make up to 8. The
	 * proportion passengers:mail is different because such a huge
	 * commercial building generates unusually high amount of mail
	 * correspondence per physical visitor. */
	acceptance[CT_MAIL] += std::max(1U, level / 2);
	SetBit(*always_accepted, CT_MAIL);
}

static void AddProducedCargo_Object(TileIndex tile, CargoArray &produced)
{
	if (!IsObjectType(tile, OBJECT_HQ)) return;

	produced[CT_PASSENGERS]++;
	produced[CT_MAIL]++;
}


static void GetTileDesc_Object(TileIndex tile, TileDesc *td)
{
	const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
	td->str = spec->name;
	td->owner[0] = GetTileOwner(tile);
	td->build_date = Object::GetByTile(tile)->build_date;

	if (spec->grf_prop.grffile != nullptr) {
		td->grf = GetGRFConfig(spec->grf_prop.grffile->grfid)->GetName();
	}
}

static void TileLoop_Object(TileIndex tile)
{
	const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
	if (spec->flags & OBJECT_FLAG_ANIMATION) {
		Object *o = Object::GetByTile(tile);
		TriggerObjectTileAnimation(o, tile, OAT_TILELOOP, spec);
		if (o->location.tile == tile) TriggerObjectAnimation(o, OAT_256_TICKS, spec);
	}

	if (IsTileOnWater(tile)) TileLoop_Water(tile);

	if (!IsObjectType(tile, OBJECT_HQ)) return;

	/* HQ accepts passenger and mail; but we have to divide the values
	 * between 4 tiles it occupies! */

	/* HQ level (depends on company performance) in the range 1..5. */
	uint level = GetCompanyHQSize(tile) + 1;
	assert(level < 6);

	StationFinder stations(TileArea(tile, 2, 2));

	uint r = Random();
	/* Top town buildings generate 250, so the top HQ type makes 256. */
	if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
		uint amt = GB(r, 0, 8) / 8 / 4 + 1;
		if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
		MoveGoodsToStation(CT_PASSENGERS, amt, SourceType::Headquarters, GetTileOwner(tile), stations.GetStations());
	}

	/* Top town building generates 90, HQ can make up to 196. The
	 * proportion passengers:mail is about the same as in the acceptance
	 * equations. */
	if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
		uint amt = GB(r, 8, 8) / 8 / 4 + 1;
		if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
		MoveGoodsToStation(CT_MAIL, amt, SourceType::Headquarters, GetTileOwner(tile), stations.GetStations());
	}
}


static TrackStatus GetTileTrackStatus_Object(TileIndex, TransportType, uint, DiagDirection)
{
	return 0;
}

static bool ClickTile_Object(TileIndex tile)
{
	if (!IsObjectType(tile, OBJECT_HQ)) return false;

	ShowCompany(GetTileOwner(tile));
	return true;
}

static void AnimateTile_Object(TileIndex tile)
{
	AnimateNewObjectTile(tile);
}

/**
 * Helper function for \c CircularTileSearch.
 * @param tile The tile to check.
 * @return True iff the tile has a radio tower.
 */
static bool HasTransmitter(TileIndex tile, void *)
{
	return IsObjectTypeTile(tile, OBJECT_TRANSMITTER);
}

/**
 * Try to build a lighthouse.
 * @return True iff building a lighthouse succeeded.
 */
static bool TryBuildLightHouse()
{
	uint maxx = Map::MaxX();
	uint maxy = Map::MaxY();
	uint r = Random();

	/* Scatter the lighthouses more evenly around the perimeter */
	int perimeter = (GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
	DiagDirection dir;
	for (dir = DIAGDIR_NE; perimeter > 0; dir++) {
		perimeter -= (DiagDirToAxis(dir) == AXIS_X) ? maxx : maxy;
	}

	TileIndex tile;
	switch (dir) {
		default:
		case DIAGDIR_NE: tile = TileXY(maxx - 1, r % maxy); break;
		case DIAGDIR_SE: tile = TileXY(r % maxx, 1); break;
		case DIAGDIR_SW: tile = TileXY(1,        r % maxy); break;
		case DIAGDIR_NW: tile = TileXY(r % maxx, maxy - 1); break;
	}

	/* Only build lighthouses at tiles where the border is sea. */
	if (!IsTileType(tile, MP_WATER)) return false;

	for (int j = 0; j < 19; j++) {
		int h;
		if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h <= 2 && !IsBridgeAbove(tile)) {
			BuildObject(OBJECT_LIGHTHOUSE, tile);
			assert(tile < Map::Size());
			return true;
		}
		tile += TileOffsByDiagDir(dir);
		if (!IsValidTile(tile)) return false;
	}
	return false;
}

/**
 * Try to build a transmitter.
 * @return True iff a transmitter was built.
 */
static bool TryBuildTransmitter()
{
	TileIndex tile = RandomTile();
	int h;
	if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h >= 4 && !IsBridgeAbove(tile)) {
		TileIndex t = tile;
		if (CircularTileSearch(&t, 9, HasTransmitter, nullptr)) return false;

		BuildObject(OBJECT_TRANSMITTER, tile);
		return true;
	}
	return false;
}

void GenerateObjects()
{
	/* Set a guestimate on how much we progress */
	SetGeneratingWorldProgress(GWP_OBJECT, (uint)ObjectSpec::Count());

	/* Determine number of water tiles at map border needed for freeform_edges */
	uint num_water_tiles = 0;
	if (_settings_game.construction.freeform_edges) {
		for (uint x = 0; x < Map::MaxX(); x++) {
			if (IsTileType(TileXY(x, 1), MP_WATER)) num_water_tiles++;
			if (IsTileType(TileXY(x, Map::MaxY() - 1), MP_WATER)) num_water_tiles++;
		}
		for (uint y = 1; y < Map::MaxY() - 1; y++) {
			if (IsTileType(TileXY(1, y), MP_WATER)) num_water_tiles++;
			if (IsTileType(TileXY(Map::MaxX() - 1, y), MP_WATER)) num_water_tiles++;
		}
	}

	/* Iterate over all possible object types */
	for (const auto &spec : ObjectSpec::Specs()) {

		/* Continue, if the object was never available till now or shall not be placed */
		if (!spec.WasEverAvailable() || spec.generate_amount == 0) continue;

		uint16_t amount = spec.generate_amount;

		/* Scale by map size */
		if ((spec.flags & OBJECT_FLAG_SCALE_BY_WATER) && _settings_game.construction.freeform_edges) {
			/* Scale the amount of lighthouses with the amount of land at the borders.
			 * The -6 is because the top borders are MP_VOID (-2) and all corners
			 * are counted twice (-4). */
			amount = Map::ScaleBySize1D(amount * num_water_tiles) / (2 * Map::MaxY() + 2 * Map::MaxX() - 6);
		} else if (spec.flags & OBJECT_FLAG_SCALE_BY_WATER) {
			amount = Map::ScaleBySize1D(amount);
		} else {
			amount = Map::ScaleBySize(amount);
		}

		/* Now try to place the requested amount of this object */
		for (uint j = Map::ScaleBySize(1000); j != 0 && amount != 0 && Object::CanAllocateItem(); j--) {
			switch (spec.Index()) {
				case OBJECT_TRANSMITTER:
					if (TryBuildTransmitter()) amount--;
					break;

				case OBJECT_LIGHTHOUSE:
					if (TryBuildLightHouse()) amount--;
					break;

				default:
					uint8_t view = RandomRange(spec.views);
					if (CmdBuildObject(DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, RandomTile(), spec.Index(), view).Succeeded()) amount--;
					break;
			}
		}
		IncreaseGeneratingWorldProgress(GWP_OBJECT);
	}
}

static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_owner)
{
	if (!IsTileOwner(tile, old_owner)) return;

	bool do_clear = false;

	ObjectType type = GetObjectType(tile);
	if ((type == OBJECT_OWNED_LAND || type >= NEW_OBJECT_OFFSET) && new_owner != INVALID_OWNER) {
		SetTileOwner(tile, new_owner);
	} else if (type == OBJECT_STATUE) {
		Town *t = Object::GetByTile(tile)->town;
		ClrBit(t->statues, old_owner);
		if (new_owner != INVALID_OWNER && !HasBit(t->statues, new_owner)) {
			/* Transfer ownership to the new company */
			SetBit(t->statues, new_owner);
			SetTileOwner(tile, new_owner);
		} else {
			do_clear = true;
		}

		SetWindowDirty(WC_TOWN_AUTHORITY, t->index);
	} else {
		do_clear = true;
	}

	if (do_clear) {
		ReallyClearObjectTile(Object::GetByTile(tile));
		/* When clearing objects, they may turn into canal, which may require transferring ownership. */
		ChangeTileOwner(tile, old_owner, new_owner);
	}
}

static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
{
	ObjectType type = GetObjectType(tile);

	if (type == OBJECT_OWNED_LAND) {
		/* Owned land remains unsold */
		CommandCost ret = CheckTileOwnership(tile);
		if (ret.Succeeded()) return CommandCost();
	} else if (AutoslopeEnabled() && type != OBJECT_TRANSMITTER && type != OBJECT_LIGHTHOUSE) {
		/* Behaviour:
		 *  - Both new and old slope must not be steep.
		 *  - TileMaxZ must not be changed.
		 *  - Allow autoslope by default.
		 *  - Disallow autoslope if callback succeeds and returns non-zero.
		 */
		Slope tileh_old = GetTileSlope(tile);
		/* TileMaxZ must not be changed. Slopes must not be steep. */
		if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
			const ObjectSpec *spec = ObjectSpec::Get(type);

			/* Call callback 'disable autosloping for objects'. */
			if (HasBit(spec->callback_mask, CBM_OBJ_AUTOSLOPE)) {
				/* If the callback fails, allow autoslope. */
				uint16_t res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile);
				if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
			} else if (spec->IsEnabled()) {
				/* allow autoslope */
				return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
			}
		}
	}

	return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
}

extern const TileTypeProcs _tile_type_object_procs = {
	DrawTile_Object,             // draw_tile_proc
	GetSlopePixelZ_Object,       // get_slope_z_proc
	ClearTile_Object,            // clear_tile_proc
	AddAcceptedCargo_Object,     // add_accepted_cargo_proc
	GetTileDesc_Object,          // get_tile_desc_proc
	GetTileTrackStatus_Object,   // get_tile_track_status_proc
	ClickTile_Object,            // click_tile_proc
	AnimateTile_Object,          // animate_tile_proc
	TileLoop_Object,             // tile_loop_proc
	ChangeTileOwner_Object,      // change_tile_owner_proc
	AddProducedCargo_Object,     // add_produced_cargo_proc
	nullptr,                        // vehicle_enter_tile_proc
	GetFoundation_Object,        // get_foundation_proc
	TerraformTile_Object,        // terraform_tile_proc
};