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

Function aiCompanyAboutToBuildCheck

src/OpenLoco/src/Map/TileClearance.cpp:150–208  ·  view source on GitHub ↗

0x00462BB3 Vanilla function would return true with input esi not modified Vanilla function would return false with esi set to 0xFFFFFFFF if error text set or problem element if not set

Source from the content-addressed store, hash-verified

148 // Vanilla function would return true with input esi not modified
149 // Vanilla function would return false with esi set to 0xFFFFFFFF if error text set or problem element if not set
150 static ClearFuncResult aiCompanyAboutToBuildCheck(const World::TileElement& el)
151 {
152 auto* elSurface = el.as<SurfaceElement>();
153
154 // 0x00462C02
155 auto returnFunc = [](const CompanyId owner) -> ClearFuncResult {
156 const auto updatingId = GameCommands::getUpdatingCompanyId();
157 if (updatingId == CompanyId::neutral || !CompanyManager::isPlayerCompany(updatingId))
158 {
159 GameCommands::setErrorText(StringIds::another_company_is_about_to_build_here);
160 return ClearFuncResult::collisionErrorSet;
161 }
162 if (owner == updatingId || CompanyManager::isPlayerCompany(owner))
163 {
164 return ClearFuncResult::collision;
165 }
166 auto* company = CompanyManager::get(owner);
167 if ((company->challengeFlags & CompanyFlags::unk2) != CompanyFlags::none)
168 {
169 GameCommands::setErrorText(StringIds::another_company_is_about_to_build_here);
170 return ClearFuncResult::collisionErrorSet;
171 }
172 // Modification from vanilla
173 company->challengeFlags |= CompanyFlags::unk1;
174 return ClearFuncResult::noCollision;
175 };
176
177 if (elSurface == nullptr)
178 {
179 CompanyId owner = TileManager::getTileOwner(el);
180 if (owner == CompanyId::null)
181 {
182 return ClearFuncResult::noCollision;
183 }
184
185 return returnFunc(owner);
186 }
187 else
188 {
189 auto* elp = &el;
190 while (!elp->isLast())
191 {
192 elp = elp->next();
193 if (!elp->isAiAllocated())
194 {
195 continue;
196 }
197 const auto owner = TileManager::getTileOwner(*elp);
198 if (owner == CompanyId::null)
199 {
200 continue;
201 }
202
203 return returnFunc(owner);
204 }
205 GameCommands::setErrorText(StringIds::another_company_is_about_to_build_here);
206 return ClearFuncResult::collisionErrorSet;
207 }

Calls 8

getUpdatingCompanyIdFunction · 0.85
isPlayerCompanyFunction · 0.85
setErrorTextFunction · 0.85
getTileOwnerFunction · 0.85
isAiAllocatedMethod · 0.80
getFunction · 0.70
isLastMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected