Merge tag '12.0-beta1' into jgrpp-beta

# Conflicts:
#	CMakeLists.txt
#	bin/ai/CMakeLists.txt
#	bin/game/CMakeLists.txt
#	src/build_vehicle_gui.cpp
#	src/console_cmds.cpp
#	src/core/overflowsafe_type.hpp
#	src/fios.cpp
#	src/lang/english.txt
#	src/lang/german.txt
#	src/lang/korean.txt
#	src/lang/polish.txt
#	src/network/core/game_info.cpp
#	src/network/core/game_info.h
#	src/network/core/tcp_game.cpp
#	src/network/core/tcp_game.h
#	src/network/network.cpp
#	src/network/network_client.cpp
#	src/network/network_client.h
#	src/network/network_coordinator.cpp
#	src/network/network_gui.cpp
#	src/network/network_server.cpp
#	src/network/network_server.h
#	src/newgrf_engine.cpp
#	src/openttd.cpp
#	src/rev.cpp.in
#	src/settings_type.h
#	src/train.h
#	src/train_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2021-11-02 17:51:38 +00:00
146 changed files with 2391 additions and 2807 deletions

View File

@@ -179,6 +179,7 @@ add_files(
script_log.hpp
script_map.hpp
script_marine.hpp
script_newgrf.hpp
script_news.hpp
script_object.hpp
script_order.hpp
@@ -246,6 +247,7 @@ add_files(
script_log.cpp
script_map.cpp
script_marine.cpp
script_newgrf.cpp
script_news.cpp
script_object.cpp
script_order.cpp

View File

@@ -13,10 +13,15 @@
* functions may still be available if you return an older API version
* in GetAPIVersion() in info.nut.
*
* \b 1.12.0
* \b 12.0
*
* This version is not yet released. The following changes are not set in stone yet.
*
* API additions:
* \li AINewGRF
* \li AINewGRFList
* \li AIGroup::GetNumVehicles
*
* \b 1.11.0
*
* API additions:

View File

@@ -13,10 +13,14 @@
* functions may still be available if you return an older API version
* in GetAPIVersion() in info.nut.
*
* \b 1.12.0
* \b 12.0
*
* This version is not yet released. The following changes are not set in stone yet.
*
* API additions:
* \li GSNewGRF
* \li GSNewGRFList
*
* \b 1.11.0
*
* API additions:

View File

@@ -140,9 +140,9 @@
if (quarter > EARLIEST_QUARTER) return -1;
if (quarter == CURRENT_QUARTER) {
return ::Company::Get(company)->cur_economy.delivered_cargo.GetSum<OverflowSafeInt<int32, INT32_MAX, INT32_MIN> >();
return ::Company::Get(company)->cur_economy.delivered_cargo.GetSum<OverflowSafeInt32>();
}
return ::Company::Get(company)->old_economy[quarter - 1].delivered_cargo.GetSum<OverflowSafeInt<int32, INT32_MAX, INT32_MIN> >();
return ::Company::Get(company)->old_economy[quarter - 1].delivered_cargo.GetSum<OverflowSafeInt32>();
}
/* static */ int32 ScriptCompany::GetQuarterlyPerformanceRating(ScriptCompany::CompanyID company, uint32 quarter)

View File

@@ -140,11 +140,20 @@ public:
/**
* Get the OpenTTD version of this executable. The version is formatted
* with the bits having the following meaning:
* 28-31 major version
* 24-27 minor version
* 20-23 build
* 24-31 major version + 16.
* 20-23 minor version.
* 19 1 if it is a release, 0 if it is not.
* 0-18 revision number; 0 when the revision is unknown.
* You have to subtract 16 from the major version to get the correct
* value.
*
* Prior to OpenTTD 12, the bits have the following meaning:
* 28-31 major version.
* 24-27 minor version.
* 20-23 build.
* 19 1 if it is a release, 0 if it is not.
* 0-18 revision number; 0 when the revision is unknown.
*
* @return The version in newgrf format.
*/
static uint GetVersion();

View File

@@ -106,6 +106,15 @@
return GetGroupNumEngines(ScriptObject::GetCompany(), group_id, engine_id);
}
/* static */ int32 ScriptGroup::GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type)
{
bool valid_group = IsValidGroup(group_id);
if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
if (!valid_group && (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR)) return -1;
return GetGroupNumVehicle(ScriptObject::GetCompany(), group_id, valid_group ? ::Group::Get(group_id)->vehicle_type : (::VehicleType)vehicle_type);
}
/* static */ bool ScriptGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id)
{
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT);

View File

@@ -128,6 +128,20 @@ public:
*/
static int32 GetNumEngines(GroupID group_id, EngineID engine_id);
/**
* Get the total number of vehicles in a given group and its sub-groups.
* @param group_id The group to get the number of vehicles in.
* @param vehicle_type The type of vehicle of the group.
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
* @pre IsValidGroup(group_id) || vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL ||
* vehicle_type == ScriptVehicle::VT_WATER || vehicle_type == ScriptVehicle::VT_AIR
* @return The total number of vehicles in the group with id group_id and it's sub-groups.
* @note If the group is valid (neither GROUP_ALL nor GROUP_DEFAULT), the value of
* vehicle_type is retrieved from the group itself and not from the input value.
* But if the group is GROUP_ALL or GROUP_DEFAULT, then vehicle_type must be valid.
*/
static int32 GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type);
/**
* Move a vehicle to a group.
* @param group_id The group to move the vehicle to.

View File

@@ -832,7 +832,7 @@ SQInteger ScriptList::_nexti(HSQUIRRELVM vm)
SQInteger idx;
sq_getinteger(vm, 2, &idx);
int val = this->Next();
SQInteger val = this->Next();
if (this->IsEnd()) {
sq_pushnull(vm);
return 1;

View File

@@ -0,0 +1,64 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_newgrf.cpp Implementation of ScriptNewGRF and friends. */
#include "../../stdafx.h"
#include "script_newgrf.hpp"
#include "../../core/bitmath_func.hpp"
#include "../../newgrf_config.h"
#include "../../string_func.h"
#include "../../safeguards.h"
ScriptNewGRFList::ScriptNewGRFList()
{
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC)) {
this->AddItem(BSWAP32(c->ident.grfid));
}
}
}
/* static */ bool ScriptNewGRF::IsLoaded(uint32 grfid)
{
grfid = BSWAP32(grfid); // Match people's expectations.
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
return true;
}
}
return false;
}
/* static */ uint32 ScriptNewGRF::GetVersion(uint32 grfid)
{
grfid = BSWAP32(grfid); // Match people's expectations.
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
return c->version;
}
}
return 0;
}
/* static */ char *ScriptNewGRF::GetName(uint32 grfid)
{
grfid = BSWAP32(grfid); // Match people's expectations.
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
return ::stredup(c->GetName());
}
}
return nullptr;
}

View File

@@ -0,0 +1,56 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_newgrf.hpp NewGRF info for scripts. */
#ifndef SCRIPT_NEWGRF_HPP
#define SCRIPT_NEWGRF_HPP
#include "script_list.hpp"
/**
* Create a list of loaded NewGRFs.
* @api ai game
* @ingroup ScriptList
*/
class ScriptNewGRFList : public ScriptList {
public:
ScriptNewGRFList();
};
/**
* Class that handles all NewGRF related functions.
* @api ai game
*/
class ScriptNewGRF : public ScriptObject {
public:
/**
* Check if a NewGRF with a given grfid is loaded.
* @param grfid The grfid to check.
* @return True if and only if a NewGRF with the given grfid is loaded in the game.
*/
static bool IsLoaded(uint32 grfid);
/**
* Get the version of a loaded NewGRF.
* @param grfid The NewGRF to query.
* @pre ScriptNewGRF::IsLoaded(grfid).
* @return Version of the NewGRF or 0 if the NewGRF specifies no version.
*/
static uint32 GetVersion(uint32 grfid);
/**
* Get the name of a loaded NewGRF.
* @param grfid The NewGRF to query.
* @pre ScriptNewGRF::IsLoaded(grfid).
* @return The name of the NewGRF or nullptr if no name is defined.
*/
static char *GetName(uint32 grfid);
};
#endif /* SCRIPT_NEWGRF_HPP */