MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TileLoop_Object

Function TileLoop_Object

src/object_cmd.cpp:673–725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671}
672
673static void TileLoop_Object(TileIndex tile)
674{
675 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
676 if (spec->flags.Test(ObjectFlag::Animation)) {
677 Object *o = Object::GetByTile(tile);
678 TriggerObjectTileAnimation(o, tile, ObjectAnimationTrigger::TileLoop, spec);
679 if (o->location.tile == tile) TriggerObjectAnimation(o, ObjectAnimationTrigger::TileLoopNorth, spec);
680 }
681
682 if (IsTileOnWater(tile)) TileLoop_Water(tile);
683
684 if (!IsObjectType(tile, OBJECT_HQ)) return;
685
686 /* HQ accepts passenger and mail; but we have to divide the values
687 * between 4 tiles it occupies! */
688
689 /* HQ level (depends on company performance) in the range 1..5. */
690 uint level = GetCompanyHQSize(tile) + 1;
691 assert(level < 6);
692
693 StationFinder stations(TileArea(tile, 2, 2));
694
695 uint r = Random();
696 /* Top town buildings generate 250, so the top HQ type makes 256. */
697 CargoType pass = GetCargoTypeByLabel(CT_PASSENGERS);
698 if (IsValidCargoType(pass) && GB(r, 0, 8) < (256 / 4 / (6 - level))) {
699 uint amt = GB(r, 0, 8) / 8 / 4 + 1;
700
701 /* Production is halved during recessions. */
702 if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
703
704 /* Scale by cargo scale setting. */
705 amt = ScaleByCargoScale(amt, true);
706
707 MoveGoodsToStation(pass, amt, {GetTileOwner(tile), SourceType::Headquarters}, stations.GetStations());
708 }
709
710 /* Top town building generates 90, HQ can make up to 196. The
711 * proportion passengers:mail is about the same as in the acceptance
712 * equations. */
713 CargoType mail = GetCargoTypeByLabel(CT_MAIL);
714 if (IsValidCargoType(mail) && GB(r, 8, 8) < (196 / 4 / (6 - level))) {
715 uint amt = GB(r, 8, 8) / 8 / 4 + 1;
716
717 /* Production is halved during recessions. */
718 if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
719
720 /* Scale by cargo scale setting. */
721 amt = ScaleByCargoScale(amt, true);
722
723 MoveGoodsToStation(mail, amt, {GetTileOwner(tile), SourceType::Headquarters}, stations.GetStations());
724 }
725}
726
727
728static TrackStatus GetTileTrackStatus_Object(TileIndex, TransportType, uint, DiagDirection)

Callers

nothing calls this directly

Calls 15

TriggerObjectAnimationFunction · 0.85
IsTileOnWaterFunction · 0.85
TileLoop_WaterFunction · 0.85
IsObjectTypeFunction · 0.85
GetCompanyHQSizeFunction · 0.85
GetCargoTypeByLabelFunction · 0.85
IsValidCargoTypeFunction · 0.85
GBFunction · 0.85
EconomyIsInRecessionFunction · 0.85
ScaleByCargoScaleFunction · 0.85
MoveGoodsToStationFunction · 0.85

Tested by

no test coverage detected