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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
|
/*
* author V. Meyer
*/
#include <stdio.h>
#include "../simdebug.h"
#include "dingliste.h"
#include "../bauer/hausbauer.h"
#include "../dings/dummy.h"
#include "../dings/wolke.h"
#include "../dings/zeiger.h"
#include "../dings/crossing.h"
#include "../dings/baum.h"
#include "../dings/bruecke.h"
#include "../dings/field.h"
#include "../dings/pillar.h"
#include "../dings/tunnel.h"
#include "../dings/gebaeude.h"
#include "../dings/signal.h"
#ifdef LAGER_NOT_IN_USE
#include "../dings/lagerhaus.h"
#endif
#include "../dings/label.h"
#include "../dings/gebaeude.h"
#include "../dings/leitung2.h"
#include "../dings/wayobj.h"
#include "../dings/roadsign.h"
#include "../dings/groundobj.h"
#include "../simtypes.h"
#include "../simdepot.h"
#include "../simmem.h"
#include "../simplay.h"
#include "../vehicle/simvehikel.h"
#include "../vehicle/simverkehr.h"
#include "../vehicle/simpeople.h"
#include "../vehicle/movingobj.h"
#include "../besch/haus_besch.h"
#include "../besch/groundobj_besch.h"
#include "../dataobj/loadsave.h"
#include "../dataobj/freelist.h"
#include "../dataobj/umgebung.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)
// priority for entering into dingliste
// unused entries have 255
static uint8 type_to_pri[32]=
{
255, //
baum_pri, // baum
100, // zeiger
90, 90, 90, // wolke
3, 3, // buildings
6, // signal
2, 2, // bridge/tunnel
255,
1, 1, 1, // depots
5, // smoke generator (not used any more)
75, 4, 4, // powerlines
6, // roadsign
6, // pillar
1, 1, 1, // depots (must be before tunnel!)
255,
7, // 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.
255
};
static void dl_free(ding_t** p, uint8 size)
{
assert(size > 1);
if (size <= 16) {
freelist_t::putback_node(sizeof(*p) * size, p);
} else {
guarded_free(p);
}
}
static ding_t** dl_alloc(uint8 size)
{
assert(size > 1);
ding_t** p;
if (size <= 16) {
p = static_cast<ding_t**>(freelist_t::gimme_node(size * sizeof(*p)));
} else {
p = MALLOCN(ding_t*, size);
}
return p;
}
dingliste_t::dingliste_t()
{
obj.one = NULL;
capacity = 0;
top = 0;
}
dingliste_t::~dingliste_t()
{
if(capacity>1) {
dl_free(obj.some, capacity);
}
obj.some = NULL;
capacity = top = 0;
}
void
dingliste_t::set_capacity(uint8 new_cap)
{
// DBG_MESSAGE("dingliste_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 );
}
capacity = 0;
top = 0;
}
else if(new_cap==1) {
if(capacity>1) {
ding_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);
capacity = 1;
}
else if(capacity==0) {
assert(obj.one && top==0);
}
}
// a single object is stored differentially
else if(capacity<=1 && new_cap>1) {
ding_t *tmp=obj.one;
obj.some = dl_alloc(new_cap);
memset( obj.some, 0, sizeof(ding_t*)*new_cap );
obj.some[0] = tmp;
capacity = new_cap;
assert(top<=1);
}
else {
// if we reach here, new_cap>1 and (capacity==0 or capacity>1)
// ensure, we do not lose anything
// get memory
ding_t **tmp = dl_alloc(new_cap);
// free old memory
if(obj.some) {
memcpy( tmp, obj.some, sizeof(ding_t *)*top );
dl_free(obj.some, capacity);
}
obj.some = tmp;
}
capacity = new_cap;
}
bool dingliste_t::grow_capacity()
{
if(capacity==0) {
return true;
}
else if(capacity==1) {
set_capacity( 4 );
return true;
}
else if(capacity>=240) {
// capacity exceeded ... (and no need for THAT many objects here ... )
return false;
}
else {
// size exeeded, needs to extent
uint8 new_cap = ((uint16)capacity+4)&0x0FC;
set_capacity( new_cap );
return true;
}
}
void
dingliste_t::shrink_capacity(uint8 o_top)
{
// strategy: avoid free'ing mem if not neccesary. Only if we hold lots
// of memory then free it.
if(capacity > 16 && o_top <= 4) {
set_capacity(o_top);
}
}
inline void dingliste_t::intern_insert_at(ding_t* ding, 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] = ding;
top++;
}
// this will automatically give the right order for citycars and the like ...
bool dingliste_t::intern_add_moving(ding_t* ding)
{
// 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 gib_typ()). However, this would increase
// the calculation even further. :(
if(top==0 || obj.some[0]->gib_typ()==ding_t::baum) {
// airplane or movingobj
intern_insert_at( ding, ((vehikel_basis_t*)ding)->gib_waytype()==air_wt ? top : 0 );
return true;
}
// find out about the first car etc. moving thing.
// We can start to insert things after this index.
uint8 start=0;
while(start<top && !obj.some[start]->is_moving()) {
start ++;
}
// if we have two ways, the way at index 0 is ALWAYS the road!
// however ships and planes may be where not way is below ...
if(start!=0 && obj.some[0]->is_way() && ((weg_t *)obj.some[0])->gib_waytype()==road_wt) {
const uint8 fahrtrichtung = ((vehikel_t*)ding)->gib_fahrtrichtung();
// this is very complicated:
// we may have many objects in two lanes (actually five with tram and pedestrians)
if(umgebung_t::drive_on_left) {
// driving on left side
if(fahrtrichtung<4) { // nord, nordwest
if((fahrtrichtung&(~ribi_t::suedost))==0) {
// if we are going east we must be drawn as the first in east direction
intern_insert_at(ding, start);
return true;
}
else {
// we must be drawn before south or west (thus insert after)
for(uint8 i=start; i<top; i++ ) {
if((((const vehikel_t*)obj.some[i])->gib_fahrtrichtung()&ribi_t::suedwest)!=0) {
intern_insert_at(ding, i);
return true;
}
}
// nothing going southwest
obj.some[top++] = ding;
return true;
}
}
else {
// going south, west or the rest
if((fahrtrichtung&(~ribi_t::suedost))==0) {
// if we are going south or southeast we must be drawn as the first in east direction (after nord and nordeast)
for(uint8 i=start; i<top; i++ ) {
const ding_t *dt = obj.some[i];
if(dt && dt->is_moving() && (((const vehikel_t*)dt)->gib_fahrtrichtung()&ribi_t::suedwest)!=0) {
intern_insert_at(ding, i);
return true;
}
}
}
// nothing going southeast
obj.some[top++] = ding;
return true;
}
}
else {
// driving on right side
if(fahrtrichtung<4) { // nord, ost, nordost
if((fahrtrichtung&(~ribi_t::suedost))==0) {
// if we are going east we must be drawn as the first in east direction (after nord and nordeast)
for(uint8 i=start; i<top; i++ ) {
if( (((const vehikel_t*)obj.some[i])->gib_fahrtrichtung()&ribi_t::nordost)!=0) {
intern_insert_at(ding, i);
return true;
}
}
// nothing going to the east
}
// we must be drawn before south or west (thus append after)
obj.some[top++] = ding;
return true;
}
else {
// going south, west or the rest
if((fahrtrichtung&(~ribi_t::suedost))==0) {
// going south or southeast, insert as first in this dirs
intern_insert_at(ding, start);
return true;
}
else {
for(uint8 i=start; i<top; i++ ) {
// west or northwest: append after all westwards
if((((const vehikel_t*)obj.some[i])->gib_fahrtrichtung()&ribi_t::suedwest)==0) {
intern_insert_at(ding, i);
return true;
}
}
// nothing going to nordeast
obj.some[top++] = ding;
return true;
}
}
} // right side/left side
}
else {
// ok, we have to sort vehicles for correct overlapping,
// but all vehicles are of the same typ, since this is track/channel etc. ONLY!
// => much simpler to handle
if((((vehikel_t*)ding)->gib_fahrtrichtung()&(~ribi_t::suedost))==0) {
// if we are going east or south, we must be drawn before (i.e. put first)
intern_insert_at(ding, start);
return true;
}
else {
// for north east we must be draw last
obj.some[top++] = ding;
return true;
}
}
return false;
}
bool dingliste_t::add(ding_t* ding)
{
if(capacity==0) {
// the first one save direct
obj.one = ding;
top = 1;
capacity = 1;
return true;
}
if(top>=capacity && !grow_capacity()) {
// memory exceeded
return false;
}
// vehicles need a special order
if(ding->is_moving()) {
return intern_add_moving(ding);
}
// now insert it a the correct place
uint8 pri=type_to_pri[ding->gib_typ()];
// roads must be first!
if(pri==0) {
// check for other ways to keep order! (maximum is two ways per tile at the moment)
if(top>0 && obj.some[0]->gib_typ()==ding_t::way && ((weg_t *)ding)->gib_waytype()>((weg_t *)obj.some[0])->gib_waytype()) {
intern_insert_at(ding, 1);
} else {
intern_insert_at(ding, 0);
}
return true;
}
uint8 i;
for( i=0; i<top && pri>type_to_pri[obj.some[i]->gib_typ()]; i++ )
;
// now i contains the position, where we either insert of just add ...
if(i==top) {
obj.some[top] = ding;
top++;
}
else {
if(pri==baum_pri) {
/* trees are a little tricky, since they cast a shadow
* therefore the y-order must be correct!
*/
const sint8 offset = ding->gib_yoff() + ding->gib_xoff();
for( ; i<top; i++) {
if(obj.some[i]->gib_typ()!=ding_t::baum || obj.some[i]->gib_yoff()+obj.some[i]->gib_xoff()>offset) {
break;
}
}
intern_insert_at(ding, i);
}
else {
intern_insert_at(ding, i);
}
}
// then correct the upper border
return true;
}
// take the thing out from the list
// use this only for temperary removing
// since it does not shrink list or checks for ownership
ding_t *
dingliste_t::remove_last()
{
ding_t *d=NULL;
if(capacity==0) {
// nothing
}
else if(capacity==1) {
d = obj.one;
obj.one = NULL;
capacity = top = 0;
}
else {
if(top>0) {
top --;
d = obj.some[top];
obj.some[top] = NULL;
}
}
return d;
}
bool dingliste_t::remove(const ding_t* ding)
{
if(capacity==0) {
return false;
} else if(capacity==1) {
if(obj.one==ding) {
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]==ding) {
// found it!
top--;
while(i<top) {
obj.some[i] = obj.some[i+1];
i++;
}
obj.some[top] = NULL;
return true;
}
}
return false;
}
bool
dingliste_t::loesche_alle(spieler_t *sp, uint8 offset)
{
if(top<=offset) {
return false;
}
// something to delete?
bool ok=false;
if(capacity>1) {
while( top>offset ) {
top --;
ding_t *dt = obj.some[top];
if(dt->is_moving() && !(dt->gib_typ()==ding_t::fussgaenger || dt->gib_typ()==ding_t::verkehr || dt->gib_typ()==ding_t::movingobj)) {
((vehikel_t *)dt)->verlasse_feld();
assert(0);
}
else {
dt->entferne(sp);
dt->set_flag(ding_t::not_on_map);
delete dt;
}
obj.some[top] = NULL;
ok = true;
}
}
else {
if(capacity==1) {
ding_t *dt = obj.one;
if(dt->is_moving()) {
((vehikel_t *)dt)->verlasse_feld();
}
else {
dt->entferne(sp);
dt->set_flag(ding_t::not_on_map);
delete dt;
}
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 *
dingliste_t::kann_alle_entfernen(const spieler_t *sp, uint8 offset) const
{
if(top<=offset) {
return NULL;
}
if(capacity==1) {
return obj.one->ist_entfernbar(sp);
}
else {
const char * msg = NULL;
for(uint8 i=offset; i<top; i++) {
msg = obj.some[i]->ist_entfernbar(sp);
if(msg != NULL) {
return msg;
}
}
}
return NULL;
}
/* recalculates all images
*/
void
dingliste_t::calc_bild()
{
if(capacity==0) {
// nothing
}
else if(capacity==1) {
obj.one->calc_bild();
}
else {
for(uint8 i=0; i<top; i++) {
obj.some[i]->calc_bild();
}
}
}
/* check for obj */
bool dingliste_t::ist_da(const ding_t* ding) const
{
if(capacity<=1) {
return obj.one==ding;
}
else {
for(uint8 i=0; i<top; i++) {
if(obj.some[i]==ding) {
return true;
}
}
}
return false;
}
ding_t *
dingliste_t::suche(ding_t::typ typ,uint8 start) const
{
if(capacity==0) {
return NULL;
}
else if(capacity==1) {
return obj.one->gib_typ()!=typ ? NULL : obj.one;
}
else if(start<top) {
// else we have to search the list
for(uint8 i=start; i<top; i++) {
ding_t * tmp = obj.some[i];
if(tmp->gib_typ()==typ) {
return tmp;
}
}
}
return NULL;
}
ding_t *
dingliste_t::get_leitung() const
{
if(capacity==0) {
return NULL;
}
else if(capacity==1) {
if(obj.one->gib_typ()>=ding_t::leitung && obj.one->gib_typ()<=ding_t::senke) {
return obj.one;
}
}
else if(top>0) {
// else we have to search the list
for(uint8 i=0; i<top; i++) {
uint8 typ = obj.some[i]->gib_typ();
if(typ>=ding_t::leitung && typ<=ding_t::senke) {
return obj.some[i];
}
}
}
return NULL;
}
void
dingliste_t::rdwr(karte_t *welt, loadsave_t *file, koord3d current_pos)
{
sint32 max_object_index;
if(file->is_saving()) {
max_object_index = top-1;
}
file->rdwr_long(max_object_index, "\n");
if(max_object_index>254) {
dbg->error("dingliste_t::laden()","Too many objects (%i) at (%i,%i), some vehicle may not appear immediately.",max_object_index,current_pos.x,current_pos.y);
}
for(sint32 i=0; i<=max_object_index; i++) {
if(file->is_loading()) {
ding_t::typ typ = (ding_t::typ)file->rd_obj_id();
// DBG_DEBUG("dingliste_t::laden()", "Thing type %d", typ);
if(typ == -1) {
continue;
}
ding_t *d = NULL;
switch(typ) {
case ding_t::bruecke: d = new bruecke_t (welt, file); break;
case ding_t::tunnel: d = new tunnel_t (welt, file); break;
case ding_t::pumpe: d = new pumpe_t (welt, file); break;
case ding_t::leitung: d = new leitung_t (welt, file); break;
case ding_t::senke: d = new senke_t (welt, file); break;
case ding_t::zeiger: d = new zeiger_t (welt, file); break;
case ding_t::signal: d = new signal_t (welt, file); break;
case ding_t::label: d = new label_t(welt,file); break;
case ding_t::crossing: d = new crossing_t(welt,file); break;
case ding_t::wayobj:
{
wayobj_t* const wo = new wayobj_t(welt, file);
if (wo->gib_besch() == NULL) {
// ignore missing wayobjs
wo->set_flag(ding_t::not_on_map);
delete wo;
d = NULL;
} else {
d = wo;
}
break;
}
// some old offsets will be converted to new ones
case ding_t::old_fussgaenger:
typ = ding_t::fussgaenger;
case ding_t::fussgaenger:
{
fussgaenger_t* const pedestrian = new fussgaenger_t(welt, file);
if (pedestrian->gib_besch() == NULL) {
// no pedestrians ... delete this
pedestrian->set_flag(ding_t::not_on_map);
delete pedestrian;
d = NULL;
} else {
d = pedestrian;
}
break;
}
case ding_t::old_verkehr:
typ = ding_t::verkehr;
case ding_t::verkehr:
{
stadtauto_t* const car = new stadtauto_t(welt, file);
if (car->gib_besch() == NULL) {
// no citycars ... delete this
car->set_flag(ding_t::not_on_map);
delete car;
d = NULL;
} else {
d = car;
}
break;
}
case ding_t::old_monoraildepot:
typ = ding_t::monoraildepot;
case ding_t::monoraildepot:
d = new monoraildepot_t (welt, file);
break;
case ding_t::old_tramdepot:
typ = ding_t::tramdepot;
case ding_t::tramdepot:
d = new tramdepot_t (welt, file);
break;
case ding_t::strassendepot:
d = new strassendepot_t (welt, file);
break;
case ding_t::schiffdepot:
d = new schiffdepot_t (welt, file);
break;
case ding_t::old_airdepot:
typ = ding_t::airdepot;
case ding_t::airdepot:
d = new airdepot_t (welt, file);
break;
case ding_t::bahndepot:
{
// for compatibilty reasons we may have to convert them to tram and monorail depots
gebaeude_t *gb = new gebaeude_t(welt, file);
if(gb->gib_tile()->gib_besch()->gib_extra()==monorail_wt) {
monoraildepot_t *md = new monoraildepot_t(welt,gb->gib_pos(),(spieler_t *)NULL,gb->gib_tile());
md->rdwr_vehicles(file);
d = md;
}
else if(gb->gib_tile()->gib_besch()->gib_extra()==tram_wt) {
tramdepot_t *td = new tramdepot_t(welt,gb->gib_pos(),(spieler_t *)NULL,gb->gib_tile());
td->rdwr_vehicles(file);
d = td;
}
else {
bahndepot_t *bd = new bahndepot_t(welt,gb->gib_pos(),(spieler_t *)NULL,gb->gib_tile());
bd->rdwr_vehicles(file);
d = bd;
}
d->setze_besitzer( gb->gib_besitzer() );
spieler_t::add_maintenance( gb->gib_besitzer(), umgebung_t::maint_building);
typ = d->gib_typ();
// do not remove from this position, since there will be nothing
gb->set_flag(ding_t::not_on_map);
delete gb;
}
break;
// check for pillars
case ding_t::old_pillar:
typ = ding_t::pillar;
case ding_t::pillar:
{
pillar_t *p = new pillar_t(welt, file);
if(p->gib_besch()!=NULL && p->gib_besch()->gib_pillar()!=0) {
d = p;
}
else {
// has no pillar ...
// do not remove from this position, since there will be nothing
p->set_flag(ding_t::not_on_map);
delete p;
}
}
break;
case ding_t::baum:
{
baum_t *b = new baum_t(welt, file);
if(!b->gib_besch()) {
// do not remove from this position, since there will be nothing
b->set_flag(ding_t::not_on_map);
delete b;
}
d = b;
}
break;
case ding_t::groundobj:
{
groundobj_t* const groundobj = new groundobj_t(welt, file);
if (groundobj->gib_besch() == NULL) {
// do not remove from this position, since there will be nothing
groundobj->set_flag(ding_t::not_on_map);
// not use entferne, since it would try to lookup besch
delete groundobj;
d = NULL;
} else {
d = groundobj;
}
break;
}
case ding_t::movingobj:
{
movingobj_t* const movingobj = new movingobj_t(welt, file);
if (movingobj->gib_besch() == NULL) {
// no citycars ... delete this
movingobj->set_flag(ding_t::not_on_map);
delete movingobj;
d = NULL;
} else {
d = movingobj;
}
break;
}
case ding_t::gebaeude:
{
// Wenn es ein Gebude nicht mehr gibt, genderte Tabfiles
// lassen wir es einfach weg. Das gibt zwar Fundamente ohne
// Aufbau, strzt aber nicht ab.
gebaeude_t *gb = new gebaeude_t (welt, file);
if(gb->gib_tile()==NULL) {
// do not remove from this position, since there will be nothing
gb->set_flag(ding_t::not_on_map);
delete gb;
gb = 0;
}
d = gb;
}
break;
case ding_t::old_roadsign:
typ = ding_t::roadsign;
case ding_t::roadsign:
{
roadsign_t *rs = new roadsign_t (welt, file);
if(rs->gib_besch()==NULL) {
// roadsign_t without description => ignore
rs->set_flag(ding_t::not_on_map);
delete rs;
}
else {
d = rs;
}
}
break;
// will be ignored, was only used before 86.09
case ding_t::old_gebaeudefundament: { dummy_ding_t(welt, file); break; }
// only factories can smoke; but then, the smoker is reinstated after loading
case ding_t::raucher: { raucher_t(welt, file); break; }
// wolke is not saved anymore
case ding_t::sync_wolke: { wolke_t(welt, file); break; }
case ding_t::async_wolke: { async_wolke_t(welt, file); break; }
default:
dbg->fatal("dingliste_t::laden()", "During loading: Unknown object type '%d'", typ);
}
if(d && d->gib_typ()!=typ) {
dbg->warning( "dingliste_t::rdwr()","typ error : %i instead %i on %i,%i, object ignored!", d->gib_typ(), typ, d->gib_pos().x, d->gib_pos().y );
d = NULL;
}
if(d && d->gib_pos()!=current_pos) {
dbg->warning("dingliste_t::rdwr()","position error: %i,%i,%i instead %i,%i,%i (object will be ignored)",d->gib_pos().x,d->gib_pos().y,d->gib_pos().z,current_pos.x,current_pos.y,current_pos.z);
d = NULL;
}
if(d) {
add(d);
}
}
else {
// here is the saving part ...
ding_t *d=bei(i);
assert(d);
if(d->is_way() || d->gib_typ()==ding_t::raucher || d->gib_typ()==ding_t::sync_wolke || d->gib_typ()==ding_t::async_wolke || d->gib_typ()==ding_t::field) {
// these objects are simply not saved
file->wr_obj_id(-1);
}
else {
if(d->gib_pos()==current_pos) {
bei(i)->rdwr(file);
}
else if(bei(i)->gib_pos().gib_2d()==current_pos.gib_2d()) {
// ok, just error in z direction => we will correct it
dbg->warning( "dingliste_t::rdwr()","position error: z pos corrected on %i,%i from %i to %i",bei(i)->gib_pos().x,bei(i)->gib_pos().y,bei(i)->gib_pos().z,current_pos.z);
bei(i)->setze_pos( current_pos );
bei(i)->rdwr(file);
}
else {
dbg->error( "dingliste_t::rdwr()","unresolvable position error: %i,%i instead %i,%i (object type %i will be not saved!)", bei(i)->gib_pos().x, bei(i)->gib_pos().y, current_pos.x, current_pos.y, bei(i)->gib_typ() );
file->wr_obj_id(-1);
}
}
}
}
}
/* Dumps a short info about the things on this tile
* @author prissi
*/
void dingliste_t::dump() const
{
if(capacity==0) {
// DBG_MESSAGE("dingliste_t::dump()","empty");
return;
}
else if(capacity==1) {
DBG_MESSAGE("dingliste_t::dump()","one object \'%s\' owned by sp %p", obj.one->gib_name(), obj.one->gib_besitzer() );
return;
}
DBG_MESSAGE("dingliste_t::dump()","%i objects", top );
for(uint8 n=0; n<top; n++) {
DBG_MESSAGE( obj.some[n]->gib_name(), "at %i owned by sp %p", n, obj.some[n]->gib_besitzer() );
}
}
/* display all things, much faster to do it here ...
* reset_dirty will be only true for the main display; all miniworld windows should still reset main window ...
* @author prissi
*/
void dingliste_t::display_dinge( const sint16 xpos, const sint16 ypos, const uint8 start_offset, const bool reset_dirty ) const
{
if(capacity==0) {
return;
}
else if(capacity==1) {
if(start_offset==0) {
obj.one->display(xpos, ypos, reset_dirty );
obj.one->display_after(xpos, ypos, reset_dirty );
if(reset_dirty) {
obj.one->clear_flag(ding_t::dirty);
}
}
return;
}
for(uint8 n=start_offset; n<top; n++) {
// ist dort ein objekt ?
obj.some[n]->display(xpos, ypos, reset_dirty );
}
// foreground (needs to be done backwards!
for(int n=top-1; n>=0; n--) {
obj.some[n]->display_after(xpos, ypos, reset_dirty );
obj.some[n]->clear_flag(ding_t::dirty);
}
}
// start next month (good for toogling a seasons)
void
dingliste_t::check_season(const long month)
{
slist_tpl<ding_t *>loeschen;
if(capacity==0) {
return;
}
else if(capacity==1) {
ding_t *d = obj.one;
if (!d->check_season(month)) {
loeschen.insert( d );
}
}
else {
for(uint8 i=0; i<top; i++) {
ding_t *d = obj.some[i];
if (!d->check_season(month)) {
loeschen.insert( d );
}
}
}
// delete all objects, which do not want to step anymore
while (!loeschen.empty()) {
delete loeschen.remove_first();
}
}
|