src/station_cmd.cpp
branchnoai
changeset 9505 9711235f5693
parent 9476 1d1ed96f32ad
child 9517 be1775555bbd
equal deleted inserted replaced
9504:de4993fa3d98 9505:9711235f5693
   350 // Get a mask of the cargo types that the station accepts.
   350 // Get a mask of the cargo types that the station accepts.
   351 static uint GetAcceptanceMask(const Station *st)
   351 static uint GetAcceptanceMask(const Station *st)
   352 {
   352 {
   353 	uint mask = 0;
   353 	uint mask = 0;
   354 
   354 
   355 	for (uint i = 0; i != NUM_CARGO; i++) {
   355 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   356 		if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i;
   356 		if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i;
   357 	}
   357 	}
   358 	return mask;
   358 	return mask;
   359 }
   359 }
   360 
   360 
   523 	} else {
   523 	} else {
   524 		memset(accepts, 0, sizeof(accepts));
   524 		memset(accepts, 0, sizeof(accepts));
   525 	}
   525 	}
   526 
   526 
   527 	// Adjust in case our station only accepts fewer kinds of goods
   527 	// Adjust in case our station only accepts fewer kinds of goods
   528 	for (uint i = 0; i != NUM_CARGO; i++) {
   528 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   529 		uint amt = min(accepts[i], 15);
   529 		uint amt = min(accepts[i], 15);
   530 
   530 
   531 		// Make sure the station can accept the goods type.
   531 		// Make sure the station can accept the goods type.
   532 		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
   532 		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
   533 		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
   533 		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
  2334 	Station *st;
  2334 	Station *st;
  2335 
  2335 
  2336 	FOR_ALL_STATIONS(st) {
  2336 	FOR_ALL_STATIONS(st) {
  2337 		if (st->owner == owner &&
  2337 		if (st->owner == owner &&
  2338 				DistanceManhattan(tile, st->xy) <= radius) {
  2338 				DistanceManhattan(tile, st->xy) <= radius) {
  2339 			for (uint i = 0; i != NUM_CARGO; i++) {
  2339 			for (CargoID i = 0; i < NUM_CARGO; i++) {
  2340 				GoodsEntry* ge = &st->goods[i];
  2340 				GoodsEntry* ge = &st->goods[i];
  2341 
  2341 
  2342 				if (ge->enroute_from != INVALID_STATION) {
  2342 				if (ge->enroute_from != INVALID_STATION) {
  2343 					ge->rating = clamp(ge->rating + amount, 0, 255);
  2343 					ge->rating = clamp(ge->rating + amount, 0, 255);
  2344 				}
  2344 				}
  2345 			}
  2345 			}
  2346 		}
  2346 		}
  2347 	}
  2347 	}
  2348 }
  2348 }
  2349 
  2349 
  2350 static void UpdateStationWaiting(Station *st, int type, uint amount)
  2350 static void UpdateStationWaiting(Station *st, CargoID type, uint amount)
  2351 {
  2351 {
  2352 	SB(st->goods[type].waiting_acceptance, 0, 12,
  2352 	SB(st->goods[type].waiting_acceptance, 0, 12,
  2353 		min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount)
  2353 		min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount)
  2354 	);
  2354 	);
  2355 
  2355 
  2389 
  2389 
  2390 	return 0;
  2390 	return 0;
  2391 }
  2391 }
  2392 
  2392 
  2393 
  2393 
  2394 uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount)
  2394 uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
  2395 {
  2395 {
  2396 	Station* around[8];
  2396 	Station* around[8];
  2397 
  2397 
  2398 	for (uint i = 0; i < lengthof(around); i++) around[i] = NULL;
  2398 	for (uint i = 0; i < lengthof(around); i++) around[i] = NULL;
  2399 
  2399 
  2551 	st->delete_ctr = 0;
  2551 	st->delete_ctr = 0;
  2552 	st->last_vehicle_type = VEH_INVALID;
  2552 	st->last_vehicle_type = VEH_INVALID;
  2553 	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
  2553 	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
  2554 	st->build_date = _date;
  2554 	st->build_date = _date;
  2555 
  2555 
  2556 	for (uint j = 0; j != NUM_CARGO; j++) {
  2556 	for (CargoID j = 0; j < NUM_CARGO; j++) {
  2557 		st->goods[j].waiting_acceptance = 0;
  2557 		st->goods[j].waiting_acceptance = 0;
  2558 		st->goods[j].days_since_pickup = 0;
  2558 		st->goods[j].days_since_pickup = 0;
  2559 		st->goods[j].enroute_from = INVALID_STATION;
  2559 		st->goods[j].enroute_from = INVALID_STATION;
  2560 		st->goods[j].enroute_from_xy = INVALID_TILE;
  2560 		st->goods[j].enroute_from_xy = INVALID_TILE;
  2561 		st->goods[j].rating = INITIAL_STATION_RATING;
  2561 		st->goods[j].rating = INITIAL_STATION_RATING;
  2799 
  2799 
  2800 
  2800 
  2801 static void SaveLoad_STNS(Station *st)
  2801 static void SaveLoad_STNS(Station *st)
  2802 {
  2802 {
  2803 	SlObject(st, _station_desc);
  2803 	SlObject(st, _station_desc);
  2804 	for (uint i = 0; i != NUM_CARGO; i++) {
  2804 	for (CargoID i = 0; i < NUM_CARGO; i++) {
  2805 		SlObject(&st->goods[i], _goods_desc);
  2805 		SlObject(&st->goods[i], _goods_desc);
  2806 	}
  2806 	}
  2807 
  2807 
  2808 	if (st->num_specs != 0) {
  2808 	if (st->num_specs != 0) {
  2809 		/* Allocate speclist memory when loading a game */
  2809 		/* Allocate speclist memory when loading a game */