diff options
author | rubidium <rubidium@openttd.org> | 2007-08-26 13:55:36 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-08-26 13:55:36 +0000 |
commit | a0d37ea7b9e26c7f918883262160e76f004e7e8f (patch) | |
tree | a1ad1c541e93eb8285d8b94ff26ffc3a974a4489 | |
parent | 36c5b4e1ef8f15cc6a79447bc95cffef82d2eb32 (diff) | |
download | openttd-a0d37ea7b9e26c7f918883262160e76f004e7e8f.tar.xz |
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
-rw-r--r-- | src/economy.cpp | 9 | ||||
-rw-r--r-- | src/newgrf_station.cpp | 6 | ||||
-rw-r--r-- | src/oldloader.cpp | 7 | ||||
-rw-r--r-- | src/station.h | 9 | ||||
-rw-r--r-- | src/station_cmd.cpp | 25 | ||||
-rw-r--r-- | src/station_gui.cpp | 8 |
6 files changed, 38 insertions, 26 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index 2c9dc29d5..2a42a13c7 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1429,7 +1429,7 @@ void VehiclePayment(Vehicle *front_v) CargoPacket *cp = *it; if (!cp->paid_for && cp->source != last_visited && - ge->acceptance && + HASBIT(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && (front_v->current_order.flags & OF_TRANSFER) == 0) { /* Deliver goods to the station */ st->time_since_unload = 0; @@ -1545,13 +1545,14 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) uint amount_unloaded = _patches.gradual_loading ? min(cargo_count, load_amount) : cargo_count; bool remaining; // Are there cargo entities in this vehicle that can still be unloaded here? - if (ge->acceptance && !(u->current_order.flags & OF_TRANSFER)) { + if (HASBIT(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE) && !(u->current_order.flags & OF_TRANSFER)) { /* The cargo has reached it's final destination, the packets may now be destroyed */ remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, last_visited); result |= 1; } else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) { remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded); + SETBIT(ge->acceptance_pickup, GoodsEntry::PICKUP); result |= 2; } else { @@ -1628,10 +1629,12 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) ge->cargo.MoveTo(&v->cargo, cap, CargoList::MTA_CARGO_LOAD, st->xy); - unloading_time += cap; + SETBIT(ge->acceptance_pickup, GoodsEntry::PICKUP); st->time_since_load = 0; st->last_vehicle_type = v->type; + unloading_time += cap; + result |= 2; } diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 4e40cacd8..58fd69631 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -429,7 +429,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by uint32 value = 0; for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { - if (st->goods[cargo_type].acceptance) SETBIT(value, cargo_type); + if (HASBIT(st->goods[cargo_type].acceptance_pickup, GoodsEntry::PICKUP)) SETBIT(value, cargo_type); } return value; } @@ -467,7 +467,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by case 0x62: return ge->rating; case 0x63: return ge->cargo.DaysInTransit(); case 0x64: return ge->last_speed | (ge->last_age << 8); - case 0x65: return ge->acceptance << 3; + case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 3; } } @@ -476,7 +476,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by const GoodsEntry *g = &st->goods[GB(variable - 0x8C, 3, 4)]; switch (GB(variable - 0x8C, 0, 3)) { case 0: return g->cargo.Count(); - case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (g->acceptance << 7); + case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 7); case 2: return g->days_since_pickup; case 3: return g->rating; case 4: return g->cargo.Source(); diff --git a/src/oldloader.cpp b/src/oldloader.cpp index 0f494e6a2..5eba924ca 100644 --- a/src/oldloader.cpp +++ b/src/oldloader.cpp @@ -579,12 +579,15 @@ static bool LoadOldGood(LoadgameState *ls, int num) Station *st = GetStation(_current_station_id); GoodsEntry *ge = &st->goods[num]; bool ret = LoadChunk(ls, ge, goods_chunk); - if (ret && GB(_waiting_acceptance, 0, 12) != 0) { + if (!ret) return false; + + SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HASBIT(_waiting_acceptance, 15)); + SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, _cargo_source != 0xFF); + if (GB(_waiting_acceptance, 0, 12) != 0) { CargoPacket *cp = new CargoPacket(); cp->source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; cp->count = GB(_waiting_acceptance, 0, 12); cp->days_in_transit = _cargo_days; - ge->acceptance = HASBIT(_waiting_acceptance, 15); ge->cargo.Append(cp); } return ret; diff --git a/src/station.h b/src/station.h index 5790c0c6a..5f48abec2 100644 --- a/src/station.h +++ b/src/station.h @@ -24,15 +24,20 @@ DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000) static const byte INITIAL_STATION_RATING = 175; struct GoodsEntry { + enum AcceptancePickup { + ACCEPTANCE, + PICKUP + }; + GoodsEntry() : - acceptance(false), + acceptance_pickup(0), days_since_pickup(255), rating(INITIAL_STATION_RATING), last_speed(0), last_age(255) {} - bool acceptance; + byte acceptance_pickup; byte days_since_pickup; byte rating; byte last_speed; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index c01357948..d27e7a667 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -389,7 +389,7 @@ static uint GetAcceptanceMask(const Station *st) uint mask = 0; for (CargoID i = 0; i < NUM_CARGO; i++) { - if (st->goods[i].acceptance) mask |= 1 << i; + if (HASBIT(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) mask |= 1 << i; } return mask; } @@ -570,7 +570,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg) (is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) amt = 0; - st->goods[i].acceptance = (amt >= 8); + SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8); } // Only show a message in case the acceptance was actually changed. @@ -2384,10 +2384,12 @@ static void UpdateStationRating(Station *st) /* Slowly increase the rating back to his original level in the case we * didn't deliver cargo yet to this station. This happens when a bribe * failed while you didn't moved that cargo yet to a station. */ - if (ge->days_since_pickup == 255 && ge->rating < INITIAL_STATION_RATING) + if (!HASBIT(ge->acceptance_pickup, GoodsEntry::PICKUP) && ge->rating < INITIAL_STATION_RATING) { ge->rating++; + } + /* Only change the rating if we are moving this cargo */ - if (ge->last_speed != 0) { + if (HASBIT(ge->acceptance_pickup, GoodsEntry::PICKUP)) { byte_inc_sat(&ge->days_since_pickup); int rating = 0; @@ -2519,7 +2521,7 @@ void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint for (CargoID i = 0; i < NUM_CARGO; i++) { GoodsEntry* ge = &st->goods[i]; - if (ge->days_since_pickup != 255) { + if (ge->acceptance_pickup != 0) { ge->rating = clamp(ge->rating + amount, 0, 255); } } @@ -2616,8 +2618,8 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount) if (around[i] == NULL) { if (!st->IsBuoy() && (st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights - st->goods[type].rating != 0 && st->goods[type].last_speed != 0 && // we actually service the station - (!_patches.selectgoods || st->goods[type].last_speed > 0) && // if last_speed is 0, no vehicle has been there. + st->goods[type].rating != 0 && // when you've got the lowest rating you can get, it's better not to give cargo anymore + (!_patches.selectgoods || st->goods[type].last_speed > 0) && // we are servicing the station (or cargo is dumped on all stations) ((st->facilities & ~FACIL_BUS_STOP) != 0 || IsCargoInClass(type, CC_PASSENGERS)) && // if we have other fac. than a bus stop, or the cargo is passengers ((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 if (_patches.modified_catchment) { @@ -2746,7 +2748,7 @@ void BuildOilRig(TileIndex tile) st->build_date = _date; for (CargoID j = 0; j < NUM_CARGO; j++) { - st->goods[j].acceptance = false; + st->goods[j].acceptance_pickup = 0; st->goods[j].days_since_pickup = 255; st->goods[j].rating = INITIAL_STATION_RATING; st->goods[j].last_speed = 0; @@ -2977,7 +2979,7 @@ static Money _cargo_feeder_share; static const SaveLoad _goods_desc[] = { SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, 0, 67), - SLE_CONDVAR(GoodsEntry, acceptance, SLE_BOOL, 68, SL_MAX_VERSION), + SLE_CONDVAR(GoodsEntry, acceptance_pickup, SLE_UINT8, 68, SL_MAX_VERSION), SLE_CONDNULL(2, 51, 67), SLE_VAR(GoodsEntry, days_since_pickup, SLE_UINT8), SLE_VAR(GoodsEntry, rating, SLE_UINT8), @@ -3013,7 +3015,7 @@ static void SaveLoad_STNS(Station *st) GoodsEntry *ge = &st->goods[i]; SlObject(ge, _goods_desc); if (CheckSavegameVersion(68)) { - ge->acceptance = HASBIT(_waiting_acceptance, 15); + SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HASBIT(_waiting_acceptance, 15)); if (GB(_waiting_acceptance, 0, 12) != 0) { /* Don't construct the packet with station here, because that'll fail with old savegames */ CargoPacket *cp = new CargoPacket(); @@ -3025,9 +3027,8 @@ static void SaveLoad_STNS(Station *st) cp->source_xy = _cargo_source_xy; cp->days_in_transit = _cargo_days; cp->feeder_share = _cargo_feeder_share; + SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1); ge->cargo.Append(cp); - } else { - ge->days_since_pickup = 255; } } } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 00f24ed36..735725fa7 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -157,8 +157,8 @@ static int CDECL StationRatingMaxSorter(const void *a, const void *b) byte maxr2 = 0; for (CargoID j = 0; j < NUM_CARGO; j++) { - if (st1->goods[j].days_since_pickup != 255) maxr1 = max(maxr1, st1->goods[j].rating); - if (st2->goods[j].days_since_pickup != 255) maxr2 = max(maxr2, st2->goods[j].rating); + if (HASBIT(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating); + if (HASBIT(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating); } return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2; @@ -771,7 +771,7 @@ static void DrawStationViewWindow(Window *w) for (CargoID i = 0; i < NUM_CARGO; i++) { if (b >= endof(_userstring) - 5 - 1) break; - if (st->goods[i].acceptance) { + if (HASBIT(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) { if (first) { first = false; } else { @@ -797,7 +797,7 @@ static void DrawStationViewWindow(Window *w) if (!cs->IsValid()) continue; const GoodsEntry *ge = &st->goods[i]; - if (ge->days_since_pickup == 255) continue; + if (!HASBIT(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue; SetDParam(0, cs->name); SetDParam(2, ge->rating * 101 >> 8); |