1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-17 03:29:09 +00: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

@@ -828,6 +828,13 @@ function Regression::List()
print(" []:");
print(" 4000 => " + list[4000]);
print(" clone:");
local list3 = clone list;
print(" Clone ListDump:");
foreach (idx, val in list3) {
print(" " + idx + " => " + val);
}
list.Clear();
print(" IsEmpty(): " + list.IsEmpty());
@@ -860,6 +867,12 @@ function Regression::List()
it = list.Next();
print(" " + it + " => " + list.GetValue(it));
}
print(" Clone ListDump:");
foreach (idx, val in list3) {
print(" " + idx + " => " + val);
}
}
function Regression::Map()

@@ -575,6 +575,13 @@
4006 => 12
[]:
4000 => 50
clone:
Clone ListDump:
1005 => 1005
4000 => 50
4001 => 8002
4002 => 8004
4006 => 12
IsEmpty(): true
0 => 5 (true)
ERROR: Next() is invalid as Begin() is never called
@@ -584,6 +591,12 @@ ERROR: IsEnd() is invalid as Begin() is never called
2 => 6 (true)
3 => 6 (true)
9 => 0 (false)
Clone ListDump:
1005 => 1005
4000 => 50
4001 => 8002
4002 => 8004
4006 => 12
--Company--
SetName(): true
@@ -9795,7 +9808,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
constructor failed with: excessive CPU usage in list filter function
Your script made an error: excessive CPU usage in valuator function
*FUNCTION [Start()] regression/main.nut line [2120]
*FUNCTION [Start()] regression/main.nut line [2133]
[Infinite] CLOSURE
[list] INSTANCE

@@ -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
*

@@ -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
*

@@ -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 */

@@ -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

@@ -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;

@@ -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.