Update to 14.0-beta3

This commit is contained in:
dP
2024-02-07 13:59:10 +05:30
parent 33ef333b57
commit 910fa762b9
200 changed files with 3470 additions and 4280 deletions
+1
View File
@@ -21,6 +21,7 @@
* \li AITimeMode
* \li AITown::ROAD_LAYOUT_RANDOM
* \li AIVehicle::IsPrimaryVehicle
* \li AITileList_StationCoverage
*
* API removals:
* \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
+2 -1
View File
@@ -87,10 +87,11 @@
* \li GSStoryPage::IsValidStoryPageButtonColour
* \li GSStoryPage::IsValidStoryPageButtonFlags
* \li GSStoryPage::IsValidStoryPageButtonCursor
* \li GSTileList_StationCoverage
*
* API removals:
* \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
* \li AIInfo::CONFIG_RANDOM, no longer used.
* \li GSInfo::CONFIG_RANDOM, no longer used.
*
* Other changes:
* \li GSGroupList accepts an optional filter function
+1 -1
View File
@@ -45,7 +45,7 @@
* like "PASS", "COAL", "OIL_". New ones can be defined by NewGRFs */
std::string cargo_label;
for (uint i = 0; i < sizeof(cargo->label); i++) {
cargo_label.push_back(GB(cargo->label, (uint8_t)(sizeof(cargo->label) - i - 1) * 8, 8));
cargo_label.push_back(GB(cargo->label.base(), (uint8_t)(sizeof(cargo->label) - i - 1) * 8, 8));
}
return cargo_label;
}
+2
View File
@@ -178,6 +178,8 @@
{
company = ResolveCompanyID(company);
if (company == COMPANY_INVALID) return -1;
/* If we return INT64_MAX as usual, overflows may occur in the script. So return a smaller value. */
if (_settings_game.difficulty.infinite_money) return INT32_MAX;
return GetAvailableMoney((::CompanyID)company);
}
+2 -1
View File
@@ -258,9 +258,10 @@ public:
/**
* Gets the bank balance. In other words, the amount of money the given company can spent.
* If infinite money is enabled, it returns INT32_MAX.
* @param company The company to get the bank balance of.
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
* @return The actual bank balance.
* @return The actual bank balance or INT32_MAX.
*/
static Money GetBankBalance(CompanyID company);
+24 -10
View File
@@ -181,6 +181,15 @@ void ScriptText::_FillParamList(ParamList &params)
}
}
void ScriptText::ParamCheck::Encode(std::back_insert_iterator<std::string> &output)
{
if (this->used) return;
if (std::holds_alternative<std::string>(*this->param)) fmt::format_to(output, ":\"{}\"", std::get<std::string>(*this->param));
if (std::holds_alternative<SQInteger>(*this->param)) fmt::format_to(output, ":{:X}", std::get<SQInteger>(*this->param));
if (std::holds_alternative<ScriptTextRef>(*this->param)) fmt::format_to(output, ":{:X}", this->owner);
this->used = true;
}
void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output, int &param_count, StringIDList &seen_ids, ParamSpan args)
{
const std::string &name = GetGameStringName(this->string);
@@ -198,7 +207,7 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
if (idx >= args.size()) throw Script_FatalError(fmt::format("{}({}): Not enough parameters", name, param_count + 1));
ParamCheck &pc = args[idx++];
if (pc.owner != this->string) ScriptLog::Warning(fmt::format("{}({}): Consumes {}({})", name, param_count + 1, GetGameStringName(pc.owner), pc.idx + 1));
return pc.param;
return &pc;
};
auto skip_args = [&](size_t nb) { idx += nb; };
@@ -209,19 +218,24 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
break;
case StringParam::RAW_STRING: {
Param *p = get_next_arg();
if (!std::holds_alternative<std::string>(*p)) throw Script_FatalError(fmt::format("{}({}): {{{}}} expects a raw string", name, param_count + 1, cur_param.cmd));
fmt::format_to(output, ":\"{}\"", std::get<std::string>(*p));
ParamCheck &p = *get_next_arg();
if (!std::holds_alternative<std::string>(*p.param)) ScriptLog::Error(fmt::format("{}({}): {{{}}} expects a raw string", name, param_count + 1, cur_param.cmd));
p.Encode(output);
break;
}
case StringParam::STRING: {
Param *p = get_next_arg();
if (!std::holds_alternative<ScriptTextRef>(*p)) throw Script_FatalError(fmt::format("{}({}): {{{}}} expects a GSText", name, param_count + 1, cur_param.cmd));
ParamCheck &p = *get_next_arg();
if (!std::holds_alternative<ScriptTextRef>(*p.param)){
ScriptLog::Error(fmt::format("{}({}): {{{}}} expects a GSText", name, param_count + 1, cur_param.cmd));
p.Encode(output);
break;
}
int count = 0;
fmt::format_to(output, ":");
ScriptTextRef &ref = std::get<ScriptTextRef>(*p);
ScriptTextRef &ref = std::get<ScriptTextRef>(*p.param);
ref->_GetEncodedText(output, count, seen_ids, args.subspan(idx));
p.used = true;
if (++count != cur_param.consumes) {
ScriptLog::Error(fmt::format("{}({}): {{{}}} expects {} to be consumed, but {} consumes {}", name, param_count + 1, cur_param.cmd, cur_param.consumes - 1, GetGameStringName(ref->string), count - 1));
/* Fill missing params if needed. */
@@ -233,9 +247,9 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
default:
for (int i = 0; i < cur_param.consumes; i++) {
Param *p = get_next_arg();
if (!std::holds_alternative<SQInteger>(*p)) throw Script_FatalError(fmt::format("{}({}): {{{}}} expects an integer", name, param_count + i + 1, cur_param.cmd));
fmt::format_to(output, ":{:X}", std::get<SQInteger>(*p));
ParamCheck &p = *get_next_arg();
if (!std::holds_alternative<SQInteger>(*p.param)) ScriptLog::Error(fmt::format("{}({}): {{{}}} expects an integer", name, param_count + i + 1, cur_param.cmd));
p.Encode(output);
}
}
+4 -1
View File
@@ -136,8 +136,11 @@ private:
StringID owner;
int idx;
Param *param;
bool used;
ParamCheck(StringID owner, int idx, Param *param) : owner(owner), idx(idx), param(param) {}
ParamCheck(StringID owner, int idx, Param *param) : owner(owner), idx(idx), param(param), used(false) {}
void Encode(std::back_insert_iterator<std::string> &output);
};
using ParamList = std::vector<ParamCheck>;
+10
View File
@@ -147,3 +147,13 @@ ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, Scr
this->AddTile(cur_tile);
}
}
ScriptTileList_StationCoverage::ScriptTileList_StationCoverage(StationID station_id)
{
if (!ScriptStation::IsValidStation(station_id)) return;
BitmapTileIterator it(::Station::Get(station_id)->catchment_tiles);
for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
this->AddTile(tile);
}
}
+13
View File
@@ -104,4 +104,17 @@ public:
ScriptTileList_StationType(StationID station_id, ScriptStation::StationType station_type);
};
/**
* Creates a list of tiles in the catchment area of the StationID.
* @api ai game
* @ingroup ScriptList
*/
class ScriptTileList_StationCoverage : public ScriptTileList {
public:
/**
* @param station_id The station to create the ScriptTileList for.
*/
ScriptTileList_StationCoverage(StationID station_id);
};
#endif /* SCRIPT_TILELIST_HPP */