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 */
7
8 /** @file script_objecttype.cpp Implementation of ScriptObjectType. */
9
10 #include "../../stdafx.h"
11
12 #include "script_objecttype.hpp"
13
14 #include "script_error.hpp"
15 #include "script_map.hpp"
16
17 #include "../../safeguards.h"
18
IsValidObjectType(ObjectType object_type)19 /* static */ bool ScriptObjectType::IsValidObjectType(ObjectType object_type)
20 {
21 if (object_type >= NUM_OBJECTS) return false;
22 return ObjectSpec::Get(object_type)->IsEverAvailable();
23 }
24
GetName(ObjectType object_type)25 /* static */ char *ScriptObjectType::GetName(ObjectType object_type)
26 {
27 EnforcePrecondition(nullptr, IsValidObjectType(object_type));
28
29 return GetString(ObjectSpec::Get(object_type)->name);
30 }
31
GetViews(ObjectType object_type)32 /* static */ uint8 ScriptObjectType::GetViews(ObjectType object_type)
33 {
34 EnforcePrecondition(0, IsValidObjectType(object_type));
35
36 return ObjectSpec::Get(object_type)->views;
37 }
38
BuildObject(ObjectType object_type,uint8 view,TileIndex tile)39 /* static */ bool ScriptObjectType::BuildObject(ObjectType object_type, uint8 view, TileIndex tile)
40 {
41 EnforcePrecondition(false, IsValidObjectType(object_type));
42 EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
43
44 return ScriptObject::DoCommand(tile, object_type, view, CMD_BUILD_OBJECT);
45 }
46