76 return min(best_dist, water ? 0x7F : 0x1FF); |
76 return min(best_dist, water ? 0x7F : 0x1FF); |
77 } |
77 } |
78 |
78 |
79 /** Make an analysis of a tile and check for its belonging to the same |
79 /** Make an analysis of a tile and check for its belonging to the same |
80 * industry, and/or the same grf file |
80 * industry, and/or the same grf file |
81 * @param new_tile TileIndex of the tile to query |
81 * @param tile TileIndex of the tile to query |
82 * @param old_tile TileIndex of the reference tile |
82 * @param i Industry to which to compare the tile to |
83 * @param i Industry to which old_tile belongs to |
|
84 * @return value encoded as per NFO specs */ |
83 * @return value encoded as per NFO specs */ |
85 uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i) |
84 uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i) |
86 { |
85 { |
87 if (IsTileType(new_tile, MP_INDUSTRY)) { // Is this an industry tile? |
86 if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) == i->index) { |
88 |
87 /* No industry and/or the tile does not have the same industry as the one we match it with */ |
89 if (GetIndustryIndex(new_tile) == i->index) { // Does it belong to the same industry? |
88 return 0xFFFF; |
90 IndustryGfx gfx = GetIndustryGfx(new_tile); |
89 } |
91 const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx); |
90 |
92 const IndustryTileSpec *indold = GetIndustryTileSpec(GetIndustryGfx(old_tile)); |
91 IndustryGfx gfx = GetCleanIndustryGfx(tile); |
93 |
92 const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx); |
94 if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type? |
93 const IndustrySpec *indold = GetIndustrySpec(i->type); |
95 /* It is an old tile. We have to see if it's been overriden */ |
94 |
96 if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden? |
95 if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type? |
97 return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile |
96 /* It is an old tile. We have to see if it's been overriden */ |
98 } else { // yes. FInd out if it is from the same grf file or not |
97 if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden? |
99 const IndustryTileSpec *old_tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override); |
98 return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile |
100 |
99 } |
101 if (old_tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { |
100 /* Not overriden */ |
102 return old_tile_ovr->grf_prop.local_id; // same grf file |
101 const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override); |
103 } else { |
102 |
104 return 0xFFFE; // not the same grf file |
103 if (tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { |
105 } |
104 return tile_ovr->grf_prop.local_id; // same grf file |
106 } |
105 } else { |
107 } else { |
106 return 0xFFFE; // not the same grf file |
108 if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ? |
107 } |
109 if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ? |
108 } |
110 return indtsp->grf_prop.local_id; |
109 /* Not an 'old type' tile */ |
111 } else { |
110 if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ? |
112 return 0xFFFE; // Defined in another grf file |
111 if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ? |
113 } |
112 return indtsp->grf_prop.local_id; |
114 } else { // tile has no spritegroup |
113 } else { |
115 return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute |
114 return 0xFFFE; // Defined in another grf file |
116 } |
115 } |
117 } |
116 } |
118 } |
117 /* The tile has no spritegroup */ |
119 } |
118 return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute |
120 |
|
121 return 0xFFFF; // tile is not an industry one or does not belong to the current industry |
|
122 } |
119 } |
123 |
120 |
124 static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) |
121 static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) |
125 { |
122 { |
126 uint32 best_dist = MAX_UVALUE(uint32); |
123 uint32 best_dist = MAX_UVALUE(uint32); |
213 |
210 |
214 /* Layout number */ |
211 /* Layout number */ |
215 case 0x44: return industry->selected_layout; |
212 case 0x44: return industry->selected_layout; |
216 |
213 |
217 /* Get industry ID at offset param */ |
214 /* Get industry ID at offset param */ |
218 case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), tile, industry); |
215 case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), industry); |
219 |
216 |
220 /* Get random tile bits at offset param */ |
217 /* Get random tile bits at offset param */ |
221 case 0x61: |
218 case 0x61: |
222 tile = GetNearbyTile(parameter, tile); |
219 tile = GetNearbyTile(parameter, tile); |
223 return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0; |
220 return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0; |