uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const { switch (variable) { case 0x48: { // Accepted cargo types CargoID cargo_type; uint32 value = 0; for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { if (HasBit(this->goods[cargo_type].acceptance_pickup, GoodsEntry::PICKUP)) SetBit(value, cargo_type); } return value; } case 0x8A: return this->had_vehicle_of_type; case 0xF1: return (this->airport.tile != INVALID_TILE) ? this->airport.GetSpec()->ttd_airport_type : ATP_TTDP_LARGE; case 0xF2: return (this->truck_stops != NULL) ? this->truck_stops->status : 0; case 0xF3: return (this->bus_stops != NULL) ? this->bus_stops->status : 0; case 0xF6: return this->airport.flags; case 0xF7: return GB(this->airport.flags, 8, 8); } /* Handle cargo variables with parameter, 0x60 to 0x65 */ if (variable >= 0x60 && variable <= 0x65) { CargoID c = GetCargoTranslation(parameter, object->u.station.statspec->grf_prop.grffile); if (c == CT_INVALID) return 0; const GoodsEntry *ge = &this->goods[c]; 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 GB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 3; } } /* Handle cargo variables (deprecated) */ if (variable >= 0x8C && variable <= 0xEC) { const GoodsEntry *g = &this->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) | (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; } } DEBUG(grf, 1, "Unhandled station variable 0x%X", variable); *available = false; return UINT_MAX; }
/** * @note Used by the resolver to get values for feature 07 deterministic spritegroups. */ /* virtual */ uint32 HouseScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const { switch (variable) { /* Construction stage. */ case 0x40: return (IsTileType(this->tile, MP_HOUSE) ? GetHouseBuildingStage(this->tile) : 0) | TileHash2Bit(TileX(this->tile), TileY(this->tile)) << 2; /* Building age. */ case 0x41: return IsTileType(this->tile, MP_HOUSE) ? GetHouseAge(this->tile) : 0; /* Town zone */ case 0x42: return GetTownRadiusGroup(this->town, this->tile); /* Terrain type */ case 0x43: return GetTerrainType(this->tile); /* Number of this type of building on the map. */ case 0x44: return GetNumHouses(this->house_id, this->town); /* Whether the town is being created or just expanded. */ case 0x45: return _generating_world ? 1 : 0; /* Current animation frame. */ case 0x46: return IsTileType(this->tile, MP_HOUSE) ? GetAnimationFrame(this->tile) : 0; /* Position of the house */ case 0x47: return TileY(this->tile) << 16 | TileX(this->tile); /* Building counts for old houses with id = parameter. */ case 0x60: return parameter < NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0; /* Building counts for new houses with id = parameter. */ case 0x61: { const HouseSpec *hs = HouseSpec::Get(this->house_id); if (hs->grf_prop.grffile == NULL) return 0; HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grffile->grfid); return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town); } /* Land info for nearby tiles. */ case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro->grffile->grf_version >= 8); /* Current animation frame of nearby house tiles */ case 0x63: { TileIndex testtile = GetNearbyTile(parameter, this->tile); return IsTileType(testtile, MP_HOUSE) ? GetAnimationFrame(testtile) : 0; } /* Cargo acceptance history of nearby stations */ case 0x64: { CargoID cid = GetCargoTranslation(parameter, this->ro->grffile); if (cid == CT_INVALID) return 0; /* Extract tile offset. */ int8 x_offs = GB(GetRegister(0x100), 0, 8); int8 y_offs = GB(GetRegister(0x100), 8, 8); TileIndex testtile = TILE_MASK(this->tile + TileDiffXY(x_offs, y_offs)); StationFinder stations(TileArea(testtile, 1, 1)); const StationList *sl = stations.GetStations(); /* Collect acceptance stats. */ uint32 res = 0; for (Station * const * st_iter = sl->Begin(); st_iter != sl->End(); st_iter++) { const Station *st = *st_iter; if (HasBit(st->goods[cid].acceptance_pickup, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0); if (HasBit(st->goods[cid].acceptance_pickup, GoodsEntry::GES_LAST_MONTH)) SetBit(res, 1); if (HasBit(st->goods[cid].acceptance_pickup, GoodsEntry::GES_CURRENT_MONTH)) SetBit(res, 2); if (HasBit(st->goods[cid].acceptance_pickup, GoodsEntry::GES_ACCEPTED_BIGTICK)) SetBit(res, 3); } /* Cargo triggered CB 148? */ if (HasBit(this->watched_cargo_triggers, cid)) SetBit(res, 4); return res; } /* Distance test for some house types */ case 0x65: return GetDistanceFromNearbyHouse(parameter, this->tile, this->house_id); /* Class and ID of nearby house tile */ case 0x66: { TileIndex testtile = GetNearbyTile(parameter, this->tile); if (!IsTileType(testtile, MP_HOUSE)) return 0xFFFFFFFF; HouseSpec *hs = HouseSpec::Get(GetHouseType(testtile)); /* Information about the grf local classid if the house has a class */ uint houseclass = 0; if (hs->class_id != HOUSE_NO_CLASS) { houseclass = (hs->grf_prop.grffile == this->ro->grffile ? 1 : 2) << 8; houseclass |= _class_mapping[hs->class_id].class_id; } /* old house type or grf-local houseid */ uint local_houseid = 0; if (this->house_id < NEW_HOUSE_OFFSET) { local_houseid = this->house_id; } else { local_houseid = (hs->grf_prop.grffile == this->ro->grffile ? 1 : 2) << 8; local_houseid |= hs->grf_prop.local_id; } return houseclass << 16 | local_houseid; } /* GRFID of nearby house tile */ case 0x67: { TileIndex testtile = GetNearbyTile(parameter, this->tile); if (!IsTileType(testtile, MP_HOUSE)) return 0xFFFFFFFF; HouseID house_id = GetHouseType(testtile); if (house_id < NEW_HOUSE_OFFSET) return 0; /* Checking the grffile information via HouseSpec doesn't work * in case the newgrf was removed. */ return _house_mngr.GetGRFID(house_id); } } DEBUG(grf, 1, "Unhandled house variable 0x%X", variable); *available = false; return UINT_MAX; }
uint32 Station::GetNewGRFVariable(const ResolverObject &object, byte variable, byte parameter, bool *available) const { switch (variable) { case 0x48: { // Accepted cargo types CargoID cargo_type; uint32 value = 0; for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { if (HasBit(this->goods[cargo_type].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(value, cargo_type); } return value; } case 0x8A: return this->had_vehicle_of_type; case 0xF1: return (this->airport.tile != INVALID_TILE) ? this->airport.GetSpec()->ttd_airport_type : ATP_TTDP_LARGE; case 0xF2: return (this->truck_stops != NULL) ? this->truck_stops->status : 0; case 0xF3: return (this->bus_stops != NULL) ? this->bus_stops->status : 0; case 0xF6: return this->airport.flags; case 0xF7: return GB(this->airport.flags, 8, 8); } /* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */ if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) { CargoID c = GetCargoTranslation(parameter, object.grffile); if (c == CT_INVALID) { switch (variable) { case 0x62: return 0xFFFFFFFF; case 0x64: return 0xFF00; default: return 0; } } const GoodsEntry *ge = &this->goods[c]; switch (variable) { case 0x60: return min(ge->cargo.TotalCount(), 4095); case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0; case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF; case 0x63: return ge->cargo.DaysInTransit(); case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00; case 0x65: return GB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1) << 3; case 0x69: { assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 1 == (int)GoodsEntry::GES_LAST_MONTH); assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 2 == (int)GoodsEntry::GES_CURRENT_MONTH); assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 3 == (int)GoodsEntry::GES_ACCEPTED_BIGTICK); return GB(ge->status, GoodsEntry::GES_EVER_ACCEPTED, 4); } } } /* Handle cargo variables (deprecated) */ if (variable >= 0x8C && variable <= 0xEC) { const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)]; switch (GB(variable - 0x8C, 0, 3)) { case 0: return g->cargo.TotalCount(); case 1: return GB(min(g->cargo.TotalCount(), 4095), 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7); case 2: return g->time_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; } } DEBUG(grf, 1, "Unhandled station variable 0x%X", variable); *available = false; return UINT_MAX; }