Drag[en]gine Script Module DragonScript  1.23
Dragengine.Utils.WeightedRandomList Class Reference

List of weighted entries for random retrieval. More...

Inheritance diagram for Dragengine.Utils.WeightedRandomList:

Classes

class  Entry
 Entry. More...
 

Public Member Functions

void add (Object object, float weight)
 Add object. More...
 
WeightedRandomList collect (Block ablock)
 New weighted random list with filtered elements. More...
 
Object find (Block ablock)
 Find entry with block. More...
 
void forEach (Block ablock)
 Visit entries with block. More...
 
int getCount ()
 Number of entries. More...
 
Object getObjectAt (int index)
 Object at index. More...
 
float getWeightAt (int index)
 Weight at index. More...
 
int indexOfObject (Object object)
 Index of first object or -1 if absent. More...
 
WeightedRandomList new ()
 Create list. More...
 
WeightedRandomList new (WeightedRandomList list)
 Create copy of list. More...
 
Object random ()
 Random object. More...
 
void removeAll ()
 Remove all objects. More...
 
void removeFrom (int index)
 Remove object from index. More...
 
void removeObject (Object object)
 Remove first occurance of object. More...
 
void setObjectAt (int index, Object object)
 Set object at index. More...
 
void setWeightAt (int index, float weight)
 Set weight at index. More...
 

Protected Member Functions

bool getDirtyThresholds ()
 Threshold are dirty. More...
 
Entry getEntryAt (int index)
 Entry at index. More...
 
float getMaxThreshold ()
 Maximum threshold. More...
 
void updateThresholds ()
 Update thresholds. More...
 

Detailed Description

List of weighted entries for random retrieval.

List entries have a weight assigned representing the percentage chance of the entry to be selected. If all entries have the same weight ths list behaves the same as Array.random(). Using different weights allows to favor or disfavor certain elements.

Member Function Documentation

◆ add()

void Dragengine.Utils.WeightedRandomList.add ( Object  object,
float  weight 
)

Add object.

◆ collect()

WeightedRandomList Dragengine.Utils.WeightedRandomList.collect ( Block  ablock)

New weighted random list with filtered elements.

Block is called with arguments (Object object, float Weight) and has to return true to include the object or false to exclude the object.

◆ find()

Object Dragengine.Utils.WeightedRandomList.find ( Block  ablock)

Find entry with block.

Black is called with arguments (Object object, float weight) and has to return true to select the object or false to continue searching.

◆ forEach()

void Dragengine.Utils.WeightedRandomList.forEach ( Block  ablock)

Visit entries with block.

Black is called with arguments (Object object, float weight).

◆ getCount()

int Dragengine.Utils.WeightedRandomList.getCount ( )

Number of entries.

◆ getDirtyThresholds()

bool Dragengine.Utils.WeightedRandomList.getDirtyThresholds ( )
protected

Threshold are dirty.

◆ getEntryAt()

Entry Dragengine.Utils.WeightedRandomList.getEntryAt ( int  index)
protected

Entry at index.

◆ getMaxThreshold()

float Dragengine.Utils.WeightedRandomList.getMaxThreshold ( )
protected

Maximum threshold.

◆ getObjectAt()

Object Dragengine.Utils.WeightedRandomList.getObjectAt ( int  index)

Object at index.

◆ getWeightAt()

float Dragengine.Utils.WeightedRandomList.getWeightAt ( int  index)

Weight at index.

◆ indexOfObject()

int Dragengine.Utils.WeightedRandomList.indexOfObject ( Object  object)

Index of first object or -1 if absent.

◆ new() [1/2]

WeightedRandomList Dragengine.Utils.WeightedRandomList.new ( )

Create list.

◆ new() [2/2]

WeightedRandomList Dragengine.Utils.WeightedRandomList.new ( WeightedRandomList  list)

Create copy of list.

◆ random()

Object Dragengine.Utils.WeightedRandomList.random ( )

Random object.

Exceptions
EInvalidParamList is empty.

◆ removeAll()

void Dragengine.Utils.WeightedRandomList.removeAll ( )

Remove all objects.

◆ removeFrom()

void Dragengine.Utils.WeightedRandomList.removeFrom ( int  index)

Remove object from index.

◆ removeObject()

void Dragengine.Utils.WeightedRandomList.removeObject ( Object  object)

Remove first occurance of object.

◆ setObjectAt()

void Dragengine.Utils.WeightedRandomList.setObjectAt ( int  index,
Object  object 
)

Set object at index.

◆ setWeightAt()

void Dragengine.Utils.WeightedRandomList.setWeightAt ( int  index,
float  weight 
)

Set weight at index.

◆ updateThresholds()

void Dragengine.Utils.WeightedRandomList.updateThresholds ( )
protected

Update thresholds.


The documentation for this class was generated from the following file: