Skip to content

Commit

Permalink
Use std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zzam committed Mar 29, 2024
1 parent a044616 commit 418576d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/action/action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ void COrder_Built::AiUnitKilled(CUnit &unit)
}


static std::size_t FindCFramePercent(const std::vector<CConstructionFrame> &cframes, int percent)
static std::optional<std::size_t> FindCFramePercent(const std::vector<CConstructionFrame> &cframes, int percent)
{
if (cframes.empty())
{
return -1;
return {};
}
const auto it =
ranges::find_if(cframes, [&](const auto &frame) { return percent < frame.Percent; });
Expand All @@ -344,9 +344,9 @@ void COrder_Built::UpdateConstructionFrame(CUnit &unit)
const int percent = this->ProgressCounter / (type.Stats[unit.Player->Index].Costs[TimeCost] * 6);
const auto index = FindCFramePercent(type.Construction->Frames, percent);

if (index != -1 && index != this->Frame) {
this->Frame = index;
const CConstructionFrame &cframe = type.Construction->Frames[index];
if (index.has_value() && index.value() != this->Frame) {
this->Frame = index.value();
const CConstructionFrame &cframe = type.Construction->Frames[index.value()];
unit.Frame = (unit.Frame < 0) ? -cframe.Frame - 1 : cframe.Frame;
}
}
Expand Down

0 comments on commit 418576d

Please sign in to comment.