mirror of https://github.com/OpenTTD/OpenTTD
Add: [Script] Cloning ScriptList
parent
7200e7f509
commit
938acbe6ef
|
@ -828,6 +828,13 @@ function Regression::List()
|
||||||
print(" []:");
|
print(" []:");
|
||||||
print(" 4000 => " + list[4000]);
|
print(" 4000 => " + list[4000]);
|
||||||
|
|
||||||
|
print(" clone:");
|
||||||
|
local list3 = clone list;
|
||||||
|
print(" Clone ListDump:");
|
||||||
|
foreach (idx, val in list3) {
|
||||||
|
print(" " + idx + " => " + val);
|
||||||
|
}
|
||||||
|
|
||||||
list.Clear();
|
list.Clear();
|
||||||
print(" IsEmpty(): " + list.IsEmpty());
|
print(" IsEmpty(): " + list.IsEmpty());
|
||||||
|
|
||||||
|
@ -860,6 +867,12 @@ function Regression::List()
|
||||||
it = list.Next();
|
it = list.Next();
|
||||||
print(" " + it + " => " + list.GetValue(it));
|
print(" " + it + " => " + list.GetValue(it));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print(" Clone ListDump:");
|
||||||
|
foreach (idx, val in list3) {
|
||||||
|
print(" " + idx + " => " + val);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Regression::Map()
|
function Regression::Map()
|
||||||
|
|
|
@ -575,6 +575,13 @@
|
||||||
4006 => 12
|
4006 => 12
|
||||||
[]:
|
[]:
|
||||||
4000 => 50
|
4000 => 50
|
||||||
|
clone:
|
||||||
|
Clone ListDump:
|
||||||
|
1005 => 1005
|
||||||
|
4000 => 50
|
||||||
|
4001 => 8002
|
||||||
|
4002 => 8004
|
||||||
|
4006 => 12
|
||||||
IsEmpty(): true
|
IsEmpty(): true
|
||||||
0 => 5 (true)
|
0 => 5 (true)
|
||||||
ERROR: Next() is invalid as Begin() is never called
|
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)
|
2 => 6 (true)
|
||||||
3 => 6 (true)
|
3 => 6 (true)
|
||||||
9 => 0 (false)
|
9 => 0 (false)
|
||||||
|
Clone ListDump:
|
||||||
|
1005 => 1005
|
||||||
|
4000 => 50
|
||||||
|
4001 => 8002
|
||||||
|
4002 => 8004
|
||||||
|
4006 => 12
|
||||||
|
|
||||||
--Company--
|
--Company--
|
||||||
SetName(): true
|
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
|
constructor failed with: excessive CPU usage in list filter function
|
||||||
Your script made an error: excessive CPU usage in valuator 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
|
[Infinite] CLOSURE
|
||||||
[list] INSTANCE
|
[list] INSTANCE
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
* \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
* \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
||||||
* \li AIList instances can now be saved
|
* \li AIList instances can now be saved
|
||||||
* \li AIVehicleList_Station accepts an optional AIVehicle::VehicleType parameter
|
* \li AIVehicleList_Station accepts an optional AIVehicle::VehicleType parameter
|
||||||
|
* \li AIList instances can now be cloned
|
||||||
*
|
*
|
||||||
* \b 14.0
|
* \b 14.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
* \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
* \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint
|
||||||
* \li GSList instances can now be saved
|
* \li GSList instances can now be saved
|
||||||
* \li GSVehicleList_Station accepts an optional GSVehicle::VehicleType parameter
|
* \li GSVehicleList_Station accepts an optional GSVehicle::VehicleType parameter
|
||||||
|
* \li GSList instances can now be cloned
|
||||||
*
|
*
|
||||||
* \b 14.0
|
* \b 14.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -453,6 +453,20 @@ bool ScriptList::LoadObject(HSQUIRRELVM vm)
|
||||||
return true;
|
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()
|
ScriptList::ScriptList()
|
||||||
{
|
{
|
||||||
/* Default sorter */
|
/* Default sorter */
|
||||||
|
|
|
@ -145,6 +145,13 @@ protected:
|
||||||
|
|
||||||
virtual bool SaveObject(HSQUIRRELVM vm) override;
|
virtual bool SaveObject(HSQUIRRELVM vm) override;
|
||||||
virtual bool LoadObject(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:
|
public:
|
||||||
typedef std::set<SQInteger> ScriptItemList; ///< The list of items inside the bucket
|
typedef std::set<SQInteger> ScriptItemList; ///< The list of items inside the bucket
|
||||||
|
|
|
@ -23,6 +23,13 @@ bool ScriptTileList::SaveObject(HSQUIRRELVM vm)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptObject *ScriptTileList::CloneObject()
|
||||||
|
{
|
||||||
|
ScriptTileList *clone = new ScriptTileList();
|
||||||
|
clone->CopyList(this);
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
|
void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t1)) return;
|
if (!::IsValidTile(t1)) return;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
class ScriptTileList : public ScriptList {
|
class ScriptTileList : public ScriptList {
|
||||||
protected:
|
protected:
|
||||||
virtual bool SaveObject(HSQUIRRELVM) override;
|
virtual bool SaveObject(HSQUIRRELVM) override;
|
||||||
|
virtual ScriptObject *CloneObject() override;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Adds the rectangle between tile_from and tile_to to the to-be-evaluated tiles.
|
* Adds the rectangle between tile_from and tile_to to the to-be-evaluated tiles.
|
||||||
|
|
Loading…
Reference in New Issue