Update to 12.0-RC1
This commit is contained in:
@@ -182,6 +182,8 @@ add_files(
|
||||
script_newgrf.hpp
|
||||
script_news.hpp
|
||||
script_object.hpp
|
||||
script_objecttype.hpp
|
||||
script_objecttypelist.hpp
|
||||
script_order.hpp
|
||||
script_priorityqueue.hpp
|
||||
script_rail.hpp
|
||||
@@ -250,6 +252,8 @@ add_files(
|
||||
script_newgrf.cpp
|
||||
script_news.cpp
|
||||
script_object.cpp
|
||||
script_objecttype.cpp
|
||||
script_objecttypelist.cpp
|
||||
script_order.cpp
|
||||
script_priorityqueue.cpp
|
||||
script_rail.cpp
|
||||
|
||||
@@ -21,6 +21,13 @@
|
||||
* \li AINewGRF
|
||||
* \li AINewGRFList
|
||||
* \li AIGroup::GetNumVehicles
|
||||
* \li AIMarine::BT_LOCK
|
||||
* \li AIMarine::BT_CANAL
|
||||
* \li AITile::IsSeaTile
|
||||
* \li AITile::IsRiverTile
|
||||
* \li AITile::BT_CLEAR_WATER
|
||||
* \li AIObjectTypeList
|
||||
* \li AIObjectType
|
||||
*
|
||||
* \b 1.11.0
|
||||
*
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
* API additions:
|
||||
* \li GSNewGRF
|
||||
* \li GSNewGRFList
|
||||
* \li GSMarine::BT_LOCK
|
||||
* \li GSMarine::BT_CANAL
|
||||
* \li GSTile::IsSeaTile
|
||||
* \li GSTile::IsRiverTile
|
||||
* \li GSTile::BT_CLEAR_WATER
|
||||
* \li GSObjectTypeList
|
||||
* \li GSObjectType
|
||||
*
|
||||
* \b 1.11.0
|
||||
*
|
||||
|
||||
@@ -167,6 +167,8 @@
|
||||
case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, nullptr);
|
||||
case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_SHIP, 1, nullptr);
|
||||
case BT_BUOY: return ::GetPrice(PR_BUILD_WAYPOINT_BUOY, 1, nullptr);
|
||||
case BT_LOCK: return ::GetPrice(PR_BUILD_LOCK, 1, nullptr);
|
||||
case BT_CANAL: return ::GetPrice(PR_BUILD_CANAL, 1, nullptr);
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ public:
|
||||
BT_DOCK, ///< Build a dock
|
||||
BT_DEPOT, ///< Build a ship depot
|
||||
BT_BUOY, ///< Build a buoy
|
||||
BT_LOCK, ///< Build a lock
|
||||
BT_CANAL, ///< Build a canal
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
45
src/script/api/script_objecttype.cpp
Normal file
45
src/script/api/script_objecttype.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_objecttype.cpp Implementation of ScriptObjectType. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
|
||||
#include "script_objecttype.hpp"
|
||||
|
||||
#include "script_error.hpp"
|
||||
#include "script_map.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptObjectType::IsValidObjectType(ObjectType object_type)
|
||||
{
|
||||
if (object_type >= NUM_OBJECTS) return false;
|
||||
return ObjectSpec::Get(object_type)->IsEverAvailable();
|
||||
}
|
||||
|
||||
/* static */ char *ScriptObjectType::GetName(ObjectType object_type)
|
||||
{
|
||||
EnforcePrecondition(nullptr, IsValidObjectType(object_type));
|
||||
|
||||
return GetString(ObjectSpec::Get(object_type)->name);
|
||||
}
|
||||
|
||||
/* static */ uint8 ScriptObjectType::GetViews(ObjectType object_type)
|
||||
{
|
||||
EnforcePrecondition(0, IsValidObjectType(object_type));
|
||||
|
||||
return ObjectSpec::Get(object_type)->views;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObjectType::BuildObject(ObjectType object_type, uint8 view, TileIndex tile)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidObjectType(object_type));
|
||||
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
|
||||
|
||||
return ScriptObject::DoCommand(tile, object_type, view, CMD_BUILD_OBJECT);
|
||||
}
|
||||
57
src/script/api/script_objecttype.hpp
Normal file
57
src/script/api/script_objecttype.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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_objecttype.hpp Everything to query and build industries. */
|
||||
|
||||
#ifndef SCRIPT_OBJECTTYPE_HPP
|
||||
#define SCRIPT_OBJECTTYPE_HPP
|
||||
|
||||
#include "script_list.hpp"
|
||||
|
||||
#include "../../newgrf_object.h"
|
||||
|
||||
/**
|
||||
* Class that handles all object-type related functions.
|
||||
* @api ai game
|
||||
*/
|
||||
class ScriptObjectType : public ScriptObject {
|
||||
public:
|
||||
/**
|
||||
* Checks whether the given object-type is valid.
|
||||
* @param object_type The type to check.
|
||||
* @return True if and only if the object-type is valid.
|
||||
*/
|
||||
static bool IsValidObjectType(ObjectType object_type);
|
||||
|
||||
/**
|
||||
* Get the name of an object-type.
|
||||
* @param object_type The type to get the name for.
|
||||
* @pre IsValidObjectType(object_type).
|
||||
* @return The name of an object.
|
||||
*/
|
||||
static char *GetName(ObjectType object_type);
|
||||
|
||||
/**
|
||||
* Get the number of views for an object-type.
|
||||
* @param object_type The type to get the number of views for.
|
||||
* @pre IsValidObjectType(object_type).
|
||||
* @return The number of views for an object.
|
||||
*/
|
||||
static uint8 GetViews(ObjectType object_type);
|
||||
|
||||
/**
|
||||
* Build an object of the specified type.
|
||||
* @param object_type The type of the object to build.
|
||||
* @param view The view for teh object.
|
||||
* @param tile The tile to build the object on.
|
||||
* @pre IsValidObjectType(object_type).
|
||||
* @return True if the object was successfully build.
|
||||
*/
|
||||
static bool BuildObject(ObjectType object_type, uint8 view, TileIndex tile);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_OBJECTTYPE_HPP */
|
||||
23
src/script/api/script_objecttypelist.cpp
Normal file
23
src/script/api/script_objecttypelist.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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_objecttypelist.cpp Implementation of ScriptObjectTypeList. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_objecttypelist.hpp"
|
||||
#include "../../newgrf_object.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptObjectTypeList::ScriptObjectTypeList()
|
||||
{
|
||||
for (int i = 0; i < NUM_OBJECTS; i++) {
|
||||
const ObjectSpec *spec = ObjectSpec::Get(i);
|
||||
if (!spec->IsEverAvailable()) continue;
|
||||
this->AddItem(i);
|
||||
}
|
||||
}
|
||||
26
src/script/api/script_objecttypelist.hpp
Normal file
26
src/script/api/script_objecttypelist.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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_objecttypelist.hpp List all available object types. */
|
||||
|
||||
#ifndef SCRIPT_OBJECTTYPELIST_HPP
|
||||
#define SCRIPT_OBJECTTYPELIST_HPP
|
||||
|
||||
#include "script_objecttype.hpp"
|
||||
|
||||
/**
|
||||
* Creates a list of valid object types.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptObjectTypeList : public ScriptList {
|
||||
public:
|
||||
ScriptObjectTypeList();
|
||||
};
|
||||
|
||||
|
||||
#endif /* SCRIPT_OBJECTTYPELIST_HPP */
|
||||
@@ -58,6 +58,20 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTile::IsSeaTile(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return false;
|
||||
|
||||
return ::IsTileType(tile, MP_WATER) && ::IsSea(tile);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTile::IsRiverTile(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return false;
|
||||
|
||||
return ::IsTileType(tile, MP_WATER) && ::IsRiver(tile);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTile::IsWaterTile(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return false;
|
||||
@@ -320,6 +334,7 @@
|
||||
case BT_CLEAR_ROCKY: return ::GetPrice(PR_CLEAR_ROCKS, 1, nullptr);
|
||||
case BT_CLEAR_FIELDS: return ::GetPrice(PR_CLEAR_FIELDS, 1, nullptr);
|
||||
case BT_CLEAR_HOUSE: return ::GetPrice(PR_CLEAR_HOUSE, 1, nullptr);
|
||||
case BT_CLEAR_WATER: return ::GetPrice(PR_CLEAR_WATER, 1, nullptr);
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ public:
|
||||
BT_CLEAR_ROCKY, ///< Clear a tile with rocks
|
||||
BT_CLEAR_FIELDS, ///< Clear a tile with farm fields
|
||||
BT_CLEAR_HOUSE, ///< Clear a tile with a house
|
||||
BT_CLEAR_WATER, ///< Clear a tile with either river or sea
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -158,11 +159,28 @@ public:
|
||||
*/
|
||||
static bool IsBuildableRectangle(TileIndex tile, uint width, uint height);
|
||||
|
||||
/**
|
||||
* Checks whether the given tile is actually a sea tile.
|
||||
* @param tile The tile to check on.
|
||||
* @pre ScriptMap::IsValidTile(tile).
|
||||
* @return True if and only if the tile is a sea tile.
|
||||
*/
|
||||
static bool IsSeaTile(TileIndex tile);
|
||||
|
||||
/**
|
||||
* Checks whether the given tile is actually a river tile.
|
||||
* @param tile The tile to check on.
|
||||
* @pre ScriptMap::IsValidTile(tile).
|
||||
* @return True if and only if the tile is a river tile.
|
||||
*/
|
||||
static bool IsRiverTile(TileIndex tile);
|
||||
|
||||
/**
|
||||
* Checks whether the given tile is actually a water tile.
|
||||
* @param tile The tile to check on.
|
||||
* @pre ScriptMap::IsValidTile(tile).
|
||||
* @return True if and only if the tile is a water tile.
|
||||
* @note Returns false when a buoy is on the tile.
|
||||
*/
|
||||
static bool IsWaterTile(TileIndex tile);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user