41 const HouseSpec *hs = HouseSpec::Get(house_id);
58 CallbackID callback, uint32 param1, uint32 param2,
59 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
61 house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
62 town_scope(*this, town, not_yet_constructed)
67 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
70 for (
int i = 1; i !=
lengthof(_class_mapping); i++) {
81 return HOUSE_NO_CLASS;
84 void InitializeBuildingCounts()
86 memset(&_building_counts, 0,
sizeof(_building_counts));
107 _building_counts.id_count[house_id]++;
109 if (class_id == HOUSE_NO_CLASS)
return;
112 _building_counts.class_count[class_id]++;
128 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
130 if (class_id == HOUSE_NO_CLASS)
return;
133 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
150 static uint32 GetNumHouses(
HouseID house_id,
const Town *town)
152 uint8 map_id_count, town_id_count, map_class_count, town_class_count;
155 map_id_count =
ClampU(_building_counts.id_count[house_id], 0, 255);
156 map_class_count =
ClampU(_building_counts.class_count[class_id], 0, 255);
160 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
192 const HouseSpec *hs = HouseSpec::Get(house);
197 if (north_tile == nbhd->
north_tile)
return false;
216 const HouseSpec *hs = HouseSpec::Get(house);
221 if (north_tile == nbhd->
north_tile)
return false;
240 const HouseSpec *hs = HouseSpec::Get(house);
245 if (north_tile == nbhd->
north_tile)
return false;
271 uint8 searchtype =
GB(parameter, 6, 2);
272 uint8 searchradius =
GB(parameter, 0, 6);
273 if (searchtype >=
lengthof(search_procs))
return 0;
274 if (searchradius < 1)
return 0;
277 nbhd.
hs = HouseSpec::Get(house);
281 if (
CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
306 case 0x44:
return GetNumHouses(this->
house_id, this->
town);
326 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->
town);
353 for (
Station *
const * st_iter = sl->
Begin(); st_iter != sl->
End(); st_iter++) {
375 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
378 if (hs->
class_id != HOUSE_NO_CLASS) {
383 uint local_houseid = 0;
385 local_houseid = nearby_house_id;
390 return houseclass << 16 | local_houseid;
401 return _house_mngr.
GetGRFID(house_id);
405 DEBUG(grf, 1,
"Unhandled house variable 0x%X", variable);
412 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
417 not_yet_constructed, initial_random_bits, watched_cargo_triggers);
418 return object.ResolveCallback();
425 const HouseSpec *hs = HouseSpec::Get(house_id);
431 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
450 const HouseSpec *hs = HouseSpec::Get(house_id);
453 bool draw_old_one =
true;
466 if (group != NULL && group->type == SGT_TILELAYOUT) {
477 return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile,
false, 0, extra_data);
492 if (hs == NULL)
return;
497 void AnimateNewHouseConstruction(
TileIndex tile)
524 static void AnimationControl(
TileIndex tile, uint16 random_bits)
543 TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
544 if (hs->
building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
552 uint16 random =
GB(Random(), 0, 16);
554 if (hs->
building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
559 AnimationControl(tile, 0);
567 ClearTownHouse(Town::GetByTile(tile), tile);
577 static void DoTriggerHouse(
TileIndex tile, HouseTrigger trigger, byte base_random,
bool first)
592 if (group == NULL)
return;
598 byte new_random_bits = Random();
600 uint32 reseed =
object.GetReseedSum();
601 random_bits &= ~reseed;
602 random_bits |= (first ? new_random_bits : base_random) & reseed;
606 case HOUSE_TRIGGER_TILE_LOOP:
610 case HOUSE_TRIGGER_TILE_LOOP_TOP:
624 void TriggerHouse(
TileIndex t, HouseTrigger trigger)
626 DoTriggerHouse(t, trigger, 0,
true);
639 uint32 cb_info = random << 16 | (uint8)diff.
y << 8 | (uint8)diff.
x;
653 const HouseSpec *hs = HouseSpec::Get(
id);
657 if (trigger_cargoes == 0)
return;
664 hs = HouseSpec::Get(
id);