1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 01:12:39 +01:00

Codechange: Replace atoi and atoll with ParseInteger.

This commit is contained in:
frosch
2025-04-29 16:12:54 +02:00
committed by frosch
parent 3973199879
commit cdafc50c94
17 changed files with 108 additions and 47 deletions

View File

@@ -35,6 +35,7 @@
#include "timer/timer.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "core/string_consumer.hpp"
#include "widgets/cheat_widget.h"
@@ -607,12 +608,13 @@ struct CheatWindow : Window {
int32_t value;
if (!str->empty()) {
long long llvalue = atoll(str->c_str());
auto llvalue = ParseInteger<int64_t>(*str);
if (!llvalue.has_value()) return;
/* Save the correct currency-translated value */
if (sd->flags.Test(SettingFlag::GuiCurrency)) llvalue /= GetCurrency().rate;
if (sd->flags.Test(SettingFlag::GuiCurrency)) llvalue = *llvalue / GetCurrency().rate;
value = ClampTo<int32_t>(llvalue);
value = ClampTo<int32_t>(*llvalue);
} else {
value = sd->GetDefaultValue();
}
@@ -621,11 +623,12 @@ struct CheatWindow : Window {
} else {
const CheatEntry *ce = &_cheats_ui[clicked_cheat];
int oldvalue = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
int value = atoi(str->c_str());
auto value = ParseInteger<int32_t>(*str);
if (!value.has_value()) return;
*ce->been_used = true;
value = ce->proc(value, value - oldvalue);
value = ce->proc(*value, *value - oldvalue);
if (value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(value));
if (*value != oldvalue) WriteValue(ce->variable, ce->type, static_cast<int64_t>(*value));
}
this->valuewindow_entry = nullptr;