Update: Translations from eints
[openttd-github.git] / src / script / api / script_objecttype.cpp
blob7e036a3e3d706fa7c83f13250869feb0e94ae054
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file script_objecttype.cpp Implementation of ScriptObjectType. */
10 #include "../../stdafx.h"
12 #include "script_objecttype.hpp"
14 #include "script_error.hpp"
15 #include "script_map.hpp"
16 #include "../../object_cmd.h"
18 #include "../../safeguards.h"
20 /* static */ bool ScriptObjectType::IsValidObjectType(ObjectType object_type)
22 if (object_type >= ObjectSpec::Count()) return false;
23 return ObjectSpec::Get(object_type)->IsEverAvailable();
26 /* static */ std::optional<std::string> ScriptObjectType::GetName(ObjectType object_type)
28 EnforcePrecondition(std::nullopt, IsValidObjectType(object_type));
30 return GetString(ObjectSpec::Get(object_type)->name);
33 /* static */ SQInteger ScriptObjectType::GetViews(ObjectType object_type)
35 EnforcePrecondition(0, IsValidObjectType(object_type));
37 return ObjectSpec::Get(object_type)->views;
40 /* static */ bool ScriptObjectType::BuildObject(ObjectType object_type, SQInteger view, TileIndex tile)
42 EnforceDeityOrCompanyModeValid(false);
43 EnforcePrecondition(false, IsValidObjectType(object_type));
44 EnforcePrecondition(false, view >= 0 && view < GetViews(object_type));
45 EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
47 return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, object_type, view);
50 /* static */ ObjectType ScriptObjectType::ResolveNewGRFID(SQInteger grfid, SQInteger grf_local_id)
52 EnforcePrecondition(INVALID_OBJECT_TYPE, IsInsideBS(grf_local_id, 0x00, NUM_OBJECTS_PER_GRF));
54 grfid = BSWAP32(GB(grfid, 0, 32)); // Match people's expectations.
55 return _object_mngr.GetID(grf_local_id, grfid);