src/economy.cpp
changeset 10081 e46b9eb2f9c1
parent 9339 daaa2adbaf99
child 10109 2c2afb6c4ea1
equal deleted inserted replaced
10080:e0a9b92ed875 10081:e46b9eb2f9c1
  1487 		for (CargoList::List::const_iterator it = cargos->begin(); it != cargos->end(); it++) {
  1487 		for (CargoList::List::const_iterator it = cargos->begin(); it != cargos->end(); it++) {
  1488 			CargoPacket *cp = *it;
  1488 			CargoPacket *cp = *it;
  1489 			if (!cp->paid_for &&
  1489 			if (!cp->paid_for &&
  1490 					cp->source != last_visited &&
  1490 					cp->source != last_visited &&
  1491 					HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) &&
  1491 					HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) &&
  1492 					(front_v->current_order.GetUnloadType() & OFB_TRANSFER) == 0) {
  1492 					(front_v->current_order.GetUnloadType() & OUFB_TRANSFER) == 0) {
  1493 				/* Deliver goods to the station */
  1493 				/* Deliver goods to the station */
  1494 				st->time_since_unload = 0;
  1494 				st->time_since_unload = 0;
  1495 
  1495 
  1496 				/* handle end of route payment */
  1496 				/* handle end of route payment */
  1497 				Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit);
  1497 				Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit);
  1500 				vehicle_profit += profit - cp->feeder_share;                    // whole vehicle is not payed for transfers picked up earlier
  1500 				vehicle_profit += profit - cp->feeder_share;                    // whole vehicle is not payed for transfers picked up earlier
  1501 
  1501 
  1502 				result |= 1;
  1502 				result |= 1;
  1503 
  1503 
  1504 				SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
  1504 				SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
  1505 			} else if (front_v->current_order.GetUnloadType() & (OFB_UNLOAD | OFB_TRANSFER)) {
  1505 			} else if (front_v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) {
  1506 				if (!cp->paid_for && (front_v->current_order.GetUnloadType() & OFB_TRANSFER) != 0) {
  1506 				if (!cp->paid_for && (front_v->current_order.GetUnloadType() & OUFB_TRANSFER) != 0) {
  1507 					Money profit = GetTransportedGoodsIncome(
  1507 					Money profit = GetTransportedGoodsIncome(
  1508 						cp->count,
  1508 						cp->count,
  1509 						/* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */
  1509 						/* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */
  1510 						DistanceManhattan(cp->loaded_at_xy, GetStation(last_visited)->xy),
  1510 						DistanceManhattan(cp->loaded_at_xy, GetStation(last_visited)->xy),
  1511 						cp->days_in_transit,
  1511 						cp->days_in_transit,
  1554 {
  1554 {
  1555 	assert(v->current_order.IsType(OT_LOADING));
  1555 	assert(v->current_order.IsType(OT_LOADING));
  1556 
  1556 
  1557 	/* We have not waited enough time till the next round of loading/unloading */
  1557 	/* We have not waited enough time till the next round of loading/unloading */
  1558 	if (--v->load_unload_time_rem != 0) {
  1558 	if (--v->load_unload_time_rem != 0) {
  1559 		if (_patches.improved_load && HasBit(v->current_order.GetLoadType(), OF_FULL_LOAD)) {
  1559 		if (_patches.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
  1560 			/* 'Reserve' this cargo for this vehicle, because we were first. */
  1560 			/* 'Reserve' this cargo for this vehicle, because we were first. */
  1561 			for (; v != NULL; v = v->Next()) {
  1561 			for (; v != NULL; v = v->Next()) {
  1562 				if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count();
  1562 				if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count();
  1563 			}
  1563 			}
  1564 		}
  1564 		}
  1602 		if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING)) {
  1602 		if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING)) {
  1603 			uint cargo_count = v->cargo.Count();
  1603 			uint cargo_count = v->cargo.Count();
  1604 			uint amount_unloaded = _patches.gradual_loading ? min(cargo_count, load_amount) : cargo_count;
  1604 			uint amount_unloaded = _patches.gradual_loading ? min(cargo_count, load_amount) : cargo_count;
  1605 			bool remaining; // Are there cargo entities in this vehicle that can still be unloaded here?
  1605 			bool remaining; // Are there cargo entities in this vehicle that can still be unloaded here?
  1606 
  1606 
  1607 			if (HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.GetUnloadType() & OFB_TRANSFER)) {
  1607 			if (HasBit(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.GetUnloadType() & OUFB_TRANSFER)) {
  1608 				/* The cargo has reached it's final destination, the packets may now be destroyed */
  1608 				/* 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);
  1609 				remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, last_visited);
  1610 
  1610 
  1611 				result |= 1;
  1611 				result |= 1;
  1612 			} else if (u->current_order.GetUnloadType() & (OFB_UNLOAD | OFB_TRANSFER)) {
  1612 			} else if (u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) {
  1613 				remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded);
  1613 				remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded);
  1614 				SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP);
  1614 				SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP);
  1615 
  1615 
  1616 				result |= 2;
  1616 				result |= 2;
  1617 			} else {
  1617 			} else {
  1636 
  1636 
  1637 			continue;
  1637 			continue;
  1638 		}
  1638 		}
  1639 
  1639 
  1640 		/* Do not pick up goods that we unloaded */
  1640 		/* Do not pick up goods that we unloaded */
  1641 		if (u->current_order.GetUnloadType() & OFB_UNLOAD) continue;
  1641 		if (u->current_order.GetUnloadType() & OUFB_UNLOAD) continue;
  1642 
  1642 
  1643 		/* update stats */
  1643 		/* update stats */
  1644 		int t;
  1644 		int t;
  1645 		switch (u->type) {
  1645 		switch (u->type) {
  1646 			case VEH_TRAIN: t = u->u.rail.cached_max_speed; break;
  1646 			case VEH_TRAIN: t = u->u.rail.cached_max_speed; break;
  1708 
  1708 
  1709 	/* We update these variables here, so gradual loading still fills
  1709 	/* We update these variables here, so gradual loading still fills
  1710 	 * all wagons at the same time instead of using the same 'improved'
  1710 	 * all wagons at the same time instead of using the same 'improved'
  1711 	 * loading algorithm for the wagons (only fill wagon when there is
  1711 	 * loading algorithm for the wagons (only fill wagon when there is
  1712 	 * enough to fill the previous wagons) */
  1712 	 * enough to fill the previous wagons) */
  1713 	if (_patches.improved_load && HasBit(u->current_order.GetLoadType(), OF_FULL_LOAD)) {
  1713 	if (_patches.improved_load && (u->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
  1714 		/* Update left cargo */
  1714 		/* Update left cargo */
  1715 		for (v = u; v != NULL; v = v->Next()) {
  1715 		for (v = u; v != NULL; v = v->Next()) {
  1716 			if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count();
  1716 			if (v->cargo_cap != 0) cargo_left[v->cargo_type] -= v->cargo_cap - v->cargo.Count();
  1717 		}
  1717 		}
  1718 	}
  1718 	}
  1727 
  1727 
  1728 			unloading_time = gradual_loading_wait_time[v->type];
  1728 			unloading_time = gradual_loading_wait_time[v->type];
  1729 		}
  1729 		}
  1730 	} else {
  1730 	} else {
  1731 		bool finished_loading = true;
  1731 		bool finished_loading = true;
  1732 		if (HasBit(v->current_order.GetLoadType(), OF_FULL_LOAD)) {
  1732 		if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) {
  1733 			if (_patches.full_load_any) {
  1733 			if (_patches.full_load_any) {
  1734 				/* if the aircraft carries passengers and is NOT full, then
  1734 				/* if the aircraft carries passengers and is NOT full, then
  1735 				 * continue loading, no matter how much mail is in */
  1735 				 * continue loading, no matter how much mail is in */
  1736 				if ((v->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS) && v->cargo_cap != v->cargo.Count()) ||
  1736 				if ((v->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS) && v->cargo_cap != v->cargo.Count()) ||
  1737 						(cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are stull non-full cargos
  1737 						(cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are stull non-full cargos