45 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
63 const HouseSpec *hs = HouseSpec::Get(house_id);
80 CallbackID callback, uint32 param1, uint32 param2,
81 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
83 house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
84 town_scope(*this, town, not_yet_constructed)
89 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
92 for (
int i = 1; i !=
lengthof(_class_mapping); i++) {
103 return HOUSE_NO_CLASS;
106 void InitializeBuildingCounts()
108 memset(&_building_counts, 0,
sizeof(_building_counts));
129 _building_counts.id_count[house_id]++;
131 if (class_id == HOUSE_NO_CLASS)
return;
134 _building_counts.class_count[class_id]++;
150 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
152 if (class_id == HOUSE_NO_CLASS)
return;
155 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
172 static uint32 GetNumHouses(
HouseID house_id,
const Town *town)
174 uint8 map_id_count, town_id_count, map_class_count, town_class_count;
177 map_id_count =
ClampU(_building_counts.id_count[house_id], 0, 255);
178 map_class_count =
ClampU(_building_counts.class_count[class_id], 0, 255);
182 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
214 const HouseSpec *hs = HouseSpec::Get(house);
219 if (north_tile == nbhd->
north_tile)
return false;
238 const HouseSpec *hs = HouseSpec::Get(house);
243 if (north_tile == nbhd->
north_tile)
return false;
262 const HouseSpec *hs = HouseSpec::Get(house);
267 if (north_tile == nbhd->
north_tile)
return false;
293 uint8 searchtype =
GB(parameter, 6, 2);
294 uint8 searchradius =
GB(parameter, 0, 6);
295 if (searchtype >=
lengthof(search_procs))
return 0;
296 if (searchradius < 1)
return 0;
299 nbhd.
hs = HouseSpec::Get(house);
303 if (
CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
328 case 0x44:
return GetNumHouses(this->
house_id, this->
town);
348 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->
town);
375 for (
Station *
const * st_iter = sl->
Begin(); st_iter != sl->
End(); st_iter++) {
397 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
400 if (hs->
class_id != HOUSE_NO_CLASS) {
405 uint local_houseid = 0;
407 local_houseid = nearby_house_id;
412 return houseclass << 16 | local_houseid;
423 return _house_mngr.
GetGRFID(house_id);
427 DEBUG(grf, 1,
"Unhandled house variable 0x%X", variable);
434 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
439 not_yet_constructed, initial_random_bits, watched_cargo_triggers);
440 return object.ResolveCallback();
447 const HouseSpec *hs = HouseSpec::Get(house_id);
453 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
472 const HouseSpec *hs = HouseSpec::Get(house_id);
475 bool draw_old_one =
true;
488 if (group != NULL && group->type == SGT_TILELAYOUT) {
499 return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile,
false, 0, extra_data);
514 if (hs == NULL)
return;
519 void AnimateNewHouseConstruction(
TileIndex tile)
546 static void AnimationControl(
TileIndex tile, uint16 random_bits)
565 TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
566 if (hs->
building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
574 uint16 random =
GB(Random(), 0, 16);
576 if (hs->
building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
581 AnimationControl(tile, 0);
589 ClearTownHouse(Town::GetByTile(tile), tile);
599 static void DoTriggerHouse(
TileIndex tile, HouseTrigger trigger, byte base_random,
bool first)
614 if (group == NULL)
return;
620 byte new_random_bits = Random();
622 uint32 reseed =
object.GetReseedSum();
623 random_bits &= ~reseed;
624 random_bits |= (first ? new_random_bits : base_random) & reseed;
628 case HOUSE_TRIGGER_TILE_LOOP:
632 case HOUSE_TRIGGER_TILE_LOOP_TOP:
646 void TriggerHouse(
TileIndex t, HouseTrigger trigger)
648 DoTriggerHouse(t, trigger, 0,
true);
661 uint32 cb_info = random << 16 | (uint8)diff.
y << 8 | (uint8)diff.
x;
675 const HouseSpec *hs = HouseSpec::Get(
id);
679 if (trigger_cargoes == 0)
return;
686 hs = HouseSpec::Get(
id);