comparison src/station_cmd.cpp @ 7795:f49ffccacf58 draft

(svn r11345) -Cleanup: a bit of comment style fixing
author belugas <belugas@openttd.org>
date Fri, 26 Oct 2007 20:42:03 +0000
parents 013f54f32e5e
children abee2c8e51ed
comparison
equal deleted inserted replaced
7794:719f4c7173ae 7795:f49ffccacf58
90 90
91 return num; 91 return num;
92 } 92 }
93 93
94 94
95 /* Calculate the radius of the station. Basicly it is the biggest 95 /** Calculate the radius of the station. Basicly it is the biggest
96 * radius that is available within the station */ 96 * radius that is available within the station
97 * @param st Station to query
98 * @return the so calculated radius
99 */
97 static uint FindCatchmentRadius(const Station* st) 100 static uint FindCatchmentRadius(const Station* st)
98 { 101 {
99 uint ret = CA_NONE; 102 uint ret = CA_NONE;
100 103
101 if (st->bus_stops != NULL) ret = max<uint>(ret, CA_BUS); 104 if (st->bus_stops != NULL) ret = max<uint>(ret, CA_BUS);
350 } 353 }
351 354
352 return best_station; 355 return best_station;
353 } 356 }
354 357
355 // Update the virtual coords needed to draw the station sign. 358 /** Update the virtual coords needed to draw the station sign.
356 // st = Station to update for. 359 * @param st Station to update for.
360 */
357 static void UpdateStationVirtCoord(Station *st) 361 static void UpdateStationVirtCoord(Station *st)
358 { 362 {
359 Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE); 363 Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
360 364
361 pt.y -= 32; 365 pt.y -= 32;
364 SetDParam(0, st->index); 368 SetDParam(0, st->index);
365 SetDParam(1, st->facilities); 369 SetDParam(1, st->facilities);
366 UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); 370 UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0);
367 } 371 }
368 372
369 // Update the virtual coords needed to draw the station sign for all stations. 373 /** Update the virtual coords needed to draw the station sign for all stations. */
370 void UpdateAllStationVirtCoord() 374 void UpdateAllStationVirtCoord()
371 { 375 {
372 Station* st; 376 Station* st;
373 377
374 FOR_ALL_STATIONS(st) { 378 FOR_ALL_STATIONS(st) {
389 st->MarkDirty(); 393 st->MarkDirty();
390 UpdateStationVirtCoord(st); 394 UpdateStationVirtCoord(st);
391 st->MarkDirty(); 395 st->MarkDirty();
392 } 396 }
393 397
394 // Get a mask of the cargo types that the station accepts. 398 /** Get a mask of the cargo types that the station accepts.
399 * @param st Station to query
400 * @return the expected mask
401 */
395 static uint GetAcceptanceMask(const Station *st) 402 static uint GetAcceptanceMask(const Station *st)
396 { 403 {
397 uint mask = 0; 404 uint mask = 0;
398 405
399 for (CargoID i = 0; i < NUM_CARGO; i++) { 406 for (CargoID i = 0; i < NUM_CARGO; i++) {
400 if (HASBIT(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) mask |= 1 << i; 407 if (HASBIT(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) mask |= 1 << i;
401 } 408 }
402 return mask; 409 return mask;
403 } 410 }
404 411
405 // Items contains the two cargo names that are to be accepted or rejected. 412 /** Items contains the two cargo names that are to be accepted or rejected.
406 // msg is the string id of the message to display. 413 * msg is the string id of the message to display.
414 */
407 static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg) 415 static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
408 { 416 {
409 for (uint i = 0; i < num_items; i++) { 417 for (uint i = 0; i < num_items; i++) {
410 SetDParam(i + 1, GetCargo(cargo[i])->name); 418 SetDParam(i + 1, GetCargo(cargo[i])->name);
411 } 419 }
412 420
413 SetDParam(0, st->index); 421 SetDParam(0, st->index);
414 AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); 422 AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0);
415 } 423 }
416 424
417 // Get a list of the cargo types being produced around the tile. 425 /** Get a list of the cargo types being produced around the tile.*/
418 void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, 426 void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
419 int w, int h, int rad) 427 int w, int h, int rad)
420 { 428 {
421 memset(produced, 0, sizeof(AcceptedCargo)); 429 memset(produced, 0, sizeof(AcceptedCargo));
422 430
423 int x = TileX(tile); 431 int x = TileX(tile);
424 int y = TileY(tile); 432 int y = TileY(tile);
425 433
426 // expand the region by rad tiles on each side 434 /* expand the region by rad tiles on each side
427 // while making sure that we remain inside the board. 435 * while making sure that we remain inside the board. */
428 int x2 = min(x + w + rad, MapSizeX()); 436 int x2 = min(x + w + rad, MapSizeX());
429 int x1 = max(x - rad, 0); 437 int x1 = max(x - rad, 0);
430 438
431 int y2 = min(y + h + rad, MapSizeY()); 439 int y2 = min(y + h + rad, MapSizeY());
432 int y1 = max(y - rad, 0); 440 int y1 = max(y - rad, 0);
456 } 464 }
457 } 465 }
458 } 466 }
459 } 467 }
460 468
461 // Get a list of the cargo types that are accepted around the tile. 469 /** Get a list of the cargo types that are accepted around the tile.*/
462 void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, 470 void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
463 int w, int h, int rad) 471 int w, int h, int rad)
464 { 472 {
465 memset(accepts, 0, sizeof(AcceptedCargo)); 473 memset(accepts, 0, sizeof(AcceptedCargo));
466 474
467 int x = TileX(tile); 475 int x = TileX(tile);
468 int y = TileY(tile); 476 int y = TileY(tile);
469 477
470 // expand the region by rad tiles on each side 478 /* expand the region by rad tiles on each side
471 // while making sure that we remain inside the board. 479 * while making sure that we remain inside the board. */
472 int x2 = min(x + w + rad, MapSizeX()); 480 int x2 = min(x + w + rad, MapSizeX());
473 int y2 = min(y + h + rad, MapSizeY()); 481 int y2 = min(y + h + rad, MapSizeY());
474 int x1 = max(x - rad, 0); 482 int x1 = max(x - rad, 0);
475 int y1 = max(y - rad, 0); 483 int y1 = max(y - rad, 0);
476 484
509 if (rect->min_y > y) rect->min_y = y; 517 if (rect->min_y > y) rect->min_y = y;
510 if (rect->max_x < x) rect->max_x = x; 518 if (rect->max_x < x) rect->max_x = x;
511 if (rect->max_y < y) rect->max_y = y; 519 if (rect->max_y < y) rect->max_y = y;
512 } 520 }
513 521
514 // Update the acceptance for a station. 522 /** Update the acceptance for a station.
515 // show_msg controls whether to display a message that acceptance was changed. 523 * @param st Station to update
524 * @param show_msg controls whether to display a message that acceptance was changed.
525 */
516 static void UpdateStationAcceptance(Station *st, bool show_msg) 526 static void UpdateStationAcceptance(Station *st, bool show_msg)
517 { 527 {
518 // Don't update acceptance for a buoy 528 /* Don't update acceptance for a buoy */
519 if (st->IsBuoy()) return; 529 if (st->IsBuoy()) return;
520 530
521 ottd_Rectangle rect; 531 ottd_Rectangle rect;
522 rect.min_x = MapSizeX(); 532 rect.min_x = MapSizeX();
523 rect.min_y = MapSizeY(); 533 rect.min_y = MapSizeY();
525 rect.max_y = 0; 535 rect.max_y = 0;
526 536
527 /* old accepted goods types */ 537 /* old accepted goods types */
528 uint old_acc = GetAcceptanceMask(st); 538 uint old_acc = GetAcceptanceMask(st);
529 539
530 // Put all the tiles that span an area in the table. 540 /* Put all the tiles that span an area in the table. */
531 if (st->train_tile != 0) { 541 if (st->train_tile != 0) {
532 MergePoint(&rect, st->train_tile); 542 MergePoint(&rect, st->train_tile);
533 MergePoint(&rect, 543 MergePoint(&rect,
534 st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1) 544 st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
535 ); 545 );
552 562
553 for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) { 563 for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) {
554 MergePoint(&rect, rs->xy); 564 MergePoint(&rect, rs->xy);
555 } 565 }
556 566
557 // And retrieve the acceptance. 567 /* And retrieve the acceptance. */
558 AcceptedCargo accepts; 568 AcceptedCargo accepts;
559 if (rect.max_x >= rect.min_x) { 569 if (rect.max_x >= rect.min_x) {
560 GetAcceptanceAroundTiles( 570 GetAcceptanceAroundTiles(
561 accepts, 571 accepts,
562 TileXY(rect.min_x, rect.min_y), 572 TileXY(rect.min_x, rect.min_y),
566 ); 576 );
567 } else { 577 } else {
568 memset(accepts, 0, sizeof(accepts)); 578 memset(accepts, 0, sizeof(accepts));
569 } 579 }
570 580
571 // Adjust in case our station only accepts fewer kinds of goods 581 /* Adjust in case our station only accepts fewer kinds of goods */
572 for (CargoID i = 0; i < NUM_CARGO; i++) { 582 for (CargoID i = 0; i < NUM_CARGO; i++) {
573 uint amt = min(accepts[i], 15); 583 uint amt = min(accepts[i], 15);
574 584
575 // Make sure the station can accept the goods type. 585 /* Make sure the station can accept the goods type. */
576 bool is_passengers = IsCargoInClass(i, CC_PASSENGERS); 586 bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
577 if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) || 587 if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
578 (is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) 588 (is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
579 amt = 0; 589 amt = 0;
580 590
581 SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8); 591 SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8);
582 } 592 }
583 593
584 // Only show a message in case the acceptance was actually changed. 594 /* Only show a message in case the acceptance was actually changed. */
585 uint new_acc = GetAcceptanceMask(st); 595 uint new_acc = GetAcceptanceMask(st);
586 if (old_acc == new_acc) 596 if (old_acc == new_acc)
587 return; 597 return;
588 598
589 // show a message to report that the acceptance was changed? 599 /* show a message to report that the acceptance was changed? */
590 if (show_msg && st->owner == _local_player && st->facilities) { 600 if (show_msg && st->owner == _local_player && st->facilities) {
591 /* List of accept and reject strings for different number of 601 /* List of accept and reject strings for different number of
592 * cargo types */ 602 * cargo types */
593 static const StringID accept_msg[] = { 603 static const StringID accept_msg[] = {
594 STR_3040_NOW_ACCEPTS, 604 STR_3040_NOW_ACCEPTS,
623 /* Show news message if there are any changes */ 633 /* Show news message if there are any changes */
624 if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]); 634 if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]);
625 if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]); 635 if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]);
626 } 636 }
627 637
628 // redraw the station view since acceptance changed 638 /* redraw the station view since acceptance changed */
629 InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4); 639 InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4);
630 } 640 }
631 641
632 static void UpdateStationSignCoord(Station *st) 642 static void UpdateStationSignCoord(Station *st)
633 { 643 {
634 const StationRect *r = &st->rect; 644 const StationRect *r = &st->rect;
635 645
636 if (r->IsEmpty()) return; // no tiles belong to this station 646 if (r->IsEmpty()) return; /* no tiles belong to this station */
637 647
638 // clamp sign coord to be inside the station rect 648 /* clamp sign coord to be inside the station rect */
639 st->xy = TileXY(clampu(TileX(st->xy), r->left, r->right), clampu(TileY(st->xy), r->top, r->bottom)); 649 st->xy = TileXY(clampu(TileX(st->xy), r->left, r->right), clampu(TileY(st->xy), r->top, r->bottom));
640 UpdateStationVirtCoordDirty(st); 650 UpdateStationVirtCoordDirty(st);
641 } 651 }
642 652
643 // This is called right after a station was deleted. 653 /** This is called right after a station was deleted.
644 // It checks if the whole station is free of substations, and if so, the station will be 654 * It checks if the whole station is free of substations, and if so, the station will be
645 // deleted after a little while. 655 * deleted after a little while.
646 static void DeleteStationIfEmpty(Station* st) 656 * @param st Station
657 */
658 static void DeleteStationIfEmpty(Station *st)
647 { 659 {
648 if (st->facilities == 0) { 660 if (st->facilities == 0) {
649 st->delete_ctr = 0; 661 st->delete_ctr = 0;
650 RebuildStationLists(); 662 RebuildStationLists();
651 InvalidateWindow(WC_STATION_LIST, st->owner); 663 InvalidateWindow(WC_STATION_LIST, st->owner);
654 UpdateStationSignCoord(st); 666 UpdateStationSignCoord(st);
655 } 667 }
656 668
657 static CommandCost ClearTile_Station(TileIndex tile, byte flags); 669 static CommandCost ClearTile_Station(TileIndex tile, byte flags);
658 670
659 // Tries to clear the given area. Returns the cost in case of success. 671 /** Tries to clear the given area.
660 // Or an error code if it failed. 672 * @param tile TileIndex to start check
661 CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true) 673 * @param w width of search area
674 * @param h height of search area
675 * @param flags operation to perform
676 * @param invalid_dirs prohibited directions
677 * @param station StationID to be queried and returned if available
678 * @param check_clear if clearing tile should be performed (in wich case, cost will be added)
679 * @return the cost in case of success, or an error code if it failed.
680 */
681 CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID *station, bool check_clear = true)
662 { 682 {
663 CommandCost cost; 683 CommandCost cost;
664 int allowed_z = -1; 684 int allowed_z = -1;
665 685
666 BEGIN_TILE_LOOP(tile_cur, w, h, tile) { 686 BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
686 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); 706 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
687 } 707 }
688 708
689 int flat_z = z; 709 int flat_z = z;
690 if (tileh != SLOPE_FLAT) { 710 if (tileh != SLOPE_FLAT) {
691 // need to check so the entrance to the station is not pointing at a slope. 711 /* need to check so the entrance to the station is not pointing at a slope. */
692 if ((invalid_dirs & 1 && !(tileh & SLOPE_NE) && (uint)w_cur == w) || 712 if ((invalid_dirs & 1 && !(tileh & SLOPE_NE) && (uint)w_cur == w) ||
693 (invalid_dirs & 2 && !(tileh & SLOPE_SE) && h_cur == 1) || 713 (invalid_dirs & 2 && !(tileh & SLOPE_SE) && h_cur == 1) ||
694 (invalid_dirs & 4 && !(tileh & SLOPE_SW) && w_cur == 1) || 714 (invalid_dirs & 4 && !(tileh & SLOPE_SW) && w_cur == 1) ||
695 (invalid_dirs & 8 && !(tileh & SLOPE_NW) && (uint)h_cur == h)) { 715 (invalid_dirs & 8 && !(tileh & SLOPE_NW) && (uint)h_cur == h)) {
696 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); 716 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
697 } 717 }
698 cost.AddCost(_price.terraform); 718 cost.AddCost(_price.terraform);
699 flat_z += TILE_HEIGHT; 719 flat_z += TILE_HEIGHT;
700 } 720 }
701 721
702 // get corresponding flat level and make sure that all parts of the station have the same level. 722 /* get corresponding flat level and make sure that all parts of the station have the same level. */
703 if (allowed_z == -1) { 723 if (allowed_z == -1) {
704 // first tile 724 /* first tile */
705 allowed_z = flat_z; 725 allowed_z = flat_z;
706 } else if (allowed_z != flat_z) { 726 } else if (allowed_z != flat_z) {
707 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); 727 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
708 } 728 }
709 729
710 // if station is set, then we have special handling to allow building on top of already existing stations. 730 /* if station is set, then we have special handling to allow building on top of already existing stations.
711 // so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build 731 * so station points to INVALID_STATION if we can build on any station.
712 // on exactly that station. 732 * Or it points to a station if we're only allowed to build on exactly that station. */
713 if (station != NULL && IsTileType(tile_cur, MP_STATION)) { 733 if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
714 if (!IsRailwayStation(tile_cur)) { 734 if (!IsRailwayStation(tile_cur)) {
715 return ClearTile_Station(tile_cur, DC_AUTO); // get error message 735 return ClearTile_Station(tile_cur, DC_AUTO); // get error message
716 } else { 736 } else {
717 StationID st = GetStationIndex(tile_cur); 737 StationID st = GetStationIndex(tile_cur);
738 TileIndex tile = fin[0]; 758 TileIndex tile = fin[0];
739 uint w = fin[1]; 759 uint w = fin[1];
740 uint h = fin[2]; 760 uint h = fin[2];
741 761
742 if (_patches.nonuniform_stations) { 762 if (_patches.nonuniform_stations) {
743 // determine new size of train station region.. 763 /* determine new size of train station region.. */
744 int x = min(TileX(st->train_tile), TileX(tile)); 764 int x = min(TileX(st->train_tile), TileX(tile));
745 int y = min(TileY(st->train_tile), TileY(tile)); 765 int y = min(TileY(st->train_tile), TileY(tile));
746 curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x; 766 curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
747 curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y; 767 curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
748 tile = TileXY(x, y); 768 tile = TileXY(x, y);
749 } else { 769 } else {
750 // check so the orientation is the same 770 /* check so the orientation is the same */
751 if (GetRailStationAxis(st->train_tile) != axis) { 771 if (GetRailStationAxis(st->train_tile) != axis) {
752 _error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; 772 _error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
753 return false; 773 return false;
754 } 774 }
755 775
756 // check if the new station adjoins the old station in either direction 776 /* check if the new station adjoins the old station in either direction */
757 if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) { 777 if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
758 // above 778 /* above */
759 curh += h; 779 curh += h;
760 } else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) { 780 } else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
761 // below 781 /* below */
762 tile -= TileDiffXY(0, curh); 782 tile -= TileDiffXY(0, curh);
763 curh += h; 783 curh += h;
764 } else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) { 784 } else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
765 // to the left 785 /* to the left */
766 curw += w; 786 curw += w;
767 } else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) { 787 } else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
768 // to the right 788 /* to the right */
769 tile -= TileDiffXY(curw, 0); 789 tile -= TileDiffXY(curw, 0);
770 curw += w; 790 curw += w;
771 } else { 791 } else {
772 _error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; 792 _error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
773 return false; 793 return false;
774 } 794 }
775 } 795 }
776 // make sure the final size is not too big. 796 /* make sure the final size is not too big. */
777 if (curw > _patches.station_spread || curh > _patches.station_spread) { 797 if (curw > _patches.station_spread || curh > _patches.station_spread) {
778 _error_message = STR_306C_STATION_TOO_SPREAD_OUT; 798 _error_message = STR_306C_STATION_TOO_SPREAD_OUT;
779 return false; 799 return false;
780 } 800 }
781 801
782 // now tile contains the new value for st->train_tile 802 /* now tile contains the new value for st->train_tile
783 // curw, curh contain the new value for width and height 803 * curw, curh contain the new value for width and height */
784 fin[0] = tile; 804 fin[0] = tile;
785 fin[1] = curw; 805 fin[1] = curw;
786 fin[2] = curh; 806 fin[2] = curh;
787 return true; 807 return true;
788 } 808 }
866 w_org = numtracks; 886 w_org = numtracks;
867 } 887 }
868 888
869 if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR; 889 if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR;
870 890
871 // these values are those that will be stored in train_tile and station_platforms 891 /* these values are those that will be stored in train_tile and station_platforms */
872 uint finalvalues[3]; 892 uint finalvalues[3];
873 finalvalues[0] = tile_org; 893 finalvalues[0] = tile_org;
874 finalvalues[1] = w_org; 894 finalvalues[1] = w_org;
875 finalvalues[2] = h_org; 895 finalvalues[2] = h_org;
876 896
877 // Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) 897 /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
878 StationID est = INVALID_STATION; 898 StationID est = INVALID_STATION;
879 // If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug 899 /* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
880 // for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 900 * for detail info, see:
901 * https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
881 ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL); 902 ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
882 if (CmdFailed(ret)) return ret; 903 if (CmdFailed(ret)) return ret;
883 CommandCost cost(ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len); 904 CommandCost cost(ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len);
884 905
885 Station *st = NULL; 906 Station *st = NULL;
903 if (HASBIT(p1, 24)) check_surrounding = false; 924 if (HASBIT(p1, 24)) check_surrounding = false;
904 } 925 }
905 } 926 }
906 927
907 if (check_surrounding) { 928 if (check_surrounding) {
908 // Make sure there are no similar stations around us. 929 /* Make sure there are no similar stations around us. */
909 st = GetStationAround(tile_org, w_org, h_org, est); 930 st = GetStationAround(tile_org, w_org, h_org, est);
910 if (st == CHECK_STATIONS_ERR) return CMD_ERROR; 931 if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
911 } 932 }
912 933
913 // See if there is a deleted station close to us. 934 /* See if there is a deleted station close to us. */
914 if (st == NULL) st = GetClosestStationFromTile(tile_org); 935 if (st == NULL) st = GetClosestStationFromTile(tile_org);
915 936
916 /* In case of new station if DC_EXEC is NOT set we still need to create the station 937 /* In case of new station if DC_EXEC is NOT set we still need to create the station
917 * to test if everything is OK. In this case we need to delete it before return. */ 938 * to test if everything is OK. In this case we need to delete it before return. */
918 AutoPtrT<Station> st_auto_delete; 939 AutoPtrT<Station> st_auto_delete;
919 940
920 if (st != NULL) { 941 if (st != NULL) {
921 // Reuse an existing station. 942 /* Reuse an existing station. */
922 if (st->owner != _current_player) 943 if (st->owner != _current_player)
923 return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); 944 return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
924 945
925 if (st->train_tile != 0) { 946 if (st->train_tile != 0) {
926 // check if we want to expanding an already existing station? 947 /* check if we want to expanding an already existing station? */
927 if (_is_old_ai_player || !_patches.join_stations) 948 if (_is_old_ai_player || !_patches.join_stations)
928 return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD); 949 return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
929 if (!CanExpandRailroadStation(st, finalvalues, axis)) 950 if (!CanExpandRailroadStation(st, finalvalues, axis))
930 return CMD_ERROR; 951 return CMD_ERROR;
931 } 952 }
932 953
933 //XXX can't we pack this in the "else" part of the if above? 954 /* XXX can't we pack this in the "else" part of the if above? */
934 if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR; 955 if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR;
935 } else { 956 } else {
936 /* allocate and initialize new station */ 957 /* allocate and initialize new station */
937 st = new Station(tile_org); 958 st = new Station(tile_org);
938 if (st == NULL) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING); 959 if (st == NULL) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
974 TileIndexDiff tile_delta; 995 TileIndexDiff tile_delta;
975 byte *layout_ptr; 996 byte *layout_ptr;
976 byte numtracks_orig; 997 byte numtracks_orig;
977 Track track; 998 Track track;
978 999
979 // Now really clear the land below the station 1000 /* Now really clear the land below the station
980 // It should never return CMD_ERROR.. but you never know ;) 1001 * It should never return CMD_ERROR.. but you never know ;)
981 // (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) 1002 * (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */
982 ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _patches.nonuniform_stations ? &est : NULL); 1003 ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
983 if (CmdFailed(ret)) return ret; 1004 if (CmdFailed(ret)) return ret;
984 1005
985 st->train_tile = finalvalues[0]; 1006 st->train_tile = finalvalues[0];
986 st->AddFacility(FACIL_TRAIN, finalvalues[0]); 1007 st->AddFacility(FACIL_TRAIN, finalvalues[0]);
1039 uint h = st->trainst_h; 1060 uint h = st->trainst_h;
1040 TileIndex tile = st->train_tile; 1061 TileIndex tile = st->train_tile;
1041 1062
1042 restart: 1063 restart:
1043 1064
1044 // too small? 1065 /* too small? */
1045 if (w != 0 && h != 0) { 1066 if (w != 0 && h != 0) {
1046 // check the left side, x = constant, y changes 1067 /* check the left side, x = constant, y changes */
1047 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) { 1068 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) {
1048 // the left side is unused? 1069 /* the left side is unused? */
1049 if (++i == h) { 1070 if (++i == h) {
1050 tile += TileDiffXY(1, 0); 1071 tile += TileDiffXY(1, 0);
1051 w--; 1072 w--;
1052 goto restart; 1073 goto restart;
1053 } 1074 }
1054 } 1075 }
1055 1076
1056 // check the right side, x = constant, y changes 1077 /* check the right side, x = constant, y changes */
1057 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) { 1078 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) {
1058 // the right side is unused? 1079 /* the right side is unused? */
1059 if (++i == h) { 1080 if (++i == h) {
1060 w--; 1081 w--;
1061 goto restart; 1082 goto restart;
1062 } 1083 }
1063 } 1084 }
1064 1085
1065 // check the upper side, y = constant, x changes 1086 /* check the upper side, y = constant, x changes */
1066 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) { 1087 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) {
1067 // the left side is unused? 1088 /* the left side is unused? */
1068 if (++i == w) { 1089 if (++i == w) {
1069 tile += TileDiffXY(0, 1); 1090 tile += TileDiffXY(0, 1);
1070 h--; 1091 h--;
1071 goto restart; 1092 goto restart;
1072 } 1093 }
1073 } 1094 }
1074 1095
1075 // check the lower side, y = constant, x changes 1096 /* check the lower side, y = constant, x changes */
1076 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) { 1097 for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) {
1077 // the left side is unused? 1098 /* the left side is unused? */
1078 if (++i == w) { 1099 if (++i == w) {
1079 h--; 1100 h--;
1080 goto restart; 1101 goto restart;
1081 } 1102 }
1082 } 1103 }
1143 SetSignalsOnBothDir(tile2, track); 1164 SetSignalsOnBothDir(tile2, track);
1144 YapfNotifyTrackLayoutChange(tile2, track); 1165 YapfNotifyTrackLayoutChange(tile2, track);
1145 1166
1146 DeallocateSpecFromStation(st, specindex); 1167 DeallocateSpecFromStation(st, specindex);
1147 1168
1148 // now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. 1169 /* now we need to make the "spanned" area of the railway station smaller
1149 // we also need to adjust train_tile. 1170 * if we deleted something at the edges.
1171 * we also need to adjust train_tile. */
1150 MakeRailwayStationAreaSmaller(st); 1172 MakeRailwayStationAreaSmaller(st);
1151 st->MarkTilesDirty(false); 1173 st->MarkTilesDirty(false);
1152 UpdateStationSignCoord(st); 1174 UpdateStationSignCoord(st);
1153 1175
1154 // if we deleted the whole station, delete the train facility. 1176 /* if we deleted the whole station, delete the train facility. */
1155 if (st->train_tile == 0) { 1177 if (st->train_tile == 0) {
1156 st->facilities &= ~FACIL_TRAIN; 1178 st->facilities &= ~FACIL_TRAIN;
1157 UpdateStationVirtCoordDirty(st); 1179 UpdateStationVirtCoordDirty(st);
1158 DeleteStationIfEmpty(st); 1180 DeleteStationIfEmpty(st);
1159 } 1181 }
1329 } 1351 }
1330 1352
1331 /* Find a station close to us */ 1353 /* Find a station close to us */
1332 if (st == NULL) st = GetClosestStationFromTile(tile); 1354 if (st == NULL) st = GetClosestStationFromTile(tile);
1333 1355
1334 //give us a road stop in the list, and check if something went wrong 1356 /* give us a road stop in the list, and check if something went wrong */
1335 RoadStop *road_stop = new RoadStop(tile); 1357 RoadStop *road_stop = new RoadStop(tile);
1336 if (road_stop == NULL) { 1358 if (road_stop == NULL) {
1337 return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); 1359 return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
1338 } 1360 }
1339 1361
1344 GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) { 1366 GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) {
1345 return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); 1367 return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
1346 } 1368 }
1347 1369
1348 /* In case of new station if DC_EXEC is NOT set we still need to create the station 1370 /* In case of new station if DC_EXEC is NOT set we still need to create the station
1349 * to test if everything is OK. In this case we need to delete it before return. */ 1371 * to test if everything is OK. In this case we need to delete it before return. */
1350 AutoPtrT<Station> st_auto_delete; 1372 AutoPtrT<Station> st_auto_delete;
1351 1373
1352 if (st != NULL) { 1374 if (st != NULL) {
1353 if (st->owner != _current_player) { 1375 if (st->owner != _current_player) {
1354 return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); 1376 return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
1375 } 1397 }
1376 1398
1377 cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station); 1399 cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station);
1378 1400
1379 if (flags & DC_EXEC) { 1401 if (flags & DC_EXEC) {
1380 // Insert into linked list of RoadStops 1402 /* Insert into linked list of RoadStops */
1381 RoadStop **currstop = FindRoadStopSpot(type, st); 1403 RoadStop **currstop = FindRoadStopSpot(type, st);
1382 *currstop = road_stop; 1404 *currstop = road_stop;
1383 1405
1384 //initialize an empty station 1406 /*initialize an empty station */
1385 st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile); 1407 st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile);
1386 1408
1387 st->rect.BeforeAddTile(tile, StationRect::ADD_TRY); 1409 st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
1388 1410
1389 RoadStop::Type rs_type = type ? RoadStop::TRUCK : RoadStop::BUS; 1411 RoadStop::Type rs_type = type ? RoadStop::TRUCK : RoadStop::BUS;
1402 rs_auto_delete.Detach(); 1424 rs_auto_delete.Detach();
1403 } 1425 }
1404 return cost; 1426 return cost;
1405 } 1427 }
1406 1428
1407 // Remove a bus station 1429 /** Remove a bus station
1430 * @param st Station to remove
1431 * @param flags operation to perform
1432 * @param tile TileIndex been queried
1433 * @return cost or failure of operation
1434 */
1408 static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) 1435 static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
1409 { 1436 {
1410 if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { 1437 if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
1411 return CMD_ERROR; 1438 return CMD_ERROR;
1412 } 1439 }
1427 1454
1428 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; 1455 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
1429 1456
1430 if (flags & DC_EXEC) { 1457 if (flags & DC_EXEC) {
1431 if (*primary_stop == cur_stop) { 1458 if (*primary_stop == cur_stop) {
1432 // removed the first stop in the list 1459 /* removed the first stop in the list */
1433 *primary_stop = cur_stop->next; 1460 *primary_stop = cur_stop->next;
1434 // removed the only stop? 1461 /* removed the only stop? */
1435 if (*primary_stop == NULL) { 1462 if (*primary_stop == NULL) {
1436 st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP); 1463 st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
1437 } 1464 }
1438 } else { 1465 } else {
1439 // tell the predecessor in the list to skip this stop 1466 /* tell the predecessor in the list to skip this stop */
1440 RoadStop *pred = *primary_stop; 1467 RoadStop *pred = *primary_stop;
1441 while (pred->next != cur_stop) pred = pred->next; 1468 while (pred->next != cur_stop) pred = pred->next;
1442 pred->next = cur_stop->next; 1469 pred->next = cur_stop->next;
1443 } 1470 }
1444 1471
1484 } 1511 }
1485 1512
1486 return ret; 1513 return ret;
1487 } 1514 }
1488 1515
1489 // FIXME -- need to move to its corresponding Airport variable 1516 /* FIXME -- need to move to its corresponding Airport variable*/
1490 // Country Airfield (small) 1517
1518 /* Country Airfield (small) */
1491 static const byte _airport_sections_country[] = { 1519 static const byte _airport_sections_country[] = {
1492 54, 53, 52, 65, 1520 54, 53, 52, 65,
1493 58, 57, 56, 55, 1521 58, 57, 56, 55,
1494 64, 63, 63, 62 1522 64, 63, 63, 62
1495 }; 1523 };
1496 1524
1497 // City Airport (large) 1525 /* City Airport (large) */
1498 static const byte _airport_sections_town[] = { 1526 static const byte _airport_sections_town[] = {
1499 31, 9, 33, 9, 9, 32, 1527 31, 9, 33, 9, 9, 32,
1500 27, 36, 29, 34, 8, 10, 1528 27, 36, 29, 34, 8, 10,
1501 30, 11, 35, 13, 20, 21, 1529 30, 11, 35, 13, 20, 21,
1502 51, 12, 14, 17, 19, 28, 1530 51, 12, 14, 17, 19, 28,
1503 38, 13, 15, 16, 18, 39, 1531 38, 13, 15, 16, 18, 39,
1504 26, 22, 23, 24, 25, 26 1532 26, 22, 23, 24, 25, 26
1505 }; 1533 };
1506 1534
1507 // Metropolitain Airport (large) - 2 runways 1535 /* Metropolitain Airport (large) - 2 runways */
1508 static const byte _airport_sections_metropolitan[] = { 1536 static const byte _airport_sections_metropolitan[] = {
1509 31, 9, 33, 9, 9, 32, 1537 31, 9, 33, 9, 9, 32,
1510 27, 36, 29, 34, 8, 10, 1538 27, 36, 29, 34, 8, 10,
1511 30, 11, 35, 13, 20, 21, 1539 30, 11, 35, 13, 20, 21,
1512 102, 8, 8, 8, 8, 28, 1540 102, 8, 8, 8, 8, 28,
1513 83, 84, 84, 84, 84, 83, 1541 83, 84, 84, 84, 84, 83,
1514 26, 23, 23, 23, 23, 26 1542 26, 23, 23, 23, 23, 26
1515 }; 1543 };
1516 1544
1517 // International Airport (large) - 2 runways 1545 /* International Airport (large) - 2 runways */
1518 static const byte _airport_sections_international[] = { 1546 static const byte _airport_sections_international[] = {
1519 88, 89, 89, 89, 89, 89, 88, 1547 88, 89, 89, 89, 89, 89, 88,
1520 51, 8, 8, 8, 8, 8, 32, 1548 51, 8, 8, 8, 8, 8, 32,
1521 30, 8, 11, 27, 11, 8, 10, 1549 30, 8, 11, 27, 11, 8, 10,
1522 32, 8, 11, 27, 11, 8, 114, 1550 32, 8, 11, 27, 11, 8, 114,
1523 87, 8, 11, 85, 11, 8, 114, 1551 87, 8, 11, 85, 11, 8, 114,
1524 87, 8, 8, 8, 8, 8, 90, 1552 87, 8, 8, 8, 8, 8, 90,
1525 26, 23, 23, 23, 23, 23, 26 1553 26, 23, 23, 23, 23, 23, 26
1526 }; 1554 };
1527 1555
1528 // Intercontinental Airport (vlarge) - 4 runways 1556 /* Intercontinental Airport (vlarge) - 4 runways */
1529 static const byte _airport_sections_intercontinental[] = { 1557 static const byte _airport_sections_intercontinental[] = {
1530 102, 120, 89, 89, 89, 89, 89, 89, 118, 1558 102, 120, 89, 89, 89, 89, 89, 89, 118,
1531 120, 23, 23, 23, 23, 23, 23, 119, 117, 1559 120, 23, 23, 23, 23, 23, 23, 119, 117,
1532 87, 54, 87, 8, 8, 8, 8, 51, 117, 1560 87, 54, 87, 8, 8, 8, 8, 51, 117,
1533 87, 162, 87, 85, 116, 116, 8, 9, 10, 1561 87, 162, 87, 85, 116, 116, 8, 9, 10,
1539 87, 120, 89, 89, 89, 89, 89, 89, 119, 1567 87, 120, 89, 89, 89, 89, 89, 89, 119,
1540 121, 23, 23, 23, 23, 23, 23, 119, 37 1568 121, 23, 23, 23, 23, 23, 23, 119, 37
1541 }; 1569 };
1542 1570
1543 1571
1544 // Commuter Airfield (small) 1572 /* Commuter Airfield (small) */
1545 static const byte _airport_sections_commuter[] = { 1573 static const byte _airport_sections_commuter[] = {
1546 85, 30, 115, 115, 32, 1574 85, 30, 115, 115, 32,
1547 87, 8, 8, 8, 10, 1575 87, 8, 8, 8, 10,
1548 87, 11, 11, 11, 10, 1576 87, 11, 11, 11, 10,
1549 26, 23, 23, 23, 26 1577 26, 23, 23, 23, 26
1550 }; 1578 };
1551 1579
1552 // Heliport 1580 /* Heliport */
1553 static const byte _airport_sections_heliport[] = { 1581 static const byte _airport_sections_heliport[] = {
1554 66, 1582 66,
1555 }; 1583 };
1556 1584
1557 // Helidepot 1585 /* Helidepot */
1558 static const byte _airport_sections_helidepot[] = { 1586 static const byte _airport_sections_helidepot[] = {
1559 124, 32, 1587 124, 32,
1560 122, 123 1588 122, 123
1561 }; 1589 };
1562 1590
1563 // Helistation 1591 /* Helistation */
1564 static const byte _airport_sections_helistation[] = { 1592 static const byte _airport_sections_helistation[] = {
1565 32, 134, 159, 158, 1593 32, 134, 159, 158,
1566 161, 142, 142, 157 1594 161, 142, 142, 157
1567 }; 1595 };
1568 1596
1924 1952
1925 /* Find a station close to us */ 1953 /* Find a station close to us */
1926 if (st == NULL) st = GetClosestStationFromTile(tile); 1954 if (st == NULL) st = GetClosestStationFromTile(tile);
1927 1955
1928 /* In case of new station if DC_EXEC is NOT set we still need to create the station 1956 /* In case of new station if DC_EXEC is NOT set we still need to create the station
1929 * to test if everything is OK. In this case we need to delete it before return. */ 1957 * to test if everything is OK. In this case we need to delete it before return. */
1930 AutoPtrT<Station> st_auto_delete; 1958 AutoPtrT<Station> st_auto_delete;
1931 1959
1932 if (st != NULL) { 1960 if (st != NULL) {
1933 if (st->owner != _current_player) 1961 if (st->owner != _current_player)
1934 return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); 1962 return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
2032 2060
2033 SpriteID palette; 2061 SpriteID palette;
2034 if (IsValidPlayer(owner)) { 2062 if (IsValidPlayer(owner)) {
2035 palette = PLAYER_SPRITE_COLOR(owner); 2063 palette = PLAYER_SPRITE_COLOR(owner);
2036 } else { 2064 } else {
2037 // Some stations are not owner by a player, namely oil rigs 2065 /* Some stations are not owner by a player, namely oil rigs */
2038 palette = PALETTE_TO_GREY; 2066 palette = PALETTE_TO_GREY;
2039 } 2067 }
2040 2068
2041 // don't show foundation for docks 2069 /* don't show foundation for docks */
2042 if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) 2070 if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile))
2043 DrawFoundation(ti, FOUNDATION_LEVELED); 2071 DrawFoundation(ti, FOUNDATION_LEVELED);
2044 2072
2045 if (IsCustomStationSpecIndex(ti->tile)) { 2073 if (IsCustomStationSpecIndex(ti->tile)) {
2046 // look for customization 2074 /* look for customization */
2047 st = GetStationByTile(ti->tile); 2075 st = GetStationByTile(ti->tile);
2048 statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec; 2076 statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
2049 2077
2050 //debug("Cust-o-mized %p", statspec); 2078 //debug("Cust-o-mized %p", statspec);
2051 2079
2074 image += rti->custom_ground_offset; 2102 image += rti->custom_ground_offset;
2075 } else { 2103 } else {
2076 image += rti->total_offset; 2104 image += rti->total_offset;
2077 } 2105 }
2078 2106
2079 // station_land array has been increased from 82 elements to 114 2107 /* station_land array has been increased from 82 elements to 114
2080 // but this is something else. If AI builds station with 114 it looks all weird 2108 * but this is something else. If AI builds station with 114 it looks all weird */
2081 DrawGroundSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE); 2109 DrawGroundSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
2082 2110
2083 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti); 2111 if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
2084 2112
2085 if (HASBIT(roadtypes, ROADTYPE_TRAM)) { 2113 if (HASBIT(roadtypes, ROADTYPE_TRAM)) {
2185 return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101; 2213 return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101;
2186 } 2214 }
2187 break; 2215 break;
2188 2216
2189 case TRANSPORT_WATER: 2217 case TRANSPORT_WATER:
2190 // buoy is coded as a station, it is always on open water 2218 /* buoy is coded as a station, it is always on open water */
2191 if (IsBuoy(tile)) { 2219 if (IsBuoy(tile)) {
2192 TrackBits ts = TRACK_BIT_ALL; 2220 TrackBits ts = TRACK_BIT_ALL;
2193 // remove tracks that connect NE map edge 2221 /* remove tracks that connect NE map edge */
2194 if (TileX(tile) == 0) ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT); 2222 if (TileX(tile) == 0) ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
2195 // remove tracks that connect NW map edge 2223 /* remove tracks that connect NW map edge */
2196 if (TileY(tile) == 0) ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER); 2224 if (TileY(tile) == 0) ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
2197 return uint32(ts) * 0x101; 2225 return uint32(ts) * 0x101;
2198 } 2226 }
2199 break; 2227 break;
2200 2228
2212 } 2240 }
2213 2241
2214 2242
2215 static void TileLoop_Station(TileIndex tile) 2243 static void TileLoop_Station(TileIndex tile)
2216 { 2244 {
2217 // FIXME -- GetTileTrackStatus_Station -> animated stationtiles 2245 /* FIXME -- GetTileTrackStatus_Station -> animated stationtiles
2218 // hardcoded.....not good 2246 * hardcoded.....not good */
2219 switch (GetStationType(tile)) { 2247 switch (GetStationType(tile)) {
2220 case STATION_AIRPORT: 2248 case STATION_AIRPORT:
2221 switch (GetStationGfx(tile)) { 2249 switch (GetStationGfx(tile)) {
2222 case GFX_RADAR_LARGE_FIRST: 2250 case GFX_RADAR_LARGE_FIRST:
2223 case GFX_WINDSACK_FIRST : // for small airport 2251 case GFX_WINDSACK_FIRST : // for small airport
2410 2438
2411 if (IsValidPlayer(st->owner) && HASBIT(st->town->statues, st->owner)) rating += 26; 2439 if (IsValidPlayer(st->owner) && HASBIT(st->town->statues, st->owner)) rating += 26;
2412 2440
2413 { 2441 {
2414 byte days = ge->days_since_pickup; 2442 byte days = ge->days_since_pickup;
2415 if (st->last_vehicle_type == VEH_SHIP) 2443 if (st->last_vehicle_type == VEH_SHIP) days >>= 2;
2416 days >>= 2;
2417 (days > 21) || 2444 (days > 21) ||
2418 (rating += 25, days > 12) || 2445 (rating += 25, days > 12) ||
2419 (rating += 25, days > 6) || 2446 (rating += 25, days > 6) ||
2420 (rating += 45, days > 3) || 2447 (rating += 45, days > 3) ||
2421 (rating += 35, true); 2448 (rating += 35, true);
2430 (rating += 10, true); 2457 (rating += 10, true);
2431 2458
2432 { 2459 {
2433 int or_ = ge->rating; // old rating 2460 int or_ = ge->rating; // old rating
2434 2461
2435 // only modify rating in steps of -2, -1, 0, 1 or 2 2462 /* only modify rating in steps of -2, -1, 0, 1 or 2 */
2436 ge->rating = rating = or_ + clamp(clamp(rating, 0, 255) - or_, -2, 2); 2463 ge->rating = rating = or_ + clamp(clamp(rating, 0, 255) - or_, -2, 2);
2437 2464
2438 // if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station 2465 /* if rating is <= 64 and more than 200 items waiting,
2466 * remove some random amount of goods from the station */
2439 if (rating <= 64 && waiting >= 200) { 2467 if (rating <= 64 && waiting >= 200) {
2440 int dec = Random() & 0x1F; 2468 int dec = Random() & 0x1F;
2441 if (waiting < 400) dec &= 7; 2469 if (waiting < 400) dec &= 7;
2442 waiting -= dec + 1; 2470 waiting -= dec + 1;
2443 waiting_changed = true; 2471 waiting_changed = true;
2444 } 2472 }
2445 2473
2446 // if rating is <= 127 and there are any items waiting, maybe remove some goods. 2474 /* if rating is <= 127 and there are any items waiting, maybe remove some goods. */
2447 if (rating <= 127 && waiting != 0) { 2475 if (rating <= 127 && waiting != 0) {
2448 uint32 r = Random(); 2476 uint32 r = Random();
2449 if (rating <= (int)GB(r, 0, 7)) { 2477 if (rating <= (int)GB(r, 0, 7)) {
2450 /* Need to have int, otherwise it will just overflow etc. */ 2478 /* Need to have int, otherwise it will just overflow etc. */
2451 waiting = max((int)waiting - (int)GB(r, 8, 2) - 1, 0); 2479 waiting = max((int)waiting - (int)GB(r, 8, 2) - 1, 0);
2622 st->goods[type].rating != 0 && // when you've got the lowest rating you can get, it's better not to give cargo anymore 2650 st->goods[type].rating != 0 && // when you've got the lowest rating you can get, it's better not to give cargo anymore
2623 (!_patches.selectgoods || st->goods[type].last_speed != 0) && // we are servicing the station (or cargo is dumped on all stations) 2651 (!_patches.selectgoods || st->goods[type].last_speed != 0) && // we are servicing the station (or cargo is dumped on all stations)
2624 ((st->facilities & ~FACIL_BUS_STOP) != 0 || IsCargoInClass(type, CC_PASSENGERS)) && // if we have other fac. than a bus stop, or the cargo is passengers 2652 ((st->facilities & ~FACIL_BUS_STOP) != 0 || IsCargoInClass(type, CC_PASSENGERS)) && // if we have other fac. than a bus stop, or the cargo is passengers
2625 ((st->facilities & ~FACIL_TRUCK_STOP) != 0 || !IsCargoInClass(type, CC_PASSENGERS))) { // if we have other fac. than a cargo bay or the cargo is not passengers 2653 ((st->facilities & ~FACIL_TRUCK_STOP) != 0 || !IsCargoInClass(type, CC_PASSENGERS))) { // if we have other fac. than a cargo bay or the cargo is not passengers
2626 if (_patches.modified_catchment) { 2654 if (_patches.modified_catchment) {
2627 // min and max coordinates of the producer relative 2655 /* min and max coordinates of the producer relative */
2628 const int x_min_prod = max_rad + 1; 2656 const int x_min_prod = max_rad + 1;
2629 const int x_max_prod = max_rad + w_prod; 2657 const int x_max_prod = max_rad + w_prod;
2630 const int y_min_prod = max_rad + 1; 2658 const int y_min_prod = max_rad + 1;
2631 const int y_max_prod = max_rad + h_prod; 2659 const int y_max_prod = max_rad + h_prod;
2632 2660
2962 SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION), 2990 SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION),
2963 SLE_REF(Station, town, REF_TOWN), 2991 SLE_REF(Station, town, REF_TOWN),
2964 SLE_VAR(Station, trainst_w, SLE_UINT8), 2992 SLE_VAR(Station, trainst_w, SLE_UINT8),
2965 SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION), 2993 SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION),
2966 2994
2967 // alpha_order was stored here in savegame format 0 - 3 2995 /* alpha_order was stored here in savegame format 0 - 3 */
2968 SLE_CONDNULL(1, 0, 3), 2996 SLE_CONDNULL(1, 0, 3),
2969 2997
2970 SLE_VAR(Station, string_id, SLE_STRINGID), 2998 SLE_VAR(Station, string_id, SLE_STRINGID),
2971 SLE_VAR(Station, had_vehicle_of_type, SLE_UINT16), 2999 SLE_VAR(Station, had_vehicle_of_type, SLE_UINT16),
2972 3000
2985 SLE_CONDVAR(Station, airport_flags, SLE_UINT64, 46, SL_MAX_VERSION), 3013 SLE_CONDVAR(Station, airport_flags, SLE_UINT64, 46, SL_MAX_VERSION),
2986 3014
2987 SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */ 3015 SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */
2988 SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION), 3016 SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION),
2989 3017
2990 // Was custom station class and id 3018 /* Was custom station class and id */
2991 SLE_CONDNULL(2, 3, 25), 3019 SLE_CONDNULL(2, 3, 25),
2992 SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), 3020 SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30),
2993 SLE_CONDVAR(Station, build_date, SLE_INT32, 31, SL_MAX_VERSION), 3021 SLE_CONDVAR(Station, build_date, SLE_INT32, 31, SL_MAX_VERSION),
2994 3022
2995 SLE_CONDREF(Station, bus_stops, REF_ROADSTOPS, 6, SL_MAX_VERSION), 3023 SLE_CONDREF(Station, bus_stops, REF_ROADSTOPS, 6, SL_MAX_VERSION),
3000 SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, 27, SL_MAX_VERSION), 3028 SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, 27, SL_MAX_VERSION),
3001 SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION), 3029 SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION),
3002 3030
3003 SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION), 3031 SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION),
3004 3032
3005 // reserve extra space in savegame here. (currently 32 bytes) 3033 /* reserve extra space in savegame here. (currently 32 bytes) */
3006 SLE_CONDNULL(32, 2, SL_MAX_VERSION), 3034 SLE_CONDNULL(32, 2, SL_MAX_VERSION),
3007 3035
3008 SLE_END() 3036 SLE_END()
3009 }; 3037 };
3010 3038
3081 } 3109 }
3082 3110
3083 static void Save_STNS() 3111 static void Save_STNS()
3084 { 3112 {
3085 Station *st; 3113 Station *st;
3086 // Write the stations 3114 /* Write the stations */
3087 FOR_ALL_STATIONS(st) { 3115 FOR_ALL_STATIONS(st) {
3088 SlSetArrayIndex(st->index); 3116 SlSetArrayIndex(st->index);
3089 SlAutolength((AutolengthProc*)SaveLoad_STNS, st); 3117 SlAutolength((AutolengthProc*)SaveLoad_STNS, st);
3090 } 3118 }
3091 } 3119 }
3096 while ((index = SlIterateArray()) != -1) { 3124 while ((index = SlIterateArray()) != -1) {
3097 Station *st = new (index) Station(); 3125 Station *st = new (index) Station();
3098 3126
3099 SaveLoad_STNS(st); 3127 SaveLoad_STNS(st);
3100 3128
3101 // this means it's an oldstyle savegame without support for nonuniform stations 3129 /* this means it's an oldstyle savegame without support for nonuniform stations */
3102 if (st->train_tile != 0 && st->trainst_h == 0) { 3130 if (st->train_tile != 0 && st->trainst_h == 0) {
3103 uint w = GB(st->trainst_w, 4, 4); 3131 uint w = GB(st->trainst_w, 4, 4);
3104 uint h = GB(st->trainst_w, 0, 4); 3132 uint h = GB(st->trainst_w, 0, 4);
3105 3133
3106 if (GetRailStationAxis(st->train_tile) != AXIS_X) Swap(w, h); 3134 if (GetRailStationAxis(st->train_tile) != AXIS_X) Swap(w, h);