|
@@ -180,25 +180,25 @@ static uint32 GetNearbyObjectTileInforma
|
|
|
* Get the closest object of a given type.
|
|
|
* @param tile The tile to start searching from.
|
|
|
* @param type The type of the object to search for.
|
|
|
* @param current The current object (to ignore).
|
|
|
* @return The distance to the closest object.
|
|
|
*/
|
|
|
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
|
|
|
{
|
|
|
uint32 best_dist = UINT32_MAX;
|
|
|
for (const Object *o : Object::Iterate()) {
|
|
|
if (o->type != type || o == current) continue;
|
|
|
|
|
|
best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile));
|
|
|
best_dist = std::min(best_dist, DistanceManhattan(tile, o->location.tile));
|
|
|
}
|
|
|
|
|
|
return best_dist;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Implementation of var 65
|
|
|
* @param local_id Parameter given to the callback, which is the set id, or the local id, in our terminology.
|
|
|
* @param grfid The object's GRFID.
|
|
|
* @param tile The tile to look from.
|
|
|
* @param current Object for which the inquiry is made
|
|
|
* @return The formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)
|
|
@@ -217,25 +217,25 @@ static uint32 GetCountAndDistanceOfClose
|
|
|
case 0xFFFFFFFF: // current grf
|
|
|
grf_id = grfid;
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
default: // use the grfid specified in register 100h
|
|
|
idx = _object_mngr.GetID(local_id, grf_id);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* If the object type is invalid, there is none and the closest is far away. */
|
|
|
if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;
|
|
|
|
|
|
return Object::GetTypeCount(idx) << 16 | min(GetClosestObject(tile, idx, current), 0xFFFF);
|
|
|
return Object::GetTypeCount(idx) << 16 | std::min(GetClosestObject(tile, idx, current), 0xFFFFu);
|
|
|
}
|
|
|
|
|
|
/** Used by the resolver to get values for feature 0F deterministic spritegroups. */
|
|
|
/* virtual */ uint32 ObjectScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
|
|
|
{
|
|
|
/* We get the town from the object, or we calculate the closest
|
|
|
* town if we need to when there's no object. */
|
|
|
const Town *t = nullptr;
|
|
|
|
|
|
if (this->obj == nullptr) {
|
|
|
switch (variable) {
|
|
|
/* Allow these when there's no object. */
|
|
@@ -292,28 +292,28 @@ static uint32 GetCountAndDistanceOfClose
|
|
|
case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
|
|
|
|
|
|
/* Construction date */
|
|
|
case 0x42: return this->obj->build_date;
|
|
|
|
|
|
/* Animation counter */
|
|
|
case 0x43: return GetAnimationFrame(this->tile);
|
|
|
|
|
|
/* Object founder information */
|
|
|
case 0x44: return GetTileOwner(this->tile);
|
|
|
|
|
|
/* Get town zone and Manhattan distance of closest town */
|
|
|
case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | min(DistanceManhattan(this->tile, t->xy), 0xFFFF);
|
|
|
case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu);
|
|
|
|
|
|
/* Get square of Euclidian distance of closes town */
|
|
|
case 0x46: return GetTownRadiusGroup(t, this->tile) << 16 | min(DistanceSquare(this->tile, t->xy), 0xFFFF);
|
|
|
case 0x46: return GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceSquare(this->tile, t->xy), 0xFFFFu);
|
|
|
|
|
|
/* Object colour */
|
|
|
case 0x47: return this->obj->colour;
|
|
|
|
|
|
/* Object view */
|
|
|
case 0x48: return this->obj->view;
|
|
|
|
|
|
/* Get object ID at offset param */
|
|
|
case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
|
|
|
|
|
|
/* Get random tile bits at offset param */
|
|
|
case 0x61: {
|