~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/station_cmd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman
  • Date: 2009-06-09 21:46:28 UTC
  • mfrom: (1.1.7 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090609214628-6z5uodi6178z050l
[ Matthijs Kooijman ]
* New upstream release.
* Link against libicu to enable right-to-left language support. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: station_cmd.cpp 15764 2009-03-18 19:47:05Z rubidium $ */
 
1
/* $Id: station_cmd.cpp 16481 2009-05-31 12:18:03Z rubidium $ */
2
2
 
3
3
/** @file station_cmd.cpp Handling of station tiles. */
4
4
 
148
148
        if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
149
149
 
150
150
        for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
151
 
                /* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */
152
 
                if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
 
151
                /* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine.
 
152
                 * Also the production of passengers and mail is ignored. */
 
153
                if (ind->produced_cargo[i] != CT_INVALID &&
 
154
                                (GetCargo(ind->produced_cargo[i])->classes & (CC_LIQUID | CC_PASSENGERS | CC_MAIL)) == 0) {
 
155
                        return true;
 
156
                }
153
157
        }
154
158
 
155
159
        return false;
534
538
        }
535
539
}
536
540
 
537
 
static inline void MergePoint(Rect *rect, TileIndex tile)
538
 
{
539
 
        int x = TileX(tile);
540
 
        int y = TileY(tile);
541
 
 
542
 
        if (rect->left   > x) rect->left   = x;
543
 
        if (rect->bottom > y) rect->bottom = y;
544
 
        if (rect->right  < x) rect->right  = x;
545
 
        if (rect->top    < y) rect->top    = y;
546
 
}
547
 
 
548
541
/** Update the acceptance for a station.
549
542
 * @param st Station to update
550
543
 * @param show_msg controls whether to display a message that acceptance was changed.
554
547
        /* Don't update acceptance for a buoy */
555
548
        if (st->IsBuoy()) return;
556
549
 
557
 
        Rect rect;
558
 
        rect.left   = MapSizeX();
559
 
        rect.bottom = MapSizeY();
560
 
        rect.right  = 0;
561
 
        rect.top    = 0;
562
 
 
563
550
        /* old accepted goods types */
564
551
        uint old_acc = GetAcceptanceMask(st);
565
552
 
566
 
        /* Put all the tiles that span an area in the table. */
567
 
        if (st->train_tile != INVALID_TILE) {
568
 
                MergePoint(&rect, st->train_tile);
569
 
                MergePoint(&rect, st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1));
570
 
        }
571
 
 
572
 
        if (st->airport_tile != INVALID_TILE) {
573
 
                const AirportFTAClass *afc = st->Airport();
574
 
 
575
 
                MergePoint(&rect, st->airport_tile);
576
 
                MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1));
577
 
        }
578
 
 
579
 
        if (st->dock_tile != INVALID_TILE) {
580
 
                MergePoint(&rect, st->dock_tile);
581
 
                if (IsDockTile(st->dock_tile)) {
582
 
                        MergePoint(&rect, st->dock_tile + TileOffsByDiagDir(GetDockDirection(st->dock_tile)));
583
 
                } // else OilRig
584
 
        }
585
 
 
586
 
        for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) {
587
 
                MergePoint(&rect, rs->xy);
588
 
        }
589
 
 
590
 
        for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) {
591
 
                MergePoint(&rect, rs->xy);
592
 
        }
593
 
 
594
553
        /* And retrieve the acceptance. */
595
554
        AcceptedCargo accepts;
596
 
        assert((rect.right >= rect.left) == !st->rect.IsEmpty());
597
 
        if (rect.right >= rect.left) {
598
 
                assert(rect.left == st->rect.left);
599
 
                assert(rect.top == st->rect.bottom);
600
 
                assert(rect.right == st->rect.right);
601
 
                assert(rect.bottom == st->rect.top);
 
555
        if (!st->rect.IsEmpty()) {
602
556
                GetAcceptanceAroundTiles(
603
557
                        accepts,
604
 
                        TileXY(rect.left, rect.bottom),
605
 
                        rect.right - rect.left   + 1,
606
 
                        rect.top   - rect.bottom + 1,
 
558
                        TileXY(st->rect.left, st->rect.top),
 
559
                        st->rect.right  - st->rect.left + 1,
 
560
                        st->rect.bottom - st->rect.top  + 1,
607
561
                        st->GetCatchmentRadius()
608
562
                );
609
563
        } else {
922
876
        }
923
877
 
924
878
        StationID station_to_join = GB(p2, 16, 16);
 
879
        bool reuse = (station_to_join != NEW_STATION);
 
880
        if (!reuse) station_to_join = INVALID_STATION;
925
881
        bool distant_join = (station_to_join != INVALID_STATION);
926
882
 
927
883
        if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
975
931
        if (st == NULL && distant_join) st = GetStation(station_to_join);
976
932
 
977
933
        /* See if there is a deleted station close to us. */
978
 
        if (st == NULL) st = GetClosestDeletedStation(tile_org);
 
934
        if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
979
935
 
980
936
        if (st != NULL) {
981
937
                /* Reuse an existing station. */
1403
1359
        bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
1404
1360
        RoadTypes rts = (RoadTypes)GB(p2, 2, 2);
1405
1361
        StationID station_to_join = GB(p2, 16, 16);
 
1362
        bool reuse = (station_to_join != NEW_STATION);
 
1363
        if (!reuse) station_to_join = INVALID_STATION;
1406
1364
        bool distant_join = (station_to_join != INVALID_STATION);
1407
1365
        Owner tram_owner = _current_company;
1408
1366
        Owner road_owner = _current_company;
1470
1428
        if (st == NULL && distant_join) st = GetStation(station_to_join);
1471
1429
 
1472
1430
        /* Find a deleted station close to us */
1473
 
        if (st == NULL) st = GetClosestDeletedStation(tile);
 
1431
        if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
1474
1432
 
1475
1433
        /* give us a road stop in the list, and check if something went wrong */
1476
1434
        if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
1535
1493
 
1536
1494
static Vehicle *ClearRoadStopStatusEnum(Vehicle *v, void *)
1537
1495
{
1538
 
        if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
 
1496
        if (v->type == VEH_ROAD) v->u.road.state &= RVSB_ROAD_STOP_TRACKDIR_MASK;
1539
1497
 
1540
1498
        return NULL;
1541
1499
}
1855
1813
{
1856
1814
        bool airport_upgrade = true;
1857
1815
        StationID station_to_join = GB(p2, 16, 16);
 
1816
        bool reuse = (station_to_join != NEW_STATION);
 
1817
        if (!reuse) station_to_join = INVALID_STATION;
1858
1818
        bool distant_join = (station_to_join != INVALID_STATION);
1859
1819
 
1860
1820
        if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
1861
1821
 
1862
1822
        /* Check if a valid, buildable airport was chosen for construction */
1863
 
        if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
 
1823
        if (p1 >= lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
1864
1824
 
1865
1825
        if (!CheckIfAuthorityAllowsNewStation(tile, flags)) {
1866
1826
                return CMD_ERROR;
1919
1879
        if (st == NULL && distant_join) st = GetStation(station_to_join);
1920
1880
 
1921
1881
        /* Find a deleted station close to us */
1922
 
        if (st == NULL) st = GetClosestDeletedStation(tile);
 
1882
        if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
1923
1883
 
1924
1884
        if (st != NULL) {
1925
1885
                if (st->owner != _current_company) {
2126
2086
 
2127
2087
static CommandCost RemoveBuoy(Station *st, DoCommandFlag flags)
2128
2088
{
2129
 
        /* XXX: strange stuff */
2130
 
        if (!IsValidCompanyID(_current_company)) return_cmd_error(INVALID_STRING_ID);
 
2089
        /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
 
2090
        if (!IsValidCompanyID(_current_company) && !(flags & DC_BANKRUPT)) return_cmd_error(INVALID_STRING_ID);
2131
2091
 
2132
2092
        TileIndex tile = st->dock_tile;
2133
2093
 
2175
2135
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
2176
2136
{
2177
2137
        StationID station_to_join = GB(p2, 16, 16);
 
2138
        bool reuse = (station_to_join != NEW_STATION);
 
2139
        if (!reuse) station_to_join = INVALID_STATION;
2178
2140
        bool distant_join = (station_to_join != INVALID_STATION);
2179
2141
 
2180
2142
        if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
2224
2186
        if (st == NULL && distant_join) st = GetStation(station_to_join);
2225
2187
 
2226
2188
        /* Find a deleted station close to us */
2227
 
        if (st == NULL) st = GetClosestDeletedStation(tile);
 
2189
        if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
2228
2190
 
2229
2191
        if (st != NULL) {
2230
2192
                if (st->owner != _current_company) {
2727
2689
        return VETSB_CONTINUE;
2728
2690
}
2729
2691
 
2730
 
/* this function is called for one station each tick */
 
2692
/**
 
2693
 * This function is called for each station once every 250 ticks.
 
2694
 * Not all stations will get the tick at the same time.
 
2695
 * @param st the station receiving the tick.
 
2696
 */
2731
2697
static void StationHandleBigTick(Station *st)
2732
2698
{
2733
2699
        UpdateStationAcceptance(st, true);
2867
2833
{
2868
2834
        if (_game_mode == GM_EDITOR) return;
2869
2835
 
2870
 
        uint i = _station_tick_ctr;
2871
 
        if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0;
2872
 
 
2873
 
        if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
2874
 
 
2875
2836
        Station *st;
2876
2837
        FOR_ALL_STATIONS(st) {
2877
2838
                StationHandleSmallTick(st);
2880
2841
                 * Station index is included so that triggers are not all done
2881
2842
                 * at the same time. */
2882
2843
                if ((_tick_counter + st->index) % 250 == 0) {
 
2844
                        StationHandleBigTick(st);
2883
2845
                        StationAnimationTrigger(st, st->xy, STAT_ANIM_250_TICKS);
2884
2846
                }
2885
2847
        }
3001
2963
 
3002
2964
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
3003
2965
{
 
2966
        /* Return if nothing to do. Also the rounding below fails for 0. */
 
2967
        if (amount == 0) return 0;
 
2968
 
3004
2969
        Station *st1 = NULL;   // Station with best rating
3005
2970
        Station *st2 = NULL;   // Second best station
3006
2971
        uint best_rating1 = 0; // rating of st1
3236
3201
        /* Clean the roadstop pool and create 1 block in it */
3237
3202
        _RoadStop_pool.CleanPool();
3238
3203
        _RoadStop_pool.AddBlockToPool();
3239
 
 
3240
 
        _station_tick_ctr = 0;
3241
3204
}
3242
3205
 
3243
3206
static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)