Changeset - r7474:73b6cb64896f
[Not reviewed]
master
0 6 0
rubidium - 17 years ago 2007-08-26 13:55:36
rubidium@openttd.org
(svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
6 files changed with 38 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1426,13 +1426,13 @@ void VehiclePayment(Vehicle *front_v)
 
		const CargoList::List *cargos = v->cargo.Packets();
 

	
 
		for (CargoList::List::const_iterator it = cargos->begin(); it != cargos->end(); it++) {
 
			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;
 

	
 
				/* handle end of route payment */
 
				Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit);
 
@@ -1542,19 +1542,20 @@ static void LoadUnloadVehicle(Vehicle *v
 

	
 
		if (HASBIT(v->vehicle_flags, VF_CARGO_UNLOADING)) {
 
			uint cargo_count = v->cargo.Count();
 
			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 {
 
				/* The order changed while unloading (unset unload/transfer) or the
 
				 * station does not accept goods anymore. */
 
				CLRBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
 
@@ -1625,16 +1626,18 @@ static void LoadUnloadVehicle(Vehicle *v
 
			 * removed; that's how TTDPatch behaves too. --pasky */
 
			completely_empty = false;
 
			anything_loaded = true;
 

	
 
			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;
 
		}
 

	
 
		if (v->cargo.Count() == v->cargo_cap) {
 
			SETBIT(cargo_full, v->cargo_type);
 
		} else {
src/newgrf_station.cpp
Show inline comments
 
@@ -426,13 +426,13 @@ static uint32 StationGetVariable(const R
 

	
 
		case 0x48: { // Accepted cargo types
 
			CargoID cargo_type;
 
			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;
 
		}
 
		case 0x49:
 
			if (!HASBIT(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(tile, false, true, false); SETBIT(_svc.valid, 5); }
 
			return _svc.v49;
 
@@ -464,22 +464,22 @@ static uint32 StationGetVariable(const R
 
		switch (variable) {
 
			case 0x60: return min(ge->cargo.Count(), 4095);
 
			case 0x61: return ge->days_since_pickup;
 
			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;
 
		}
 
	}
 

	
 
	/* Handle cargo variables (deprecated) */
 
	if (variable >= 0x8C && variable <= 0xEC) {
 
		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();
 
			case 5: return g->cargo.DaysInTransit();
 
			case 6: return g->last_speed;
 
			case 7: return g->last_age;
src/oldloader.cpp
Show inline comments
 
@@ -576,18 +576,21 @@ static const OldChunks goods_chunk[] = {
 

	
 
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;
 
}
 

	
 
static const OldChunks station_chunk[] = {
src/station.h
Show inline comments
 
@@ -21,21 +21,26 @@ struct RoadStop;
 
DECLARE_OLD_POOL(Station, Station, 6, 1000)
 
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;
 
	byte last_age;
 
	CargoList cargo; ///< The cargo packets of cargo waiting in this station
 
};
src/station_cmd.cpp
Show inline comments
 
@@ -386,13 +386,13 @@ static void UpdateStationVirtCoordDirty(
 
// Get a mask of the cargo types that the station accepts.
 
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;
 
}
 

	
 
// Items contains the two cargo names that are to be accepted or rejected.
 
// msg is the string id of the message to display.
 
@@ -567,13 +567,13 @@ static void UpdateStationAcceptance(Stat
 
		// Make sure the station can accept the goods type.
 
		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
 
		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
 
				(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.
 
	uint new_acc = GetAcceptanceMask(st);
 
	if (old_acc == new_acc)
 
		return;
 
@@ -2381,16 +2381,18 @@ static void UpdateStationRating(Station 
 

	
 
	GoodsEntry *ge = st->goods;
 
	do {
 
		/* 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;
 

	
 
			{
 
				int b = ge->last_speed;
 
@@ -2516,13 +2518,13 @@ void ModifyStationRatingAround(TileIndex
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner == owner &&
 
				DistanceManhattan(tile, st->xy) <= radius) {
 
			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);
 
				}
 
			}
 
		}
 
	}
 
}
 
@@ -2613,14 +2615,14 @@ uint MoveGoodsToStation(TileIndex tile, 
 
		Station *st = GetStationByTile(cur_tile);
 

	
 
		for (uint i = 0; i != lengthof(around); i++) {
 
			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) {
 
						// min and max coordinates of the producer relative
 
						const int x_min_prod = 9;
 
						const int x_max_prod = 8 + w_prod;
 
@@ -2743,13 +2745,13 @@ void BuildOilRig(TileIndex tile)
 
	st->delete_ctr = 0;
 
	st->last_vehicle_type = VEH_INVALID;
 
	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
 
	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;
 
		st->goods[j].last_age = 255;
 
	}
 

	
 
@@ -2974,13 +2976,13 @@ static uint16 _cargo_source;
 
static uint32 _cargo_source_xy;
 
static uint16 _cargo_days;
 
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),
 
	SLEG_CONDVAR(            _cargo_source,       SLE_FILE_U8 | SLE_VAR_U16,   0, 6),
 
	SLEG_CONDVAR(            _cargo_source,       SLE_UINT16,                  7, 67),
 
	SLEG_CONDVAR(            _cargo_source_xy,    SLE_UINT32,                 44, 67),
 
@@ -3010,27 +3012,26 @@ static void SaveLoad_STNS(Station *st)
 

	
 
	uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
 
	for (CargoID i = 0; i < num_cargo; i++) {
 
		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();
 
				/* In old versions, enroute_from used 0xFF as INVALID_STATION */
 
				cp->source          = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
 
				cp->count           = GB(_waiting_acceptance, 0, 12);
 
				cp->days_in_transit = _cargo_days;
 
				cp->feeder_share    = _cargo_feeder_share;
 
				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;
 
			}
 
		}
 
	}
 

	
 
	if (st->num_specs != 0) {
 
		/* Allocate speclist memory when loading a game */
src/station_gui.cpp
Show inline comments
 
@@ -154,14 +154,14 @@ static int CDECL StationRatingMaxSorter(
 
	const Station* st1 = *(const Station**)a;
 
	const Station* st2 = *(const Station**)b;
 
	byte maxr1 = 0;
 
	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;
 
}
 

	
 
enum StationListFlags {
 
@@ -768,13 +768,13 @@ static void DrawStationViewWindow(Window
 
		bool first = true;
 

	
 
		b = InlineString(b, STR_000C_ACCEPTS);
 

	
 
		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 {
 
					/* Add a comma if this is not the first item */
 
					*b++ = ',';
 
					*b++ = ' ';
 
@@ -794,13 +794,13 @@ static void DrawStationViewWindow(Window
 
		y = 77;
 
		for (CargoID i = 0; i < NUM_CARGO; i++) {
 
			const CargoSpec *cs = GetCargo(i);
 
			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);
 
			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
 
			DrawString(8, y, STR_303D, 0);
 
			y += 10;
0 comments (0 inline, 0 general)