OpenTTD GameScript API  20241118-master-gd2496b6ec4
Public Member Functions
GSVehicleList Class Reference

Creates a list of vehicles of which you are the owner. More...

Inheritance diagram for GSVehicleList:
GSList

Public Member Functions

 GSVehicleList (function filter_function,...)
 Apply a filter when building the list. More...
 
- Public Member Functions inherited from GSList
void AddItem (int item, int value)
 Add a single item to the list. More...
 
void RemoveItem (int item)
 Remove a single item from the list. More...
 
void Clear ()
 Clear the list, making Count() returning 0 and IsEmpty() returning true.
 
bool HasItem (int item)
 Check if an item is in the list. More...
 
int Begin ()
 Go to the beginning of the list and return the item. More...
 
int Next ()
 Go to the next item in the list and return the item. More...
 
bool IsEmpty ()
 Check if a list is empty. More...
 
bool IsEnd ()
 Check if there is a element left. More...
 
int Count ()
 Returns the amount of items in the list. More...
 
int GetValue (int item)
 Get the value that belongs to this item. More...
 
bool SetValue (int item, int value)
 Set a value of an item directly. More...
 
void Sort (SorterType sorter, bool ascending)
 Sort this list by the given sorter and direction. More...
 
void AddList (GSList *list)
 Add one list to another one. More...
 
void SwapList (GSList *list)
 Swap the contents of two lists. More...
 
void RemoveAboveValue (int value)
 Removes all items with a higher value than 'value'. More...
 
void RemoveBelowValue (int value)
 Removes all items with a lower value than 'value'. More...
 
void RemoveBetweenValue (int start, int end)
 Removes all items with a value above start and below end. More...
 
void RemoveValue (int value)
 Remove all items with this value. More...
 
void RemoveTop (int count)
 Remove the first count items. More...
 
void RemoveBottom (int count)
 Remove the last count items. More...
 
void RemoveList (GSList *list)
 Remove everything that is in the given list from this list (same item index that is). More...
 
void KeepAboveValue (int value)
 Keep all items with a higher value than 'value'. More...
 
void KeepBelowValue (int value)
 Keep all items with a lower value than 'value'. More...
 
void KeepBetweenValue (int start, int end)
 Keep all items with a value above start and below end. More...
 
void KeepValue (int value)
 Keep all items with this value. More...
 
void KeepTop (int count)
 Keep the first count items, i.e. More...
 
void KeepBottom (int count)
 Keep the last count items, i.e. More...
 
void KeepList (GSList *list)
 Keeps everything that is in the given list from this list (same item index that is). More...
 
void Valuate (function valuator_function,...)
 Give all items a value defined by the valuator you give. More...
 

Additional Inherited Members

- Public Types inherited from GSList
enum  SorterType {
  SORT_BY_VALUE ,
  SORT_BY_ITEM
}
 Type of sorter. More...
 
- Static Public Attributes inherited from GSList
static const bool SORT_ASCENDING = true
 Sort ascending.
 
static const bool SORT_DESCENDING = false
 Sort descending.
 

Detailed Description

Creates a list of vehicles of which you are the owner.

Constructor & Destructor Documentation

◆ GSVehicleList()

GSVehicleList::GSVehicleList ( function  filter_function,
  ... 
)

Apply a filter when building the list.

Parameters
filter_functionThe function which will be doing the filtering.
...The params to give to the filters (minus the first param, which is always the index-value).
Note
You can write your own filters and use them. Just remember that the first parameter should be the index-value, and it should return a bool.
Example:
local vehs_in_depot = GSVehicleList(GSVehicle.IsInDepot);
function IsType(vehicle_id, type)
{
return GSVehicle.GetVehicleType(vehicle_id) == type;
}
local road_vehs = GSVehicleList(IsType, GSVehicle.VT_ROAD);
Creates a list of vehicles of which you are the owner.
Definition: script_vehiclelist.hpp:9
Class that handles all vehicle related functions.
Definition: script_vehicle.hpp:8
static GSVehicle::VehicleType GetVehicleType(VehicleID vehicle_id)
Get the type of vehicle.
static bool IsInDepot(VehicleID vehicle_id)
Check if a vehicle is in a depot.
@ VT_ROAD
Road type vehicle (bus / truck).
Definition: script_vehicle.hpp:67