mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
of magic numbers (tnx to Stumo)
This commit is contained in:
parent
88b94c3c67
commit
3f2d2d8f37
10
macros.h
10
macros.h
|
@ -165,16 +165,6 @@ static inline int FindFirstBit2x64(int value)
|
|||
#define CHANCE16R(a,b,r) ((uint16)(r=Random()) <= (uint16)((65536 * a) / b))
|
||||
#define CHANCE16I(a,b,v) ((uint16)(v) <= (uint16)((65536 * a) / b))
|
||||
|
||||
#define FIND_CATCHMENT_RADIUS(st,rad) \
|
||||
{\
|
||||
if (st->bus_tile || st->lorry_tile || (st->airport_tile && st->airport_type == AT_OILRIG)) rad = 3; \
|
||||
if (st->train_tile || (st->airport_tile && (st->airport_type == AT_HELIPORT || st->airport_type == AT_SMALL))) rad = 4; \
|
||||
if (st->dock_tile || (st->airport_tile && st->airport_type == AT_LARGE)) rad = 5; \
|
||||
if (st->airport_tile && st->airport_type == AT_METROPOLITAN) rad = 6; \
|
||||
if (st->airport_tile && st->airport_type == AT_INTERNATIONAL) rad = 8; }
|
||||
|
||||
|
||||
|
||||
#define BEGIN_TILE_LOOP(var,w,h,tile) \
|
||||
{int h_cur = h; \
|
||||
uint var = tile; \
|
||||
|
|
|
@ -38,6 +38,31 @@ static void MarkStationDirty(Station *st)
|
|||
}
|
||||
}
|
||||
|
||||
/* Calculate the radius of the station. Basicly it is the biggest
|
||||
radius that is available within the station */
|
||||
static byte FindCatchmentRadius(Station *st)
|
||||
{
|
||||
byte ret = 0;
|
||||
|
||||
if (st->bus_tile) ret = max(ret, CA_BUS);
|
||||
if (st->lorry_tile) ret = max(ret, CA_TRUCK);
|
||||
if (st->train_tile) ret = max(ret, CA_TRAIN);
|
||||
if (st->dock_tile) ret = max(ret, CA_DOCK);
|
||||
|
||||
if (st->airport_tile) {
|
||||
switch (st->airport_type) {
|
||||
case AT_OILRIG: ret = max(ret, CA_AIR_OILPAD); break;
|
||||
case AT_SMALL: ret = max(ret, CA_AIR_SMALL); break;
|
||||
case AT_HELIPORT: ret = max(ret, CA_AIR_HELIPORT); break;
|
||||
case AT_LARGE: ret = max(ret, CA_AIR_LARGE); break;
|
||||
case AT_METROPOLITAN: ret = max(ret, CA_AIR_METRO); break;
|
||||
case AT_INTERNATIONAL: ret = max(ret, CA_AIR_INTER); break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define CHECK_STATIONS_ERR ((Station*)-1)
|
||||
|
||||
static Station *GetStationAround(uint tile, int w, int h, int closest_station)
|
||||
|
@ -512,7 +537,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
|
|||
}
|
||||
}
|
||||
if (_patches.modified_catchment) {
|
||||
FIND_CATCHMENT_RADIUS(st,rad)
|
||||
rad = FindCatchmentRadius(st);
|
||||
} else {
|
||||
rad = 4;
|
||||
}
|
||||
|
@ -1966,7 +1991,7 @@ static void DrawTile_Station(TileInfo *ti)
|
|||
if (_display_opt & DO_TRANS_BUILDINGS) {
|
||||
image = (image & 0x3FFF) | 0x03224000;
|
||||
} else {
|
||||
if (image&0x8000) image |= image_or_modificator;
|
||||
if (image&0x8000) image |= image_or_modificator;
|
||||
}
|
||||
|
||||
if ((byte)dtss->delta_z != 0x80) {
|
||||
|
@ -2500,30 +2525,30 @@ uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount)
|
|||
((st->facilities & (byte)~FACIL_BUS_STOP)!=0 || type==CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers
|
||||
((st->facilities & (byte)~FACIL_TRUCK_STOP)!=0 || type!=CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers
|
||||
if (_patches.modified_catchment) {
|
||||
FIND_CATCHMENT_RADIUS(st,rad)
|
||||
rad = FindCatchmentRadius(st);
|
||||
x_min_prod = y_min_prod = 9;
|
||||
x_max_prod = 8 + w_prod;
|
||||
y_max_prod = 8 + h_prod;
|
||||
|
||||
|
||||
x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
|
||||
|
||||
|
||||
if (w_cur < x_min_prod) {
|
||||
x_dist = x_min_prod - w_cur;
|
||||
} else { //save cycles
|
||||
if (w_cur > x_max_prod) x_dist = w_cur - x_max_prod;
|
||||
}
|
||||
|
||||
|
||||
y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
|
||||
if (h_cur < y_min_prod) {
|
||||
y_dist = y_min_prod - h_cur;
|
||||
} else {
|
||||
if (h_cur > y_max_prod) y_dist = h_cur - y_max_prod;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
x_dist = y_dist = 0;
|
||||
}
|
||||
|
||||
|
||||
if ( !(x_dist > rad) && !(y_dist > rad) ) {
|
||||
|
||||
around[i] = st_index;
|
||||
|
|
Loading…
Reference in New Issue