Merge tag '14.0-beta3' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/industrytype.h
#	src/network/core/config.h
#	src/network/core/network_game_info.cpp
#	src/network/core/network_game_info.h
#	src/network/core/packet.cpp
#	src/network/core/packet.h
#	src/network/core/tcp.cpp
#	src/network/core/tcp.h
#	src/network/core/tcp_admin.cpp
#	src/network/core/tcp_content.cpp
#	src/network/core/tcp_coordinator.cpp
#	src/network/core/tcp_game.cpp
#	src/network/core/tcp_game.h
#	src/network/core/tcp_turn.cpp
#	src/network/core/udp.cpp
#	src/network/core/udp.h
#	src/network/network_admin.cpp
#	src/network/network_client.cpp
#	src/network/network_client.h
#	src/network/network_command.cpp
#	src/network/network_content.cpp
#	src/network/network_internal.h
#	src/network/network_query.cpp
#	src/network/network_query.h
#	src/network/network_server.cpp
#	src/network/network_server.h
#	src/network/network_turn.cpp
#	src/network/network_udp.cpp
#	src/rail_gui.cpp
#	src/road_gui.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 17:57:05 +00:00
67 changed files with 1463 additions and 1297 deletions

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.

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

View File

@@ -185,6 +185,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);
}

View File

@@ -260,9 +260,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);

View File

@@ -284,6 +284,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);
@@ -301,7 +310,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; };
@@ -312,19 +321,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. */
@@ -336,9 +350,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);
}
}

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>;

View File

@@ -153,3 +153,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);
}
}

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 */