forked from teamhimeh/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objlist.cc
1320 lines (1179 loc) · 33.1 KB
/
objlist.cc
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
/*
* This file is part of the Simutrans project under the Artistic License.
* (see LICENSE.txt)
*/
#include <stdio.h>
#include <algorithm>
#include "../simdebug.h"
#include "../display/simgraph.h"
#include "../simworld.h"
#include "../bauer/hausbauer.h"
#include "../obj/dummy.h"
#include "../obj/wolke.h"
#include "../obj/zeiger.h"
#include "../obj/crossing.h"
#include "../obj/baum.h"
#include "../obj/bruecke.h"
#include "../obj/field.h"
#include "../obj/pillar.h"
#include "../obj/tunnel.h"
#include "../obj/gebaeude.h"
#include "../obj/signal.h"
#include "../obj/label.h"
#include "../obj/leitung2.h"
#include "../obj/wayobj.h"
#include "../obj/roadsign.h"
#include "../obj/groundobj.h"
#include "../simtypes.h"
#include "../simdepot.h"
#include "../simmem.h"
#include "../player/simplay.h"
#include "../vehicle/simvehicle.h"
#include "../vehicle/simroadtraffic.h"
#include "../vehicle/simpeople.h"
#include "../vehicle/movingobj.h"
#include "../descriptor/building_desc.h"
#include "../descriptor/groundobj_desc.h"
#include "../dataobj/loadsave.h"
#include "../dataobj/freelist.h"
#include "../dataobj/environment.h"
#include "objlist.h"
/* All things including ways are stored in this structure.
* The entries are packed, i.e. the first free entry is at the top.
* To save memory, a single element (like in the case for houses or a single tree)
* is stored directly (obj.one) and capacity==1. Otherwise obj.some points to an
* array.
* The objects are sorted according to their drawing order.
* ways are always first.
*/
#define baum_pri (50)
#define pillar_pri (7)
#define wayobj_pri (8)
// priority of moving things: should be smaller than the priority of powerlines
#define moving_obj_pri (100)
// priority for entering into objlist
// unused entries have 255
static uint8 type_to_pri[256]=
{
255, //
baum_pri, // tree
254, // cursor/pointers
200, 200, 200, // wolke
3, 3, // buildings
6, // signal
2, 2, // bridge/tunnel
255,
1, 1, 1, // depots
5, // smoke generator (not used any more)
150, 4, 4, // powerlines
6, // roadsign
pillar_pri, // pillar
1, 1, 1, 1, // depots (must be before tunnel!)
wayobj_pri, // way objects (electrification)
0, // ways (always at the top!)
9, // label, indicates ownership: insert before trees
3, // field (factory extension)
1, // crossings, treated like bridges or tunnels
1, // groundobjs, overlays over bare ground like lakes etc.
1, // narrowgaugedepot
255, 255, 255, 255, 255, 255, 255, 255, // 32-63 left empty (old numbers)
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
moving_obj_pri, // pedestrians
moving_obj_pri, // city cars
moving_obj_pri, // road vehicle
moving_obj_pri, // rail vehicle
moving_obj_pri, // monorail
moving_obj_pri, // maglev
moving_obj_pri, // narrowgauge
255, 255, 255, 255, 255, 255, 255, 255, 255,
moving_obj_pri, // ship
moving_obj_pri+1, // aircraft (no trailer, could be handled by normal method)
moving_obj_pri+1, // movingobject (no trailer, could be handled by normal method)
255, 255, 255, 255, 255, 255, 255, 255, // 83-95 left empty (for other moving stuff) 95, is reserved for old choosesignals
255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, // 96-128 left empty (old numbers)
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, // 128-255 left empty
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255
};
static void dl_free(obj_t** p, uint8 size)
{
assert(size > 1);
if (size <= 16) {
freelist_t::putback_node(sizeof(*p) * size, p);
}
else {
free(p);
}
}
static obj_t** dl_alloc(uint8 size)
{
assert(size > 1);
obj_t** p;
if (size <= 16) {
p = static_cast<obj_t**>(freelist_t::gimme_node(sizeof(*p) * size ));
}
else {
p = MALLOCN(obj_t*, size);
}
return p;
}
objlist_t::objlist_t()
{
obj.one = NULL;
capacity = 0;
top = 0;
}
objlist_t::~objlist_t()
{
if( capacity == 1 ) {
obj.one->set_flag(obj_t::not_on_map);
if(!obj.one->has_managed_lifecycle()) {
delete obj.one;
}
}
else {
for( uint8 i=0; i<top; i++ ) {
obj_t* const object = obj.some[i];
object->set_flag(obj_t::not_on_map);
if(!object->has_managed_lifecycle()) {
delete object;
}
}
}
if(capacity>1) {
dl_free(obj.some, capacity);
}
obj.some = NULL;
capacity = top = 0;
}
void objlist_t::set_capacity(uint16 new_cap)
{
// DBG_MESSAGE("objlist_t::set_capacity()", "old cap=%d, new cap=%d", capacity, new_cap);
if(new_cap>=255) {
new_cap = 254;
}
// a single object is stored differentially
if(new_cap==0) {
if(capacity>1) {
dl_free( obj.some, capacity );
}
obj.one = NULL;
capacity = 0;
top = 0;
}
else if(new_cap==1) {
if(capacity>1) {
obj_t *tmp=NULL;
// we have an obj to save into the list
tmp = obj.some[0];
dl_free( obj.some, capacity );
obj.one = tmp;
assert(top<2);
}
else if(top==0) {
obj.one = NULL;
}
capacity = top;
}
// a single object is stored differentially
else if(capacity<=1 && new_cap>1) {
// if we reach here, new_cap>1 and (capacity==0 or capacity>1)
obj_t *tmp=obj.one;
obj.some = dl_alloc(new_cap);
MEMZERON(obj.some, new_cap);
obj.some[0] = tmp;
capacity = new_cap;
assert(top<=1);
}
else {
// we need to copy old list to large list
assert( top<=new_cap );
// get memory
obj_t **tmp = dl_alloc(new_cap);
// free old memory
if(obj.some) {
memcpy( tmp, obj.some, sizeof(obj_t *)*top );
dl_free(obj.some, capacity);
}
obj.some = tmp;
capacity = new_cap;
}
}
bool objlist_t::grow_capacity()
{
if(capacity==0) {
return true;
}
else if(capacity==1) {
set_capacity( 4 );
return true;
}
else if(capacity>=254) {
// capacity exceeded ... (and no need for THAT many objects here ... )
return false;
}
else {
// size exceeded, extent
uint16 new_cap = (uint16)capacity+4;
set_capacity( new_cap );
return true;
}
}
void objlist_t::shrink_capacity(uint8 o_top)
{
// strategy: avoid freeing mem if not needed. Only if we hold lots of memory then free it.
// this is almost only called when deleting ways in practice
if( capacity > 16 && o_top <= 4 ) {
set_capacity(o_top);
}
}
inline void objlist_t::intern_insert_at(obj_t* new_obj, uint8 pri)
{
// we have more than one object here, thus we can use obj.some exclusively!
for( uint8 i=top; i>pri; i-- ) {
obj.some[i] = obj.some[i-1];
}
obj.some[pri] = new_obj;
top++;
}
// only used internal for loading. DO NOT USE OTHERWISE!
bool objlist_t::append(obj_t *new_obj)
{
if(capacity==0) {
// the first one save direct
obj.one = new_obj;
top = 1;
capacity = 1;
return true;
}
if(top>=capacity && !grow_capacity()) {
// memory exceeded
return false;
}
intern_insert_at(new_obj, top);
return true;
}
// this will automatically give the right order for citycars and the like ...
bool objlist_t::intern_add_moving(obj_t* new_obj)
{
// we are more than one object, thus we exclusively use obj.some here!
// it would be nice, if also the objects are inserted according to their priorities as
// vehicles types (number returned by get_typ()). However, this would increase
// the calculation even further. :(
// insert at this lane
uint8 lane = ((vehicle_base_t*)new_obj)->get_disp_lane();
// find out about the first car etc. moving thing.
// We can start to insert between (start) and (end)
uint8 start=0;
while(start<top && (!obj.some[start]->is_moving() || ((vehicle_base_t*)obj.some[start])->get_disp_lane() < lane) ) {
start ++;
}
uint8 end = top;
while( end>start && (!obj.some[end-1]->is_moving() || ((vehicle_base_t*)obj.some[end-1])->get_disp_lane() > lane) ) {
end--;
}
if(start==end) {
intern_insert_at(new_obj, start);
return true;
}
const uint8 direction = ((vehicle_base_t*)new_obj)->get_direction();
switch(lane) {
// pedestrians or road vehicles, back: either w/sw/s or n/ne/e
case 0:
case 1: {
// on right side to w,sw; on left to n: insert last
// on right side to s; on left to ne,e: insert first
if (direction == ribi_t::south || (direction & ribi_t::east)) {
intern_insert_at(new_obj, start);
}
else {
intern_insert_at(new_obj, end);
}
return true;
}
// middle land
case 2:
case 3:
// pedestrians, road vehicles, front lane
case 4: {
// going e/s: insert first, else last
if ( (direction & ribi_t::northwest)==0 ) {
intern_insert_at(new_obj, start);
}
else {
intern_insert_at(new_obj, end);
}
return true;
}
}
return false;
}
/**
* @returns true if tree1 must be sorted before tree2 (tree1 stands behind tree2)
*/
bool compare_trees(const obj_t *tree1, const obj_t *tree2)
{
// the tree with larger yoff is in front
sint8 diff = tree2->get_yoff() - tree1->get_yoff();
if (diff==0) {
// .. or the one that is the left most (ie xoff is small)
diff = tree1->get_xoff() - tree2->get_xoff();
}
return diff>0;
}
void objlist_t::sort_trees(uint8 index, uint8 count)
{
if(top>=index+count) {
std::sort(&obj.some[index], &obj.some[index+count], compare_trees);
}
}
bool objlist_t::add(obj_t* new_obj)
{
if(capacity==0) {
// the first one save direct
obj.one = new_obj;
top = 1;
capacity = 1;
return true;
}
if(top>=capacity && !grow_capacity()) {
// memory exceeded
return false;
}
if(top==0) {
intern_insert_at( new_obj, 0 );
return true;
}
// now top>0
// now insert it a the correct place
const uint8 pri=type_to_pri[new_obj->get_typ()];
// vehicles need a special order
if(pri==moving_obj_pri) {
return intern_add_moving(new_obj);
}
// roads must be first!
if(pri==0) {
// check for other ways to keep order! (maximum is two ways per tile at the moment)
weg_t const* const w = obj_cast<weg_t>(obj.some[0]);
uint8 const pos = w && w->get_waytype() < static_cast<weg_t*>(new_obj)->get_waytype() ? 1 : 0;
intern_insert_at(new_obj, pos);
return true;
}
uint8 i;
for( i=0; i<top && pri>type_to_pri[obj.some[i]->get_typ()]; i++ )
;
// now i contains the position, where we either insert of just add ...
if(i==top) {
obj.some[top] = new_obj;
top++;
}
else {
if(pri==baum_pri) {
/* trees are a little tricky, since they cast a shadow
* therefore the y-order must be correct!
*/
for( ; i<top; i++) {
baum_t const* const tree = obj_cast<baum_t>(obj.some[i]);
if (!tree || compare_trees(new_obj, tree)) {
break;
}
}
}
else if (pri == pillar_pri) {
// pillars have to be sorted wrt their y-offset, too.
for( ; i<top; i++) {
pillar_t const* const pillar = obj_cast<pillar_t>(obj.some[i]);
if (!pillar || new_obj->get_yoff() > pillar->get_yoff() ) {
break;
}
}
}
else if( pri == wayobj_pri && obj.some[i]->get_typ()==obj_t::wayobj ) {
wayobj_t const* const wo = obj_cast<wayobj_t>(obj.some[i]);
if( wo && wo->get_waytype() < obj_cast<wayobj_t>(new_obj)->get_waytype() ) {
// insert after a lower waytype
i += 1;
}
}
intern_insert_at(new_obj, i);
}
// then correct the upper border
return true;
}
// take the thing out from the list
// use this only for temporary removing
// since it does not shrink list or checks for ownership
obj_t *objlist_t::remove_last()
{
obj_t *last_obj=NULL;
if(capacity==0) {
// nothing
}
else if(capacity==1) {
last_obj = obj.one;
obj.one = NULL;
capacity = top = 0;
}
else {
if(top>0) {
top --;
last_obj = obj.some[top];
obj.some[top] = NULL;
}
}
return last_obj;
}
bool objlist_t::remove(const obj_t* remove_obj)
{
if( capacity == 0 ) {
return false;
}
else if( capacity == 1 ) {
if( obj.one == remove_obj ) {
obj.one = NULL;
capacity = 0;
top = 0;
return true;
}
return false;
}
// we keep the array dense!
for( uint8 i=0; i<top; i++ ) {
if( obj.some[i] == remove_obj ) {
// found it!
top--;
while( i < top ) {
obj.some[i] = obj.some[i+1];
i++;
}
obj.some[top] = NULL;
return true;
}
}
return false;
}
/**
* removes object from map
* deletes object if it is not a zeiger_t
*/
static void local_delete_object(obj_t *remove_obj, player_t *player)
{
vehicle_base_t* const v = obj_cast<vehicle_base_t>(remove_obj);
if (v && remove_obj->get_typ() != obj_t::pedestrian && remove_obj->get_typ() != obj_t::road_user && remove_obj->get_typ() != obj_t::movingobj) {
v->leave_tile();
}
else {
remove_obj->cleanup(player);
remove_obj->set_flag(obj_t::not_on_map);
// all objects except zeiger (pointer) are destroyed here
// zeiger's will be deleted if their associated tool terminates
if (!remove_obj->has_managed_lifecycle()) {
delete remove_obj;
}
}
}
bool objlist_t::loesche_alle(player_t *player, uint8 offset)
{
if(top<=offset) {
return false;
}
// something to delete?
bool ok=false;
if(capacity>1) {
while( top>offset ) {
top --;
local_delete_object(obj.some[top], player);
obj.some[top] = NULL;
ok = true;
}
}
else {
if(capacity==1) {
local_delete_object(obj.one, player);
ok = true;
obj.one = NULL;
capacity = top = 0;
}
}
shrink_capacity(top);
return ok;
}
/* returns the text of an error message, if obj could not be removed */
const char *objlist_t::kann_alle_entfernen(const player_t *player, uint8 offset) const
{
if(top<=offset) {
return NULL;
}
if(capacity==1) {
return obj.one->is_deletable(player);
}
else {
const char * msg = NULL;
for(uint8 i=offset; i<top; i++) {
msg = obj.some[i]->is_deletable(player);
if(msg != NULL) {
return msg;
}
}
}
return NULL;
}
/* recalculates all images
*/
void objlist_t::calc_image()
{
if(capacity==0) {
// nothing
}
else if(capacity==1) {
obj.one->calc_image();
}
else {
for(uint8 i=0; i<top; i++) {
obj.some[i]->calc_image();
}
}
}
void objlist_t::set_all_dirty()
{
if( capacity == 0 ) {
// nothing
}
else if( capacity == 1 ) {
obj.one->set_flag( obj_t::dirty );
}
else {
for( uint8 i = 0; i < top; i++ ) {
obj.some[i]->set_flag( obj_t::dirty );
}
}
}
/* check for obj */
bool objlist_t::ist_da(const obj_t* test_obj) const
{
if(capacity<=1) {
return obj.one==test_obj;
}
else {
for(uint8 i=0; i<top; i++) {
if(obj.some[i]==test_obj) {
return true;
}
}
}
return false;
}
obj_t *objlist_t::suche(obj_t::typ typ,uint8 start) const
{
if( start >= top ) {
// start==0 and top==0 is already covered by this too
return NULL;
}
if( capacity <= 1 ) {
// it will crash on capacity==1 and top==0, but this should never happen!
// this is only reached for top==1 and start==0
return obj.one->get_typ()!=typ ? NULL : obj.one;
}
else {
// else we have to search the list
for(uint8 i=start; i<top; i++) {
obj_t * tmp = obj.some[i];
if(tmp->get_typ()==typ) {
return tmp;
}
}
}
return NULL;
}
obj_t *objlist_t::get_leitung() const
{
if( top == 0 ) {
return NULL;
}
if( capacity <= 1 ) {
// it will crash on capacity==1 and top==0, but this should never happen!
if( obj.one->get_typ() >= obj_t::leitung && obj.one->get_typ() <= obj_t::senke ) {
return obj.one;
}
}
else {
// else we have to search the list
for( uint8 i=0; i<top; i++ ) {
uint8 typ = obj.some[i]->get_typ();
if( typ >= obj_t::leitung && typ <= obj_t::senke ) {
return obj.some[i];
}
}
}
return NULL;
}
obj_t *objlist_t::get_convoi_vehicle() const
{
if( top == 0 ) {
return NULL;
}
if( capacity <= 1 ) {
// it will crash on capacity==1 and top==0, but this should never happen!
// only ships and aircraft can go on tiles without ways => only test for those
uint8 t = obj.one->get_typ();
if( t == obj_t::air_vehicle || t == obj_t::water_vehicle ) {
return obj.one;
}
}
else {
for( uint8 i=0; i < top; i++ ) {
uint8 typ = obj.some[i]->get_typ();
if( typ >= obj_t::road_vehicle && typ <= obj_t::air_vehicle ) {
return obj.some[i];
}
}
}
return NULL;
}
void objlist_t::rdwr(loadsave_t *file, koord3d current_pos)
{
if(file->is_loading()) {
sint32 max_object_index;
if( file->is_version_less(110, 1) ) {
file->rdwr_long(max_object_index);
if(max_object_index>254) {
dbg->error("objlist_t::laden()","Too many objects (%i) at (%i,%i), some vehicle may not appear immediately.",max_object_index,current_pos.x,current_pos.y);
}
}
else {
uint8 obj_count;
file->rdwr_byte(obj_count);
max_object_index = -1+(sint32)obj_count;
}
for(sint32 i=0; i<=max_object_index; i++) {
obj_t::typ typ = (obj_t::typ)file->rd_obj_id();
// DBG_DEBUG("objlist_t::laden()", "Thing type %d", typ);
if(typ == -1) {
continue;
}
obj_t *new_obj = NULL;
switch(typ) {
case obj_t::bruecke: new_obj = new bruecke_t(file); break;
case obj_t::tunnel: new_obj = new tunnel_t(file); break;
case obj_t::pumpe: new_obj = new pumpe_t(file); break;
case obj_t::leitung: new_obj = new leitung_t(file); break;
case obj_t::senke: new_obj = new senke_t(file); break;
case obj_t::zeiger: new_obj = new zeiger_t(file); break;
case obj_t::signal: new_obj = new signal_t(file); break;
case obj_t::label: new_obj = new label_t(file); break;
case obj_t::crossing: new_obj = new crossing_t(file); break;
case obj_t::wayobj:
{
wayobj_t* const wo = new wayobj_t(file);
if (wo->get_desc() == NULL) {
// ignore missing wayobjs
wo->set_flag(obj_t::not_on_map);
delete wo;
new_obj = NULL;
}
else {
new_obj = wo;
}
break;
}
// some old offsets will be converted to new ones
case obj_t::old_fussgaenger:
typ = obj_t::pedestrian;
/* FALLTHROUGH */
case obj_t::pedestrian:
{
pedestrian_t* const pedestrian = new pedestrian_t(file);
if (pedestrian->get_desc() == NULL) {
// no pedestrians ... delete this
pedestrian->set_flag(obj_t::not_on_map);
delete pedestrian;
new_obj = NULL;
}
else {
new_obj = pedestrian;
}
break;
}
case obj_t::old_verkehr:
typ = obj_t::road_user;
/* FALLTHROUGH */
case obj_t::road_user:
{
private_car_t* const car = new private_car_t(file);
if (car->get_desc() == NULL) {
// no citycars ... delete this
car->set_flag(obj_t::not_on_map);
delete car;
}
else {
new_obj = car;
}
break;
}
case obj_t::old_monoraildepot:
typ = obj_t::monoraildepot;
/* FALLTHROUGH */
case obj_t::monoraildepot:
new_obj = new monoraildepot_t(file);
break;
case obj_t::old_tramdepot:
typ = obj_t::tramdepot;
/* FALLTHROUGH */
case obj_t::tramdepot:
new_obj = new tramdepot_t(file);
break;
case obj_t::strassendepot:
new_obj = new strassendepot_t(file);
break;
case obj_t::schiffdepot:
new_obj = new schiffdepot_t(file);
break;
case obj_t::old_airdepot:
typ = obj_t::airdepot;
/* FALLTHROUGH */
case obj_t::airdepot:
new_obj = new airdepot_t(file);
break;
case obj_t::maglevdepot:
new_obj = new maglevdepot_t(file);
break;
case obj_t::narrowgaugedepot:
new_obj = new narrowgaugedepot_t(file);
break;
case obj_t::bahndepot:
{
// for compatibility reasons we may have to convert them to tram and monorail depots
bahndepot_t* bd;
gebaeude_t gb(file);
building_tile_desc_t const* const tile = gb.get_tile();
if( tile ) {
switch (tile->get_desc()->get_extra()) {
case monorail_wt: bd = new monoraildepot_t( gb.get_pos(), gb.get_owner(), tile); break;
case tram_wt: bd = new tramdepot_t( gb.get_pos(), gb.get_owner(), tile); break;
default: bd = new bahndepot_t( gb.get_pos(), gb.get_owner(), tile); break;
}
}
else {
bd = new bahndepot_t( gb.get_pos(), gb.get_owner(), NULL );
}
bd->rdwr_vehicles(file);
new_obj = bd;
typ = new_obj->get_typ();
// do not remove from this position, since there will be nothing
gb.set_flag(obj_t::not_on_map);
}
break;
// check for pillars
case obj_t::old_pillar:
typ = obj_t::pillar;
/* FALLTHROUGH */
case obj_t::pillar:
{
pillar_t *p = new pillar_t(file);
if(p->get_desc()!=NULL && p->get_desc()->get_pillar()!=0) {
new_obj = p;
}
else {
// has no pillar ...
// do not remove from this position, since there will be nothing
p->set_flag(obj_t::not_on_map);
delete p;
}
}
break;
case obj_t::baum:
{
baum_t *b = new baum_t(file);
if( !b->get_desc() ) {
// is there a replacement possible
if( const tree_desc_t *desc = baum_t::random_tree_for_climate( world()->get_climate_at_height(current_pos.z) ) ) {
b->set_desc( desc );
}
else {
// do not remove from map on this position, since there will be nothing
b->set_flag(obj_t::not_on_map);
delete b;
b = NULL;
}
}
else {
new_obj = b;
}
}
break;
case obj_t::groundobj:
{
groundobj_t* const groundobj = new groundobj_t(file);
if(groundobj->get_desc() == NULL) {
// do not remove from this position, since there will be nothing
groundobj->set_flag(obj_t::not_on_map);
delete groundobj;
}
else {
new_obj = groundobj;
}
break;
}
case obj_t::movingobj:
{
movingobj_t* const movingobj = new movingobj_t(file);
if (movingobj->get_desc() == NULL) {
// no citycars ... delete this
movingobj->set_flag(obj_t::not_on_map);
delete movingobj;
}
else {
new_obj = movingobj;
}
break;
}
case obj_t::gebaeude:
{
gebaeude_t *gb = new gebaeude_t(file);
if(gb->get_tile()==NULL) {
// do not remove from this position, since there will be nothing
gb->set_flag(obj_t::not_on_map);
delete gb;
gb = NULL;
}
else {
new_obj = gb;
}
}
break;
case obj_t::old_roadsign:
typ = obj_t::roadsign;
/* FALLTHROUGH */
case obj_t::roadsign:
{
roadsign_t *rs = new roadsign_t(file);
if(rs->get_desc()==NULL) {
// roadsign_t without description => ignore
rs->set_flag(obj_t::not_on_map);
delete rs;
}
else {
new_obj = rs;
}
}
break;
// will be ignored, was only used before 86.09
case obj_t::old_gebaeudefundament: { dummy_obj_t d(file); break; }
// only factories can smoke; but then, the smoker is reinstated after loading
case obj_t::raucher: { raucher_t r(file); break; }
// wolke is not saved any more
case obj_t::sync_wolke: { wolke_t w(file); break; }
case obj_t::async_wolke: { async_wolke_t w(file); break; }
default:
dbg->fatal("objlist_t::laden()", "During loading: Unknown object type '%d'", typ);
}