mirror of https://github.com/OpenTTD/OpenTTD
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
parent
e4dc1f460b
commit
981bf52bdd
|
@ -1421,15 +1421,8 @@ static void HandleAircraftLoading(Vehicle *v, int mode)
|
||||||
if (mode != 0) return;
|
if (mode != 0) return;
|
||||||
if (--v->load_unload_time_rem != 0) return;
|
if (--v->load_unload_time_rem != 0) return;
|
||||||
|
|
||||||
if (CanFillVehicle(v) && (
|
if (CanFillVehicle(v)) {
|
||||||
v->current_order.flags & OF_FULL_LOAD ||
|
LoadUnloadVehicle(v);
|
||||||
(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED))
|
|
||||||
)) {
|
|
||||||
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
|
|
||||||
if (LoadUnloadVehicle(v, false)) {
|
|
||||||
InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
|
|
||||||
v->MarkDirty();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1381,11 +1381,8 @@ static bool LoadWait(const Vehicle* v, const Vehicle* u)
|
||||||
/**
|
/**
|
||||||
* Performs the vehicle payment _and_ marks the vehicle to be unloaded.
|
* Performs the vehicle payment _and_ marks the vehicle to be unloaded.
|
||||||
* @param front_v the vehicle to be unloaded
|
* @param front_v the vehicle to be unloaded
|
||||||
* @return what windows need to be updated;
|
|
||||||
* bit 0 set: only vehicle details,
|
|
||||||
* bit 1 set: vehicle details and station details
|
|
||||||
*/
|
*/
|
||||||
static int VehiclePayment(Vehicle *front_v)
|
void VehiclePayment(Vehicle *front_v)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
@ -1401,10 +1398,22 @@ static int VehiclePayment(Vehicle *front_v)
|
||||||
StationID last_visited = front_v->last_station_visited;
|
StationID last_visited = front_v->last_station_visited;
|
||||||
Station *st = GetStation(last_visited);
|
Station *st = GetStation(last_visited);
|
||||||
|
|
||||||
|
/* The owner of the train wants to be paid */
|
||||||
|
PlayerID old_player = _current_player;
|
||||||
|
_current_player = front_v->owner;
|
||||||
|
|
||||||
|
/* At this moment loading cannot be finished */
|
||||||
|
CLRBIT(front_v->vehicle_flags, VF_LOADING_FINISHED);
|
||||||
|
|
||||||
|
/* Start unloading in at the first possible moment */
|
||||||
|
front_v->load_unload_time_rem = 1;
|
||||||
|
|
||||||
for (Vehicle *v = front_v; v != NULL; v = v->next) {
|
for (Vehicle *v = front_v; v != NULL; v = v->next) {
|
||||||
|
/* No cargo to unload */
|
||||||
if (v->cargo_cap == 0) continue;
|
if (v->cargo_cap == 0) continue;
|
||||||
|
|
||||||
SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
|
SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
|
||||||
|
/* All cargo has already been paid for, no need to pay again */
|
||||||
if (v->cargo_count == v->cargo_paid_for) continue;
|
if (v->cargo_count == v->cargo_paid_for) continue;
|
||||||
|
|
||||||
GoodsEntry *ge = &st->goods[v->cargo_type];
|
GoodsEntry *ge = &st->goods[v->cargo_type];
|
||||||
|
@ -1465,17 +1474,17 @@ static int VehiclePayment(Vehicle *front_v)
|
||||||
ShowCostOrIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, -total_veh_profit);
|
ShowCostOrIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, -total_veh_profit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
_current_player = old_player;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoadUnloadVehicle(Vehicle *v, bool just_arrived)
|
int LoadUnloadVehicle(Vehicle *v)
|
||||||
{
|
{
|
||||||
int unloading_time = 20;
|
int unloading_time = 20;
|
||||||
Vehicle *u = v;
|
Vehicle *u = v;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int t;
|
int t;
|
||||||
uint count, cap;
|
uint count, cap;
|
||||||
PlayerID old_player;
|
|
||||||
bool completely_empty = true;
|
bool completely_empty = true;
|
||||||
byte load_amount;
|
byte load_amount;
|
||||||
bool anything_loaded = false;
|
bool anything_loaded = false;
|
||||||
|
@ -1491,14 +1500,9 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived)
|
||||||
* enabling though. */
|
* enabling though. */
|
||||||
SETBIT(v->vehicle_flags, VF_LOADING_FINISHED);
|
SETBIT(v->vehicle_flags, VF_LOADING_FINISHED);
|
||||||
|
|
||||||
old_player = _current_player;
|
|
||||||
_current_player = v->owner;
|
|
||||||
|
|
||||||
StationID last_visited = v->last_station_visited;
|
StationID last_visited = v->last_station_visited;
|
||||||
Station *st = GetStation(last_visited);
|
Station *st = GetStation(last_visited);
|
||||||
|
|
||||||
if (just_arrived) result |= VehiclePayment(v);
|
|
||||||
|
|
||||||
for (; v != NULL; v = v->next) {
|
for (; v != NULL; v = v->next) {
|
||||||
GoodsEntry* ge;
|
GoodsEntry* ge;
|
||||||
load_amount = EngInfo(v->engine_type)->load_amount;
|
load_amount = EngInfo(v->engine_type)->load_amount;
|
||||||
|
@ -1596,7 +1600,10 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived)
|
||||||
|
|
||||||
/* Skip loading this vehicle if another train/vehicle is already handling
|
/* Skip loading this vehicle if another train/vehicle is already handling
|
||||||
* the same cargo type at this station */
|
* the same cargo type at this station */
|
||||||
if (_patches.improved_load && (u->current_order.flags & OF_FULL_LOAD) && LoadWait(v,u)) continue;
|
if (_patches.improved_load && (u->current_order.flags & OF_FULL_LOAD) && LoadWait(v,u)) {
|
||||||
|
CLRBIT(u->vehicle_flags, VF_LOADING_FINISHED);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: Regarding this, when we do gradual loading, we
|
/* TODO: Regarding this, when we do gradual loading, we
|
||||||
* should first unload all vehicles and then start
|
* should first unload all vehicles and then start
|
||||||
|
@ -1673,13 +1680,15 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
|
InvalidateWindow(v->GetVehicleListWindowClass(), v->owner);
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
||||||
|
|
||||||
st->MarkTilesDirty();
|
st->MarkTilesDirty();
|
||||||
|
v->MarkDirty();
|
||||||
|
|
||||||
if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited);
|
if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited);
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_player = old_player;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,4 +68,6 @@ void DeleteSubsidyWithStation(StationID index);
|
||||||
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type);
|
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type);
|
||||||
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount);
|
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount);
|
||||||
|
|
||||||
|
void VehiclePayment(Vehicle *front_v);
|
||||||
|
|
||||||
#endif /* ECONOMY_H */
|
#endif /* ECONOMY_H */
|
||||||
|
|
|
@ -761,13 +761,8 @@ static void HandleRoadVehLoading(Vehicle *v)
|
||||||
|
|
||||||
if (--v->load_unload_time_rem != 0) return;
|
if (--v->load_unload_time_rem != 0) return;
|
||||||
|
|
||||||
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD ||
|
if (CanFillVehicle(v)) {
|
||||||
(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED)))) {
|
LoadUnloadVehicle(v);
|
||||||
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
|
|
||||||
if (LoadUnloadVehicle(v, false)) {
|
|
||||||
InvalidateWindow(WC_ROADVEH_LIST, v->owner);
|
|
||||||
v->MarkDirty();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -306,15 +306,8 @@ static void HandleShipLoading(Vehicle *v)
|
||||||
case OT_LOADING: {
|
case OT_LOADING: {
|
||||||
if (--v->load_unload_time_rem != 0) return;
|
if (--v->load_unload_time_rem != 0) return;
|
||||||
|
|
||||||
if (CanFillVehicle(v) && (
|
if (CanFillVehicle(v)) {
|
||||||
v->current_order.flags & OF_FULL_LOAD ||
|
LoadUnloadVehicle(v);
|
||||||
(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED))
|
|
||||||
)) {
|
|
||||||
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
|
|
||||||
if (LoadUnloadVehicle(v, false)) {
|
|
||||||
InvalidateWindow(WC_SHIPS_LIST, v->owner);
|
|
||||||
v->MarkDirty();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayShipSound(v);
|
PlayShipSound(v);
|
||||||
|
|
|
@ -2544,16 +2544,8 @@ static void HandleTrainLoading(Vehicle *v, bool mode)
|
||||||
|
|
||||||
if (--v->load_unload_time_rem) return;
|
if (--v->load_unload_time_rem) return;
|
||||||
|
|
||||||
if (CanFillVehicle(v) && (
|
if (CanFillVehicle(v)) {
|
||||||
v->current_order.flags & OF_FULL_LOAD ||
|
LoadUnloadVehicle(v);
|
||||||
(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED))
|
|
||||||
)) {
|
|
||||||
v->u.rail.days_since_order_progr = 0; // Prevent a train lost message for full loading trains
|
|
||||||
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
|
|
||||||
if (LoadUnloadVehicle(v, false)) {
|
|
||||||
InvalidateWindow(WC_TRAINS_LIST, v->owner);
|
|
||||||
v->MarkDirty();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "newgrf_engine.h"
|
#include "newgrf_engine.h"
|
||||||
#include "newgrf_sound.h"
|
#include "newgrf_sound.h"
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
|
#include "economy.h"
|
||||||
|
|
||||||
#define INVALID_COORD (-0x8000)
|
#define INVALID_COORD (-0x8000)
|
||||||
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6))
|
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6))
|
||||||
|
@ -741,6 +742,7 @@ static bool CanFillVehicle_FullLoadAny(Vehicle *v)
|
||||||
return keep_loading || (not_full && (full & ~not_full) == 0);
|
return keep_loading || (not_full && (full & ~not_full) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CanFillVehicle(Vehicle *v)
|
bool CanFillVehicle(Vehicle *v)
|
||||||
{
|
{
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
|
@ -2971,11 +2973,15 @@ void Vehicle::BeginLoading()
|
||||||
GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
|
GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
|
||||||
|
|
||||||
SET_EXPENSES_TYPE(this->GetExpenseType(true));
|
SET_EXPENSES_TYPE(this->GetExpenseType(true));
|
||||||
if (LoadUnloadVehicle(this, true) != 0) {
|
VehiclePayment(this);
|
||||||
InvalidateWindow(this->GetVehicleListWindowClass(), this->owner);
|
|
||||||
this->MarkDirty();
|
InvalidateWindow(this->GetVehicleListWindowClass(), this->owner);
|
||||||
}
|
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR);
|
||||||
|
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||||
|
InvalidateWindow(WC_STATION_VIEW, this->last_station_visited);
|
||||||
|
|
||||||
|
GetStation(this->last_station_visited)->MarkTilesDirty();
|
||||||
|
this->MarkDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vehicle::LeaveStation()
|
void Vehicle::LeaveStation()
|
||||||
|
|
|
@ -508,7 +508,7 @@ void ShowAircraftViewWindow(const Vehicle* v);
|
||||||
|
|
||||||
UnitID GetFreeUnitNumber(byte type);
|
UnitID GetFreeUnitNumber(byte type);
|
||||||
|
|
||||||
int LoadUnloadVehicle(Vehicle *v, bool just_arrived);
|
int LoadUnloadVehicle(Vehicle *v);
|
||||||
|
|
||||||
void TrainConsistChanged(Vehicle *v);
|
void TrainConsistChanged(Vehicle *v);
|
||||||
void TrainPowerChanged(Vehicle *v);
|
void TrainPowerChanged(Vehicle *v);
|
||||||
|
|
Loading…
Reference in New Issue