OpenTTD AI API 20241015-master-gd5b57a56f4
Public Member Functions
AIGroupList Class Reference

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

#include <script_grouplist.hpp>

Inheritance diagram for AIGroupList:
AIList

Public Member Functions

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

Additional Inherited Members

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

Detailed Description

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

Note
Neither AIGroup::GROUP_ALL nor AIGroup::GROUP_DEFAULT is in this list.

Constructor & Destructor Documentation

◆ AIGroupList()

AIGroupList::AIGroupList ( 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:
function IsType(group_id, type)
{
return AIGroup.GetVehicleType(group_id) == type;
}
local rv_groups = AIGroupList(IsType, AIVehicle.VT_ROAD);
Creates a list of groups of which you are the owner.
Definition script_grouplist.hpp:10
Class that handles all group related functions.
Definition script_group.hpp:8
static AIVehicle::VehicleType GetVehicleType(GroupID group_id)
Get the vehicle type of a group.
Class that handles all vehicle related functions.
Definition script_vehicle.hpp:8
@ VT_ROAD
Road type vehicle (bus / truck).
Definition script_vehicle.hpp:67