1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +01:00

Add: [Script] Cloning ScriptList

This commit is contained in:
glx22
2025-05-26 18:50:06 +02:00
committed by Loïc Guilloux
parent 7200e7f509
commit 938acbe6ef
8 changed files with 58 additions and 1 deletions

View File

@@ -34,6 +34,7 @@
* \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint
* \li AIList instances can now be saved
* \li AIVehicleList_Station accepts an optional AIVehicle::VehicleType parameter
* \li AIList instances can now be cloned
*
* \b 14.0
*

View File

@@ -35,6 +35,7 @@
* \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint
* \li GSList instances can now be saved
* \li GSVehicleList_Station accepts an optional GSVehicle::VehicleType parameter
* \li GSList instances can now be cloned
*
* \b 14.0
*

View File

@@ -453,6 +453,20 @@ bool ScriptList::LoadObject(HSQUIRRELVM vm)
return true;
}
ScriptObject *ScriptList::CloneObject()
{
ScriptList *clone = new ScriptList();
clone->CopyList(this);
return clone;
}
void ScriptList::CopyList(const ScriptList *list)
{
this->Sort(list->sorter_type, list->sort_ascending);
this->items = list->items;
this->buckets = list->buckets;
}
ScriptList::ScriptList()
{
/* Default sorter */

View File

@@ -145,6 +145,13 @@ protected:
virtual bool SaveObject(HSQUIRRELVM vm) override;
virtual bool LoadObject(HSQUIRRELVM vm) override;
virtual ScriptObject *CloneObject() override;
/**
* Copy the content of a list.
* @param list The list that will be copied.
*/
void CopyList(const ScriptList *list);
public:
typedef std::set<SQInteger> ScriptItemList; ///< The list of items inside the bucket

View File

@@ -23,6 +23,13 @@ bool ScriptTileList::SaveObject(HSQUIRRELVM vm)
return true;
}
ScriptObject *ScriptTileList::CloneObject()
{
ScriptTileList *clone = new ScriptTileList();
clone->CopyList(this);
return clone;
}
void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
{
if (!::IsValidTile(t1)) return;

View File

@@ -22,6 +22,7 @@
class ScriptTileList : public ScriptList {
protected:
virtual bool SaveObject(HSQUIRRELVM) override;
virtual ScriptObject *CloneObject() override;
public:
/**
* Adds the rectangle between tile_from and tile_to to the to-be-evaluated tiles.