MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / update

Method update

src/OpenLoco/src/Map/IndustryElement.cpp:101–243  ·  view source on GitHub ↗

0x00456FF7

Source from the content-addressed store, hash-verified

99
100 // 0x00456FF7
101 bool IndustryElement::update(const World::Pos2& loc)
102 {
103 // Sequence 0 updates all the other ones
104 if (sequenceIndex() != 0)
105 {
106 return true;
107 }
108 if (isGhost())
109 {
110 return true;
111 }
112
113 auto* ind = industry();
114 const auto* indObj = ind->getObject();
115 const auto type = buildingType();
116 const auto isMultiTile = indObj->buildingSizeFlags & (1 << type);
117
118 if (!isConstructed())
119 {
120 bool newConstructed = isConstructed();
121 uint8_t newSectionProgress = sectionProgress();
122 uint8_t newNumSections = var_6_003F();
123
124 const auto progress = sectionProgress();
125 if (progress == 0x7)
126 {
127 const size_t numSections = var_6_003F();
128 const auto parts = indObj->getBuildingParts(type);
129 const auto heights = indObj->getBuildingPartHeights();
130 if (parts.size() <= numSections + 1)
131 {
132 ind->under_construction++;
133 if (ind->under_construction >= ind->numTiles)
134 {
135 ind->under_construction = 0xFF;
136 Ui::WindowManager::invalidate(Ui::WindowType::industry, enumValue(ind->id()));
137 Ui::WindowManager::invalidate(Ui::WindowType::industryList);
138 }
139
140 const auto height = std::accumulate(parts.begin(), parts.end(), 0, [partHeights = heights](int32_t total, uint8_t part) {
141 return total + partHeights[part];
142 });
143
144 const auto newClearZ = ((height + 3) / World::kSmallZStep) + baseZ();
145
146 applyToMultiTile(*this, loc, isMultiTile, [newClearZ](World::IndustryElement& elIndustry, const World::Pos2& pos) {
147 Ui::ViewportManager::invalidate(pos, elIndustry.baseHeight(), elIndustry.clearHeight(), ZoomLevel::quarter);
148 elIndustry.setClearZ(newClearZ);
149 });
150
151 newConstructed = true;
152 newSectionProgress = 0;
153 newNumSections = 0;
154 }
155 else
156 {
157 newSectionProgress = 0;
158 newNumSections++;

Callers

nothing calls this directly

Calls 15

enumValueFunction · 0.85
createAnimationFunction · 0.85
toTileSpaceFunction · 0.85
getClampedRangeFunction · 0.85
baseHeightMethod · 0.80
clearHeightMethod · 0.80
setClearZMethod · 0.80
setIsConstructedMethod · 0.80
setSectionProgressMethod · 0.80
setVar_6_003FMethod · 0.80
getUnk38Method · 0.80
isAiAllocatedMethod · 0.80

Tested by

no test coverage detected