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

« back to all changes in this revision

Viewing changes to src/economy.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Kooijman, Matthijs Kooijman
  • Date: 2009-10-01 22:52:59 UTC
  • mfrom: (1.1.8 upstream) (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091001225259-5kpkp4sthbszpyif
[ Matthijs Kooijman ]
* New upstream release
* Use printf instead of echo -en in openttd-wrapper to make it POSIX
  compatible (Closes: #547758).
* Remove three patches that are now included in upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: economy.cpp 16423 2009-05-25 17:15:15Z rubidium $ */
 
1
/* $Id: economy.cpp 17564 2009-09-18 07:00:35Z rubidium $ */
2
2
 
3
3
/** @file economy.cpp Handling of the economy. */
4
4
 
32
32
#include "autoreplace_func.h"
33
33
#include "company_gui.h"
34
34
#include "signs_base.h"
 
35
#include "economy_base.h"
 
36
#include "oldpool_func.h"
35
37
 
36
38
#include "table/strings.h"
37
39
#include "table/sprites.h"
38
40
 
 
41
 
 
42
/* Initialize the cargo payment-pool */
 
43
DEFINE_OLD_POOL_GENERIC(CargoPayment, CargoPayment)
 
44
 
39
45
/**
40
46
 * Multiply two integer values and shift the results to right.
41
47
 *
463
469
        /*  If the company has money again, it does not go bankrupt */
464
470
        if (c->money >= 0) {
465
471
                c->quarters_of_bankrupcy = 0;
 
472
                c->bankrupt_asked = 0;
466
473
                return;
467
474
        }
468
475
 
515
522
                                 * he/she is no long in control of this company. However... when you
516
523
                                 * join another company (cheat) the "unowned" company can bankrupt. */
517
524
                                c->bankrupt_asked = MAX_UVALUE(CompanyMask);
518
 
                                c->bankrupt_timeout = 0x456;
 
525
                                free(cni);
519
526
                                break;
520
527
                        }
521
528
 
664
671
 
665
672
static void HandleEconomyFluctuations()
666
673
{
667
 
        if (_settings_game.difficulty.economy == 0) return;
 
674
        if (_settings_game.difficulty.economy != 0) {
 
675
                /* When economy is Fluctuating, decrease counter */
 
676
                _economy.fluct--;
 
677
        } else if (_economy.fluct <= 0) {
 
678
                /* When it's Steady and we are in recession, end it now */
 
679
                _economy.fluct = -12;
 
680
        } else {
 
681
                /* No need to do anything else in other cases */
 
682
                return;
 
683
        }
668
684
 
669
 
        if (--_economy.fluct == 0) {
 
685
        if (_economy.fluct == 0) {
670
686
                _economy.fluct = -(int)GB(Random(), 0, 2);
671
687
                AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NS_ECONOMY, 0, 0);
672
688
        } else if (_economy.fluct == -12) {
1137
1153
                        int result = GB(callback, 0, 14);
1138
1154
 
1139
1155
                        /* Simulate a 15 bit signed value */
1140
 
                        if (HasBit(callback, 14)) result = 0x4000 - result;
 
1156
                        if (HasBit(callback, 14)) result -= 0x4000;
1141
1157
 
1142
1158
                        /* "The result should be a signed multiplier that gets multiplied
1143
1159
                         * by the amount of cargo moved and the price factor, then gets
1220
1236
        return true;
1221
1237
}
1222
1238
 
 
1239
/** The industries we've currently brought cargo to. */
 
1240
static SmallIndustryList _cargo_delivery_destinations;
 
1241
 
1223
1242
/**
1224
1243
 * Transfer goods from station to industry.
1225
1244
 * All cargo is delivered to the nearest (Manhattan) industry to the station sign, which is inside the acceptance rectangle and actually accepts the cargo.
1226
1245
 * @param st The station that accepted the cargo
1227
1246
 * @param cargo_type Type of cargo delivered
1228
1247
 * @param nun_pieces Amount of cargo delivered
1229
 
 * @param industry_set The destination industry will be inserted into this set
1230
1248
 */
1231
 
static void DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, int num_pieces, SmallIndustryList *industry_set)
 
1249
static void DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, int num_pieces)
1232
1250
{
1233
1251
        if (st->rect.IsEmpty()) return;
1234
1252
 
1267
1285
                assert(best != NULL);
1268
1286
 
1269
1287
                /* Insert the industry into industry_set, if not yet contained */
1270
 
                if (industry_set != NULL) industry_set->Include(best);
 
1288
                _cargo_delivery_destinations.Include(best);
1271
1289
 
1272
1290
                best->incoming_cargo_waiting[accepted_cargo_index] = min(num_pieces + best->incoming_cargo_waiting[accepted_cargo_index], 0xFFFF);
1273
1291
        }
1274
1292
}
1275
1293
 
1276
 
static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type)
 
1294
 
 
1295
static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type, CompanyID company)
1277
1296
{
1278
1297
        Subsidy *s;
1279
1298
        TileIndex xy;
1325
1344
                        pair = SetupSubsidyDecodeParam(s, 0);
1326
1345
                        InjectDParam(1);
1327
1346
 
1328
 
                        SetDParam(0, _current_company);
 
1347
                        SetDParam(0, company);
1329
1348
                        AddNewsItem(
1330
1349
                                STR_2031_SERVICE_SUBSIDY_AWARDED + _settings_game.difficulty.subsidy_multiplier,
1331
1350
                                NS_SUBSIDIES,
1347
1366
 * @param dest Station the cargo has been unloaded
1348
1367
 * @param source_tile The origin of the cargo for distance calculation
1349
1368
 * @param days_in_transit Travel time
1350
 
 * @param industry_set The delivered industry will be inserted into this set, if not yet contained
 
1369
 * @param company The company delivering the cargo
1351
1370
 * The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery
1352
1371
 */
1353
 
static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit, SmallIndustryList *industry_set)
 
1372
static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit, Company *company)
1354
1373
{
1355
1374
        bool subsidised;
1356
1375
        Station *s_from, *s_to;
1359
1378
        assert(num_pieces > 0);
1360
1379
 
1361
1380
        /* Update company statistics */
1362
 
        {
1363
 
                Company *c = GetCompany(_current_company);
1364
 
                c->cur_economy.delivered_cargo += num_pieces;
1365
 
                SetBit(c->cargo_types, cargo_type);
1366
 
        }
 
1381
        company->cur_economy.delivered_cargo += num_pieces;
 
1382
        SetBit(company->cargo_types, cargo_type);
1367
1383
 
1368
1384
        /* Get station pointers. */
1369
1385
        s_from = IsValidStationID(source) ? GetStation(source) : NULL;
1370
1386
        s_to = GetStation(dest);
1371
1387
 
1372
1388
        /* Check if a subsidy applies. */
1373
 
        subsidised = s_from != NULL && CheckSubsidised(s_from, s_to, cargo_type);
 
1389
        subsidised = s_from != NULL && CheckSubsidised(s_from, s_to, cargo_type, company->index);
1374
1390
 
1375
1391
        /* Increase town's counter for some special goods types */
1376
1392
        const CargoSpec *cs = GetCargo(cargo_type);
1378
1394
        if (cs->town_effect == TE_WATER) s_to->town->new_act_water += num_pieces;
1379
1395
 
1380
1396
        /* Give the goods to the industry. */
1381
 
        DeliverGoodsToIndustry(s_to, cargo_type, num_pieces, industry_set);
 
1397
        DeliverGoodsToIndustry(s_to, cargo_type, num_pieces);
1382
1398
 
1383
1399
        /* Determine profit */
1384
1400
        profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(source_tile, s_to->xy), days_in_transit, cargo_type);
1432
1448
}
1433
1449
 
1434
1450
/**
1435
 
 * Performs the vehicle payment _and_ marks the vehicle to be unloaded.
 
1451
 * Makes us a new cargo payment helper.
 
1452
 * @param front The front of the train
 
1453
 * @param destinations List to add the destinations of 'our' cargo to
 
1454
 */
 
1455
CargoPayment::CargoPayment(Vehicle *front) :
 
1456
        front(front),
 
1457
        current_station(front->last_station_visited)
 
1458
{
 
1459
}
 
1460
 
 
1461
CargoPayment::~CargoPayment()
 
1462
{
 
1463
        if (this->CleaningPool()) return;
 
1464
 
 
1465
        this->front->cargo_payment = NULL;
 
1466
 
 
1467
        if (this->visual_profit == 0) {
 
1468
                this->front = NULL;
 
1469
                return;
 
1470
        }
 
1471
 
 
1472
        CompanyID old_company = _current_company;
 
1473
        _current_company = this->front->owner;
 
1474
 
 
1475
        SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit));
 
1476
        this->front->profit_this_year += this->visual_profit << 8;
 
1477
 
 
1478
        if (this->route_profit != 0) {
 
1479
                if (IsLocalCompany() && !PlayVehicleSound(this->front, VSE_LOAD_UNLOAD)) {
 
1480
                        SndPlayVehicleFx(SND_14_CASHTILL, this->front);
 
1481
                }
 
1482
 
 
1483
                ShowCostOrIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, -this->visual_profit);
 
1484
        } else {
 
1485
                ShowFeederIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, this->visual_profit);
 
1486
        }
 
1487
 
 
1488
        _current_company = old_company;
 
1489
 
 
1490
        this->front = NULL;
 
1491
}
 
1492
 
 
1493
/**
 
1494
 * Handle payment for final delivery of the given cargo packet.
 
1495
 * @param cp The cargo packet to pay for.
 
1496
 * @param count The number of packets to pay for.
 
1497
 */
 
1498
void CargoPayment::PayFinalDelivery(CargoPacket *cp, uint count)
 
1499
{
 
1500
        if (this->owner == NULL) {
 
1501
                this->owner = GetCompany(this->front->owner);
 
1502
        }
 
1503
 
 
1504
        /* Handle end of route payment */
 
1505
        Money profit = DeliverGoods(count, this->ct, cp->source, this->current_station, cp->source_xy, cp->days_in_transit, this->owner);
 
1506
        this->route_profit += profit;
 
1507
 
 
1508
        /* The vehicle's profit is whatever route profit there is minus feeder shares. */
 
1509
        this->visual_profit += profit - cp->feeder_share;
 
1510
}
 
1511
 
 
1512
/**
 
1513
 * Handle payment for transfer of the given cargo packet.
 
1514
 * @param cp The cargo packet to pay for.
 
1515
 * @param count The number of packets to pay for.
 
1516
 */
 
1517
void CargoPayment::PayTransfer(CargoPacket *cp, uint count)
 
1518
{
 
1519
        Money profit = GetTransportedGoodsIncome(
 
1520
                count,
 
1521
                /* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */
 
1522
                DistanceManhattan(cp->loaded_at_xy, GetStation(this->current_station)->xy),
 
1523
                cp->days_in_transit,
 
1524
                this->ct);
 
1525
 
 
1526
        this->visual_profit += profit; // accumulate transfer profits for whole vehicle
 
1527
        cp->feeder_share    += profit; // account for the (virtual) profit already made for the cargo packet
 
1528
}
 
1529
 
 
1530
/**
 
1531
 * Prepare the vehicle to be unloaded.
1436
1532
 * @param front_v the vehicle to be unloaded
1437
1533
 */
1438
 
void VehiclePayment(Vehicle *front_v)
 
1534
void PrepareUnload(Vehicle *front_v)
1439
1535
{
1440
 
        int result = 0;
1441
 
 
1442
 
        Money vehicle_profit = 0; // Money paid to the train
1443
 
        Money route_profit   = 0; // The grand total amount for the route. A-D of transfer chain A-B-C-D
1444
 
        Money virtual_profit = 0; // The virtual profit for entire vehicle chain
1445
 
 
1446
 
        StationID last_visited = front_v->last_station_visited;
1447
 
        Station *st = GetStation(last_visited);
1448
 
 
1449
 
        /* The owner of the train wants to be paid */
1450
 
        CompanyID old_company = _current_company;
1451
 
        _current_company = front_v->owner;
1452
 
 
1453
1536
        /* At this moment loading cannot be finished */
1454
1537
        ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED);
1455
1538
 
1456
1539
        /* Start unloading in at the first possible moment */
1457
1540
        front_v->load_unload_time_rem = 1;
1458
1541
 
1459
 
        /* Collect delivered industries */
1460
 
        static SmallIndustryList industry_set;
1461
 
        industry_set.Clear();
1462
 
 
1463
 
        for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
1464
 
                /* No cargo to unload */
1465
 
                if (v->cargo_cap == 0 || v->cargo.Empty() || front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) continue;
1466
 
 
1467
 
                /* All cargo has already been paid for, no need to pay again */
1468
 
                if (!v->cargo.UnpaidCargo()) {
1469
 
                        SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
1470
 
                        continue;
1471
 
                }
1472
 
 
1473
 
                GoodsEntry *ge = &st->goods[v->cargo_type];
1474
 
                const CargoList::List *cargos = v->cargo.Packets();
1475
 
 
1476
 
                for (CargoList::List::const_iterator it = cargos->begin(); it != cargos->end(); it++) {
1477
 
                        CargoPacket *cp = *it;
1478
 
                        if (!cp->paid_for &&
1479
 
                                        cp->source != last_visited &&
1480
 
                                        HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) &&
1481
 
                                        (front_v->current_order.GetUnloadType() & OUFB_TRANSFER) == 0) {
1482
 
                                /* Deliver goods to the station */
1483
 
                                st->time_since_unload = 0;
1484
 
 
1485
 
                                /* handle end of route payment */
1486
 
                                Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit, &industry_set);
1487
 
                                cp->paid_for = true;
1488
 
                                route_profit   += profit; // display amount paid for final route delivery, A-D of a chain A-B-C-D
1489
 
                                vehicle_profit += profit - cp->feeder_share;                    // whole vehicle is not payed for transfers picked up earlier
1490
 
 
1491
 
                                result |= 1;
1492
 
 
1493
 
                                SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
1494
 
                        } else if (front_v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) {
1495
 
                                if (!cp->paid_for && (front_v->current_order.GetUnloadType() & OUFB_TRANSFER) != 0) {
1496
 
                                        Money profit = GetTransportedGoodsIncome(
1497
 
                                                cp->count,
1498
 
                                                /* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */
1499
 
                                                DistanceManhattan(cp->loaded_at_xy, GetStation(last_visited)->xy),
1500
 
                                                cp->days_in_transit,
1501
 
                                                v->cargo_type);
1502
 
 
1503
 
                                        front_v->profit_this_year += profit << 8;
1504
 
                                        virtual_profit   += profit; // accumulate transfer profits for whole vehicle
1505
 
                                        cp->feeder_share += profit; // account for the (virtual) profit already made for the cargo packet
1506
 
                                        cp->paid_for      = true;   // record that the cargo has been paid for to eliminate double counting
1507
 
                                }
1508
 
                                result |= 2;
1509
 
 
 
1542
        if ((front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
 
1543
                for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
 
1544
                        if (v->cargo_cap > 0 && !v->cargo.Empty()) {
1510
1545
                                SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
1511
1546
                        }
1512
1547
                }
1513
 
                v->cargo.InvalidateCache();
1514
 
        }
1515
 
 
1516
 
        /* Call the production machinery of industries only once for every vehicle chain */
1517
 
        const Industry * const *isend = industry_set.End();
1518
 
        for (Industry **iid = industry_set.Begin(); iid != isend; iid++) {
1519
 
                TriggerIndustryProduction(*iid);
1520
 
        }
1521
 
 
1522
 
        if (virtual_profit > 0) {
1523
 
                ShowFeederIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, virtual_profit);
1524
 
        }
1525
 
 
1526
 
        if (route_profit != 0) {
1527
 
                front_v->profit_this_year += vehicle_profit << 8;
1528
 
                SubtractMoneyFromCompany(CommandCost(front_v->GetExpenseType(true), -route_profit));
1529
 
 
1530
 
                if (IsLocalCompany() && !PlayVehicleSound(front_v, VSE_LOAD_UNLOAD)) {
1531
 
                        SndPlayVehicleFx(SND_14_CASHTILL, front_v);
1532
 
                }
1533
 
 
1534
 
                ShowCostOrIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, -vehicle_profit);
1535
 
        }
1536
 
 
1537
 
        _current_company = old_company;
 
1548
        }
 
1549
 
 
1550
        assert(front_v->cargo_payment == NULL);
 
1551
        front_v->cargo_payment = new CargoPayment(front_v);
1538
1552
}
1539
1553
 
1540
1554
/**
1549
1563
{
1550
1564
        assert(v->current_order.IsType(OT_LOADING));
1551
1565
 
 
1566
        assert(v->load_unload_time_rem != 0);
 
1567
 
1552
1568
        /* We have not waited enough time till the next round of loading/unloading */
1553
1569
        if (--v->load_unload_time_rem != 0) {
1554
1570
                if (_settings_game.order.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
1568
1584
                /* The train reversed in the station. Take the "easy" way
1569
1585
                 * out and let the train just leave as it always did. */
1570
1586
                SetBit(v->vehicle_flags, VF_LOADING_FINISHED);
 
1587
                v->load_unload_time_rem = 1;
1571
1588
                return;
1572
1589
        }
1573
1590
 
1583
1600
 
1584
1601
        v->cur_speed = 0;
1585
1602
 
 
1603
        CargoPayment *payment = v->cargo_payment;
 
1604
 
1586
1605
        for (; v != NULL; v = v->Next()) {
1587
1606
                if (v->cargo_cap == 0) continue;
1588
1607
 
1604
1623
                        bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here?
1605
1624
                        bool accepted  = false; // Is the cargo accepted by the station?
1606
1625
 
 
1626
                        payment->SetCargo(v->cargo_type);
 
1627
 
1607
1628
                        if (HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.GetUnloadType() & OUFB_TRANSFER)) {
1608
1629
                                /* The cargo has reached it's final destination, the packets may now be destroyed */
1609
 
                                remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, last_visited);
 
1630
                                remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, payment, last_visited);
1610
1631
 
1611
1632
                                result |= 1;
1612
1633
                                accepted = true;
1618
1639
                         * station is still accepting the cargo in the vehicle. It doesn't
1619
1640
                         * accept cargo that was loaded at the same station. */
1620
1641
                        if (u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER) && (!accepted || v->cargo.Count() == cargo_count)) {
1621
 
                                remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded);
 
1642
                                remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded, u->current_order.GetUnloadType() & OUFB_TRANSFER ? CargoList::MTA_TRANSFER : CargoList::MTA_UNLOAD, payment);
1622
1643
                                SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP);
1623
1644
 
1624
1645
                                result |= 2;
1625
1646
                        } else if (!accepted) {
1626
1647
                                /* The order changed while unloading (unset unload/transfer) or the
1627
 
                                 * station does not accept goods anymore. */
 
1648
                                 * station does not accept our goods. */
1628
1649
                                ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING);
 
1650
 
 
1651
                                /* Say we loaded something, otherwise we'll think we didn't unload
 
1652
                                 * something and we didn't load something, so we must be finished
 
1653
                                 * at this station. Setting the unloaded means that we will get a
 
1654
                                 * retry for loading in the next cycle. */
 
1655
                                anything_unloaded = true;
1629
1656
                                continue;
1630
1657
                        }
1631
1658
 
1651
1678
                /* update stats */
1652
1679
                int t;
1653
1680
                switch (u->type) {
1654
 
                        case VEH_TRAIN: t = u->u.rail.cached_max_speed; break;
1655
 
                        case VEH_ROAD:  t = u->max_speed / 2;           break;
1656
 
                        default:        t = u->max_speed;               break;
 
1681
                        case VEH_TRAIN:    t = u->u.rail.cached_max_speed; break;
 
1682
                        case VEH_ROAD:     t = u->max_speed / 2;           break;
 
1683
                        case VEH_SHIP:     t = u->max_speed;               break;
 
1684
                        case VEH_AIRCRAFT: t = u->max_speed * 10 / 129;    break; // convert to old units
 
1685
                        default: NOT_REACHED();
1657
1686
                }
1658
1687
 
1659
1688
                /* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
1695
1724
                        completely_emptied = false;
1696
1725
                        anything_loaded = true;
1697
1726
 
1698
 
                        ge->cargo.MoveTo(&v->cargo, cap, CargoList::MTA_CARGO_LOAD, st->xy);
 
1727
                        ge->cargo.MoveTo(&v->cargo, cap, CargoList::MTA_CARGO_LOAD, NULL, st->xy);
1699
1728
 
1700
1729
                        st->time_since_load = 0;
1701
1730
                        st->last_vehicle_type = v->type;
1731
1760
 
1732
1761
        v = u;
1733
1762
 
 
1763
        if (!anything_unloaded) delete payment;
 
1764
 
1734
1765
        if (anything_loaded || anything_unloaded) {
1735
1766
                if (_settings_game.order.gradual_loading) {
1736
1767
                        /* The time it takes to load one 'slice' of cargo or passengers depends
1783
1814
                }
1784
1815
        }
1785
1816
 
1786
 
        v->load_unload_time_rem = unloading_time;
 
1817
        /* Always wait at least 1, otherwise we'll wait 'infinitively' long. */
 
1818
        v->load_unload_time_rem = max(1, unloading_time);
1787
1819
 
1788
1820
        if (completely_emptied) {
1789
1821
                TriggerVehicle(v, VEHICLE_TRIGGER_EMPTY);
1807
1839
 */
1808
1840
void LoadUnloadStation(Station *st)
1809
1841
{
 
1842
        /* No vehicle is here... */
 
1843
        if (st->loading_vehicles.empty()) return;
 
1844
 
1810
1845
        int cargo_left[NUM_CARGO];
1811
1846
 
1812
1847
        for (uint i = 0; i < NUM_CARGO; i++) cargo_left[i] = st->goods[i].cargo.Count();
1816
1851
                Vehicle *v = *iter;
1817
1852
                if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left);
1818
1853
        }
 
1854
 
 
1855
        /* Call the production machinery of industries */
 
1856
        const Industry * const *isend = _cargo_delivery_destinations.End();
 
1857
        for (Industry **iid = _cargo_delivery_destinations.Begin(); iid != isend; iid++) {
 
1858
                TriggerIndustryProduction(*iid);
 
1859
        }
 
1860
        _cargo_delivery_destinations.Clear();
1819
1861
}
1820
1862
 
1821
1863
void CompaniesMonthlyLoop()