GIANTS Game Engine v10 Documentation



Table of Contents

  1. Chapter 01: Overview
    1. Enable development controls
    2. Runtime development key short-cuts
    3. Console Command Reference
  2. Chapter 02: Editor
    1. Viewport
    2. Scenegraph
    3. Attributes
    4. Toolbar
    5. Terrain
    6. User Attributes
    7. Scripting
    8. Terrain Editing
    9. Replace Dialog
    10. Interactive Placement
    11. Other functionality
    12. Key short-cuts
  3. Chapter 03: Studio
    1. GIANTS Studio
    2. Overview of panels
    3. Creating a new project
    4. Global and local variables
    5. Callstack panel
    6. Running new scripts during debugging
    7. Breakpoints
    8. Game output
    9. Searching in code
    10. Shortcuts
  4. Chapter 04: Scripting API Reference
    1. Script Reference(1.2.0.1)
      1. General
      2. Animation
      3. AI
      4. I3D
      5. Handtools
      6. Events
      7. Objects
      8. Placeables
      9. Triggers
      10. Utils
      11. Vehicles
      12. Specializations
      13. animals
      14. AnimalHusbandryModules
      15. shop
      16. collections
      17. densityMaps
      18. economy
      19. effects
      20. weather
      21. farms
      22. fieldJobs
      23. dialogs
      24. GUI
      25. materials
      26. misc
      27. missions
      28. modHub
      29. Player
      30. sounds
      31. trainSystem
      32. tutorials
      Engine Reference(8.0.0.0)
      1. General
      2. Entity
      3. Node
      4. Scenegraph
      5. Lighting
      6. Camera
      7. Shape
      8. Particle System
      9. Physics
      10. Spline
      11. Animation
      12. Overlays
      13. Sound
      14. Input
      15. XML
      16. Network
      17. Callbacks
      18. Text Rendering
      19. Terrain Detail
      20. Tire Track
      21. Editor
      22. AI
      23. Rendering
      24. String
      25. Math
      26. I3D
      27. Fillplanes
      28. ModDownloadManager
    2. Foundation Reference
      1. Scenegraph
      2. Input
  5. Chapter 05: Tutorials
    1. Tutorial 1 - Load i3d files and basics
    2. Tutorial 2 - Light functions, global time and rendering text
    3. Tutorial 3 - User Attributes
    4. Tutorial 4 - Timers
    5. Tutorial 5 - Physics
    6. Tutorial 6 - Overlays
    7. Tutorial 7 - Audio
  6. Chapter 06: Exporter
    1. Autodesk Maya1 I3D Exporter
      1. Material Export Options
      2. Manual Installation
    2. Blender I3D Exporter
  7. Chapter 07: Content Creation - Artwork Guide
    1. Autodesk Maya
    2. Texturing
  8. Chapter 08: I3D Format
    1. Introduction
    2. Features
    3. Overview
    4. Specification
      1. General Layout
      2. Materials
      3. Shapes
      4. Dynamics
      5. Scenegraph
      6. Animation


Overview



Enable development controls



Open the file game.xml and change the value of controls from false to true.

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<game>
  ...
  <development>
    <controls>true</controls>
  </development>
</game>


Runtime development shortcuts


Key Function
~ or ` Toggle console
F2 Show frame rate
F3 Toggle frame rate limiter
F4 Wireframe mode
F5 Toggle debug rendering
F7 Toggle camera
F8 Toggle stats


Console command reference


help

Description
List all available commands

showFps

Description
Show frames per second

enableFramerateLimit

Description
Enable/disable frames-per-second limiter

framerateLimitFPS

Description
Frames per second limit attribute

listEntities

Description
Print detailed entity list

listResources

Description
Print detailed resource list

parallelRenderingAndPhysics

Description
Enable parallel rendering and physics

exit, quit or q

Description
Quit the application






Editor

Table of Contents

  1. Viewport
  2. Scenegraph Panel
  3. Attributes Panel
  4. Toolbar
  5. Terrain Editing
  6. User Attributes
  7. Animation Panel
  8. Particle System Panel
  9. Spline Editing
  10. Scripting
  11. Replace Dialog
  12. Interactive Placement
  13. Other functionality
  14. Keyboard shortcuts



If you start up the Editor, you might not have all the panel windows open. To open other panel windows open the menu option window and enable the panel you want. You can adjust the width and height of the panels by dragging the outlines and if you want to close a window you can simply press the cross right of the panel name.


Viewport




Navigation

The navigation is quite like in Maya. If you have nothing open in your editor I suggest you quickly open a simple i3d file otherwise you won’t see much of an effect. If it's too dark in your scene just create a light by going to Create–>Light.

Some shortcuts:
LMB = Left Mouse Button
RMB = Right Mouse Button
MMB = Middle Mouse Button
Alt + LMB = Press and hold the Alt-Key and the left mouse button.

Alt + LMB rotates the camera.
Alt + RMB moves the camera forward and backward.
Alt + MMB causes the camera to pan.

If you don’t have a middle mouse button, you can press LMB and RMB instead.

View Options

By simply right-clicking into the viewport panel you get the View Options. Sometimes it’s useful to use different cameras in a scene. You can create them once and then with the View Options you can choose the camera to view at your scene from different angles quickly.

You might notice that if you rotate, the camera is rotated. If you have a big level this behaviour is very useful, but if you want to look at one particular object this can be quite awkward. To change the rotation to Framed Rotate you first have to select your object either by clicking on it directly or by choosing it from the scene-graph and the framing the selected object by pressing the F key. Now you can simply click (RMB) on the screen to open the View Options and choose Framed Rotate. Now the camera is rotating around your last framed object.

You can select the visual appearance of the object with Shaded (solid surface) or Wireframe (only edges of the object are visible)

If you have large scenes, you can toggle the visibility of lights, audio sources, physics and the cameras by checking them on the show submenu.

You can also use the Selectable submenu to toggle whether you can select lights, audio sources or cameras.

Furthermore you can toggle the grid and the polycount on and off.

Profile gives you the ability to choose different hardware profiles adequate for your system.

Debug can be used to find errors (e.g. on your 3D model)


Scenegraph Panel

A very useful feature of the GIANTS Editor is the scenegraph. If you don’t have it on the screen, just go to menu window and hit scenegraph. It is basically the same you have in Maya. It shows all objects you have in your scene and also the parent-child relationship between your objects.



Let’s just make a little scene with some Transform Groups. The Transform Group is the basic building block of your scene. You can use a TransformGroup to move all the attached objects just by moving the Transform Group since the children inherit the transformations of the parent. To create a new Transform Group go to Create and hit TransformGroup. Now you can see it in the Scenegraph, its name is transform. To change the name just select it and go to the attributes panel. At the very top of the panel you can choose the name of your object. Make two TransformGroups and name them Parent and Child. If you move them around you see that their transformations are independent, the movement of the parent doesn’t affect the child. Now let’s make the appropriate relationship between the two. Select the child in the scenegraph panel and go to Edit->Cut. Now select your parent and hit Edit->Paste. Additionally by pressing MMB on the child, dragging it over parent and releasing MMB, the same as above will happen.

As you can see now, the child is now connected to the parent. If you now move around the parent, the transformation of the child is affected too whereas the child can be moved around without affecting the parent.




There can be 6 types of objects in your scene: Triangle Meshes, Splines, Cameras, Transform Groups, Lights, Terrains and Audio Sources.

It is also possible to use CTRL + C to copy objects, CTRL + X to cut objects and CTRL + V to paste objects. Notice that pasted objects are always children of the currently selected object. If you want to paste an object on the highest hierarchy level of the scenegraph be sure that nothing is selected in the scenegraph. This can be achieved by clicking at an empty space in the scenegraph panel.


Attributes Panel

If you don’t see the attributes panel go to Windows->Attributes then select an object in the scenegraph or the viewport. One important thing to notice is, that if the background color of an attribute turns red, you entered a value that isn’t allowed. (e.g. scale values other than 1 for a dynamic rigid body object) The background color of animated attributes is yellow.




Toolbar




The toolbar looks like this. If you're pointing on the icons with your mouse, a text with the functionality of the tool is displayed.

Let’s quickly go through them from left to right.

File Operations
History
Physics
If you hit the play icon, the physics will simulate.

Toggle Local-World Mode
A handy tool is the toggle Local-World Mode, it changes the orientation of the viewport transform gizmo from the local space of your object to world space.

Grid Snapping
Use this option to snap objects to a predefined grid.

Terrain and Terrain Foliage
Texture Reload
Script Editor


Terrain Editing




To test the terrain sculpting, just open the terrain test scene. Now you have a terrain to play with. Open the terrain editing panel with window->Terrain Editing. (If the scenegraph panel is still open it might cut off a bit, just close it to get more space.)



If the terrain sculpt mode is active now, you can raise or lower the surface of your terrain by using RMB and LMB. MMB can be used to smooth and the value defines the force with which you pull or push. What happens here is, that you are painting a height map, that defines the height of each point of your terrain by giving it a grey-value. The attributes Opacity, Hardness and the Value are defining the "brush" you are painting the height map with. Just play around with the setting. You can change the radius of the brush with the shortcuts "V" and "B" and you can change the opacity value of the brush quickly with "N" and "M".

In the terrain texture paint mode next to the terrain sculpt icon you can colorize your terrain with different textures.
The used texture layers are defined in the i3d-file. (If you want to change the texture layers, you have to open the i3d with a text editor and change the layers there) Just choose your texture and paint onto your terrain. With the Chunk vis checkbox on, you can see exactly which texture layers you used in a chunk by what amount. You can use as many texture layers as you want, but you are limited to a maximum of four texture layers per chunk.

With the Terrain Foliage Paint Mode active, you can paint your foliage onto your terrain, it's the same thing as if you would paint onto your terrain - not with a texture but with foliage. LMB adds foliage, RMB removes foliage.


User Attributes




The user attributes panel is typically not visible if you open the editor for the first time. So go to Windows->User Attributes. Select an object in the scenegraph to see its user attributes.

User Attributes can be defined in the editor and then be used in the engine (eg. within a script). This enables you to define object specific attributes for every object in the scene.


Animation Panel




You can preview animation sets with the animation panel.

Particle System Panel




The particle system panel allows you to edit particle systems with real time preview.

Spline Editing




You can edit splines by picking a control vertex (CV) of a spline and moving it around. Delete or insert new control vertices with the keys delete and insert.

Scripting

Here you can execute script snippets. With ENTER, you can add new lines. SHIFT+ENTER will execute the code in the text field.

Type in the following:

print("hello world from the GIANTS Editor");

Then hit SHIFT + ENTER and the string is printed out above.


The scripting can be useful for many things. For example you can run this script snippet to test the fog settings in an i3d scene:

setFog("exp2", 0.002, 0, 0.8, 0.81, 0.97);


Replace Dialog




If you want to replace an object in your scene, you can go to Edit->Replace to open the replace panel. Select the object you want to replace, then hit load. Do likewise with the object you want to replace with and choose whether you want to keep the User Attributes or not. Now you can replace one single object by hitting replace or you can replace all objects that are similar to the one you selected by hitting replace all.

Note: replace all does only work with single objects, but not with hierarchies of objects, however the single replace function works.
This feature is quite useful because you can use it to substitute an object reference feature within your i3d scene file.


Interactive Placement

This is a really nice feature of the editor, you should try it at least once!
To place an object on the surface of another object, you can simply select the object you want to place and then press CTRL + B + LMB, while pointing at your desired location. The selected object will then instantly be set to the location you’ve chosen.

Hint: you can do this with all your objects within your scenegraph and also with the camera or light sources. E.g. you can select the current camera and then place the camera at a location far away, allowing for fast relocation of the camera.

If you keep the LMB pressed and hit SHIFT or CTRL you can clone the selected object at the current mouse position. SHIFT will just clone the object while CTRL will add a random rotation in the Y-axis. (Useful feature if you want to create a group with hundreds of randomly rotated objects like a forest)

Other functionality


Edit->Clear History: This clears the undo/redo history.

Edit->Move to Camera: Moves the selected object in front of the current camera

Navigation Speed: Moves the camera faster or slower. Use - and + to adjust the speed.


Default keyboard shortcuts

Key Function
W A S D Navigation
Alt + LMB Rotate camera
Alt + MMB Pan camera
Alt + RMB Zoom camera
Alt + LMB + RMB Move camera up or down and left or right camera
F Frame selected object
- Decrease navigation speed
+ Increase navigation speed
4 Wireframe mode
6 Shaded mode
Ctrl-S Save
Ctrl-Z Undo
Ctrl-W Replace Dialog
Ctrl-X Cut
Ctrl-C Copy
Ctrl-V Paste
Ctrl-Shift-C Copy X,Y,Z components at once
Ctrl-Shift-V Paste X,Y,Z components at once (can also be copied from a text source in the format "x y z")
Delete Delete
Ctrl-D Duplicate
Ctrl-F Move to Camera
Ctrl-B Interactive placement (hold left mouse button to move around)
Shift Interactive placement paint
Ctrl Interactive placement paint with random rotation around y axis
Ctrl-H Hide object
Shift-H Show object
Ctrl-G Group objects
Ctrl-R Pick replace value in viewport (Terrain edit modes)
V Decrease brush radius
B Increase brush radius
N Decrease brush opacity
M Increase brush opacity
F8 Toggle stats
Shift + Enter Execute Script (Script Window)
X Absolute grid snapping
J Relative grid snapping
Delete Delete spline control vertex
Insert Insert new spline control vertex
Left Previous spline control vertex
Right Next spline control vertex
Up or Down First spline control vertex
S Stitch spline endpoints
O Toggle spline open/close
R Reverse spline
Ctrl-L Create light


Debugger

Table of Contents

  1. GIANTS Debugger/Studio
  2. Overview of panels
  3. Creating a new project
  4. Global and local variables
  5. Callstack panel
  6. Running new scripts during debugging
  7. Breakpoints
  8. Game output
  9. Searching in code
  10. Shortcuts

GIANTS Debugger/Studio

The GIANTS Studio is a new tool for creating, editing and debugging script mods. It works as an editor and a “remote” debugger in one. It interacts with the game state and provides you with information about the game state.

Possible use-case scenarios:

The Debugger can be used on all kinds of mod configurations. These are the most common three configurations:

Working on a single mod (fast iteration time, but only compatible with singeplayer):
Unzip your mod and put the mod in the “mods” directory (by default in Documents/My Games/FarmingSimulator2019/mods). Make sure that the layout of the mod is correct, i.e. the modDesc.xml is directly in the mod folder (i.e. mods//modDesc.xml). Then create a new project in the Debugger. In “Project Settings”, set “Mod Name” to be the same name as the name of the mod folder and set the “Mod Directory” as a path to the directory of the mod (mods/). In case the mod zip file is already in the “mods” directory remove the zip file from the “mods” directory, because the zip file has priority over the directory when the game is loading.

Working on multiple mods at the same time (fast iteration time, but only compatible with singeplayer):
Follow the instructions above, but when you create a project in the Debugger, set the “Mod Directory” to “mods” directory instead of the specific mod directory. This way you can edit several mods at the same time. In this configuration, the “Mod Name” is not important, you can call it anything you like.

Working on a single mod outside the “mods” directory (also compatible with multiplayer):
This is the most complex configuration, and it is the only one that lets you debug mods in multiplayer. Place the mod zip file in the “mods” directory and unzip it somewhere else. In “Project Settings” set the “Mod Name” to match with the name of the zip file but without .zip at the end) and set the “Mod Directory” as a path to the unzipped directory. For every change you make in the Debugger, you will have to re-create the mod zip file and copy it to the “mods” directory before you start the game. External tools for zipping are useful for this purpose (not included).


Overview of panels



Creating a new project

First you need to open or create a project.


Most of the required parameters are self-explanatory. The “Mod Directory” can be a path to a single mod or a “mods” directory if you are working on several mods at the same time. If you are working on a single mod, the “Mod Name” must have the same name as the .zip file. The “User Profile App Directory” should be saved as a path to a folder where the game stores user data (changes are not needed by default if the game configuration has not been changed manually). The debugger uses sockets to communicate with the game and listens at the port defined as the “Debug Network Port”.


Global and local variables

The function of the “Globals” and “Locals” panels is the same: to explore the value of local and global variables at a current execution point (using breakpoints to halt execution and observe these variables, or by hitting the ‘break all’ button). By right-clicking on a variable, you can add it as a “Watch” or a “Breakpoint”.


The ”Watch” panel is similar to the “Globals” and “Locals” panel, but instead of global or local variables, you can select variables that you would like to ‘watch’. Values are updated every time a breakpoint is hit or when you execute the code step-by-step. Variable names can be written like most other simple Lua statements:



Callstack panel

The “Callstack” panel shows you the callstack at a current execution point. Double-click on a line to open a file at the location of the call. The Debugger even allows you to step through some of the base game functions for which the source code has been made public. Grayed-out lines are parts of code that have not been made public.



Running new scripts during debugging

The “Script Console” executes user-defined Lua code when execution is paused (by hitting a breakpoint or break-all being pressed). Enter your code in the bottom part of the panel and press Ctrl + Enter to execute it.



Breakpoints

The “Breakpoints” panel is where you manage breakpoints.

Regular breakpoints can be placed in the code by clicking on the vertical gray bar on the left of the code panel. You can also use F9 to enable/disable a breakpoint at the current position. The program will stop running when it tries to execute a line with a breakpoint.

Data breakpoints can be placed by right-clicking on a variable name in the “Globals”/”Locals”/”Watch” panel or by right-clicking on a name in the text editor. A data breakpoint will be hit when the data for the specified variable changes.


You can fine-tune a breakpoint by adding a conditional expression and/or hit count condition to it. These conditions are evaluated each time a breakpoint is hit and the code will only stop executing once the conditions are met.



Game output

The “Output” panel shows the game’s log output. If a script error is reported, this panel will provide you with the file name and line number, so that you can double-click on it and view the code causing the error. The output is the same as the log file written by the game.



Searching in code

The “Find Results” panel shows search results from the “Find in Files” dialog. Double-clicking on a result opens a file at the search hit location.


The “Find Replace” window behaves in a similar way to other text editors. “Find” and “Replace” directly show the results in the text editor; while “Find in Files” searches through the entire file and shows results in the “Find Results” panel. Other search modes are available too:





Default keyboard short-cuts

KeyFunction
Ctrl-NNew file
Ctrl-OOpen file
Ctrl-SSave file
Ctrl-Shift-SSave all files
Ctrl-QQuit application
Ctrl-ZUndo
Ctrl-YRedo
Ctrl-FFind
Ctrl-HReplace
Ctrl-Shift-FFind in files
F3Find next
Shift-F3Find previous
Ctrl-Shift-GGo to file
Ctrl-GGo to line
Ctrl-KComment lines
Ctrl-Shift-KUncomment lines
Ctrl-WClose tab
Ctrl-Shift-TReopen tab
Alt-UpMove line up
Alt-DownMove line down
Alt-LeftNavigate backwards
Alt-RightNavigate forward
F5Run / Continue execution
Ctrl-F5Run Without Debugging
F7Pause execution
F6Stop execution
F9Toggle Breakpoint
F11Step Into
F10Step Over
Shift-F11Step Out

Scripting API Reference

Script Version: 1.2.0.1

AchievementMessage

Description
Achievement message display element.
-- Used to display a message in the HUD when a new achievement is unlocked.
--@category GUI

new

Description
Create a new instance of AchievementMessage.
Definition
new(string hudAtlasPath, table inputManager, table guiSoundPlayer, ContextActionDisplay ContextActionDisplay)
Arguments
stringhudAtlasPathPath the HUD texture atlas
tableinputManagerInputBinding reference for achievement acknowledgment input
tableguiSoundPlayerGuiSoundPlayer reference for playing a sound cue
ContextActionDisplayContextActionDisplayreference for visibility checks (it occupies the same space on the HUD)
Return Values
tableAchievementMessageinstance

onMenuVisibilityChange

Description
Handle changes in menu visibility.
Keeps track of menu visibility state to avoid showing (or updating) an achievement message when the menu is active.
Definition
onMenuVisibilityChange()

showMessage

Description
Show an achievement message.
The message will be shown as soon as the player is not in a menu and there is no context action display visible.
Messages will however not be checked for overlaps. The caller has to make sure that achievements are displayed
sequentially.
Definition
showMessage(string title, string description, string iconFilename, table iconUVs, float duration)
Arguments
stringtitleAchievement title text
stringdescriptionAchievement description text
stringiconFilenamePath to the achievement icon texture
tableiconUVsUV coordinates of achievement icon with icon texture
floatdurationMaximum display duration in milliseconds

update

Description
Update display state.
Definition
update()

beginShowMessage

Description
Actually start showing the message when nothing is obstructing the view.
Definition
beginShowMessage()

hideMessage

Description
Hide the message, including animation.
Also removes the acknowledgment input events.
Definition
hideMessage()

draw

Description
Draw the achievement message if necessary.
Definition
draw()

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()

setScale

Description
Set this element's scale.
Definition
setScale()

getBackgroundPosition

Description
Get the position of the background element, which provides this element's absolute position.
Definition
getBackgroundPosition(scale Current, float width)
Arguments
scaleCurrentUI scale
floatwidthScaled background width in pixels
Return Values
floatXposition in screen space
floatYposition in screen space

createBackground

Description
Create the empty background overlay
Definition
createBackground()

createComponents

Description
Create required display components.
Definition
createComponents()

createFrame

Description
Create the message frame.
Definition
createFrame()

createIcon

Description
Create the achievement icon.
Definition
createIcon()

AnimalScreen

Description
Animal Buying Screen.
AnimalScreen = {}

new

Description
Constructor
Definition
new(table target, table metatable)
Arguments
tabletarget
tablemetatable
Return Values
tableselfinstance
Code
53function AnimalScreen:new(target, custom_mt, animalController, l10n, messageCenter)
54 local self = ScreenElement:new(target, custom_mt or AnimalScreen_mt)
55
56 self:registerControls(AnimalScreen.CONTROLS)
57
58 self.l10n = l10n
59 self.messageCenter = messageCenter
60 self.animalController = animalController
61
62 self.animalController:setSourceUpdateCallback(self.onSourceUpdate, self)
63 self.animalController:setTargetUpdateCallback(self.onTargetUpdate, self)
64 self.animalController:setNoValidHusbandryCallback(self.onNoValidHusbandry, self)
65 self.animalController:setHusbandryIsFullCallback(self.onHusbandryIsFull, self)
66 self.animalController:setTrailerFullCallback(self.onTrailerIsFull, self)
67 self.animalController:setInvalidAnimalTypeCallback(self.onInvalidAnimalType, self)
68 self.animalController:setAnimalNotSupportedByTrailerCallback(self.onAnimalNotSupportedByTrailer, self)
69 self.animalController:setNotEnoughMoneyCallback(self.onNotEnoughMoney, self)
70 self.animalController:setCanNotAddToTrailerCallback(self.onCanNotAddToTrailer, self)
71 self.animalController:setAnimalInUseCallback(self.onAnimalInUse, self)
72
73 self.isSourceSelected = true
74
75 self.isOpen = false
76 self.lastBalance = 0
77 self.sourceElementToAnimal = {}
78 self.targetElementToAnimal = {}
79
80 self.dofState = DepthOfFieldState.createFullscreenBlur()
81
82 return self
83end

onOpen

Description
Callback on open
Definition
onOpen()
Code
87function AnimalScreen:onOpen()
88 AnimalScreen:superClass().onOpen(self)
89
90 self.isOpen = true
91 self.isUpdating = false
92
93 g_gameStateManager:setGameState(GameState.MENU_ANIMAL_SHOP)
94
95 self.dofState:recordState() -- record current state before changing
96 self.dofState:apply() -- apply blur effect
97
98 self:updateScreen()
99
100 self.messageCenter:subscribe(MessageType.HUSBANDRY_ANIMALS_CHANGED, self.onAnimalsChanged, self)
101end

onClose

Description
Callback on close
Definition
onClose(table element)
Arguments
tableelement
Code
106function AnimalScreen:onClose(element)
107 AnimalScreen:superClass().onClose(self)
108 self.animalController:close()
109 self.isOpen = false
110 self.sourceElementToAnimal = {}
111
112 g_currentMission:resetGameState()
113
114 self.messageCenter:unsubscribeAll(self)
115
116 self.dofState:reset() -- reset depth of field parameters (blur effect)
117end

onClickBack

Description
Callback on click back
Definition
onClickBack()
Code
262function AnimalScreen:onClickBack()
263 AnimalScreen:superClass().onClickBack(self)
264 self:changeScreen(nil)
265end

onClickOk

Description
Callback on click cancel
Definition
onClickOk()
Code
269function AnimalScreen:onClickOk()
270 AnimalScreen:superClass().onClickOk(self)
271
272 if self.isSourceSelected then
273 self.animalController:moveToTarget(self.listSource.selectedIndex)
274 else
275 self.animalController:moveToSource(self.listTarget.selectedIndex)
276 end
277end

BaseMission

Description
Input context name for identification, does not take care of proper context handling

new

Description
Create a new base mission
Definition
new(string baseDirectory, table customMt, table missionCollaborators)
Arguments
stringbaseDirectoryMission scripts base directory
tablecustomMtSub-class meta table
tablemissionCollaboratorsMissionCollaborators object containing a defined collection required object
references for a mission.

initialize

Description
Initialize mission after instantiation.
Create complex members and call dependency methods in here so that mission instantiation cannot fail.
Definition
initialize()

createHUD

Description
Create the in-game HUD display.
Definition
createHUD()

addHelpButtonText

Description
Deprecated: Replaced by InputBinding:setActionEventText()
Definition
addHelpButtonText()

subscribeSettingsChangeMessages

Description
Subscribe to relevant game settings changes.
Definition
subscribeSettingsChangeMessages()

subscribeGuiOpenCloseMessages

Description
Subscribe to GUI notifications of opening and closing.
Definition
subscribeGuiOpenCloseMessages()

onBeforeMenuOpen

Description
Handle a menu open event.
Definition
onBeforeMenuOpen()

onAfterMenuClose

Description
Handle a menu closed event.
Definition
onAfterMenuClose()

registerActionEvents

Description
Register required input action events.
Definition
registerActionEvents()

registerPauseActionEvents

Description
Register action events for pause actions.
Event registration in this method is enclosed in an input binding registration context (InputBinding:beginActionEventsModification()).
Make sure that this is only called when all other registration-context altering code is done.
Definition
registerPauseActionEvents()

onPause

Description
Input event for "pause".
Definition
onPause()

onConsoleAcceptPause

Description
Input event for breaking pause on consoles.
Definition
onConsoleAcceptPause()

onToggleHelpText

Description
Input event for "toggle help text".
Definition
onToggleHelpText()

onSwitchVehicle

Description
Input event for "switch vehicle".
Definition
onSwitchVehicle(directionValue Numeric)
Arguments
directionValueNumericvalue for switch direction, 1 is the next, -1 is the previous vehicle

Binding

Description
Binding of input to actions.
--@category Input
--@xmlConfig binding#device Device ID, must match a value returned by engine function getGamepadId() or one of the
constants of InputDevice.DEFAULT_DEVICE_NAMES.

new

Description
Create a new Binding instance.
Definition
new(action InputAction, deviceId ID, axisNames List, axisComponent Component, inputComponent Component, index Binding)
Arguments
actionInputActionreference which is being bound to an input
deviceIdIDof the input device whose input is being bound to the given action
axisNamesListof input axis names. If the list contains more than one axis, any axis before the last one is a modifier.
axisComponentComponentof the last given axis to bind to the given action.
inputComponentComponentof a physical axis (e.g. analog stick) to bind
indexBindingindex, 1 primary, 2 secondary, etc.
Return Values
booltrueif allowed
NewBindinginstance

createFromXML

Description
Create a new Binding instance from an XML element.
Definition
createFromXML(int xmlFile, string elementTag, bool isLocked)
Arguments
intxmlFileXML file handle
stringelementTagTag of the element to parse as a Binding
boolisLockedIf true, the binding belongs to a locked action
Return Values
booleanisAllowedtrue if fillType is supported else false
Bindinginstanceinitialized with values from XML and the given parameters

saveToXMLFile

Description
Save this binding to XML.
Definition
saveToXMLFile(xmlFile Input, elementTag Element)
Arguments
xmlFileInputbinding settings XML file handle
elementTagElementtag of this binding
Return Values
booleanisSupportedtrue if fillType is supported else false

updateData

Description
Update a binding with a new input target.
Always use this method to change existing bindings or risk invalid state.
Definition
updateData(deviceId (New), axisNames List, inputComponent [optional])
Arguments
deviceId(New)device ID
axisNamesListof input axis names. Make sure these are valid in the context of this binding's state (i.e. device and action axis type).
inputComponent[optional]Direction of a physical axis (e.g. analog stick) to bind, defaults to positive.
Return Values
floatfreeCapacityfree capacity

updateInput

Description
Update this binding's input state.
Definition
updateInput(inputValue Current)
Arguments
inputValueCurrentinput value of the last axis in self.axisNames
Return Values
booleanisAllowedtrue if toolType is allowed else false

setIsAnalog

Description
Set this binding's analog input flag.
Definition
setIsAnalog()
Return Values
tableinstanceinstance of object

setIndex

Description
Set this binding's index and update internal state.
Definition
setIndex()
Return Values
tableinstanceinstance of object

setActive

Description
Set this binding's active state.
Only active bindings are updated and can trigger action events.
Definition
setActive()
Return Values
integerharvestPixelsSumharvest of pixels sum
integerharvestNumPixelsharvest number of pixels
floatsprayFactorspray factor
floatplowFactorplow factor
floatlimeFactorlime factor
floatweedFactorweed factor
integergrowthStategrowth state
floatmaxAreamax area

setFrameTriggered

Description
Set the frame trigger flag which shows if this binding has triggered an event this frame.
Definition
setFrameTriggered()

getFrameTriggered

Description
Get the frame trigger flag which shows if this binding has triggered an event this frame.
Definition
getFrameTriggered()

setComboMask

Description
Set and store the combo bit mask for this binding.
This is agnostic of the actually bound device because a binding can only map input on one specific device.
Definition
setComboMask(int comboMask)
Arguments
intcomboMaskCombo mask

getComboMask

Description
Get the combo bit mask.
Definition
getComboMask()
Return Values
intCombobit mask

hasCollisionWith

Description
Check if there is a collision between this binding and another one.
Two bindings collide if they bind the same input on the same axes of the same device.
Definition
hasCollisionWith(otherBinding Other)
Arguments
otherBindingOtherbinding to check for collision
Return Values
Trueifthere is a collision.

isAlternativeTo

Description
Check if this binding is an alternative to another one on the same action.
Two bindings are alternatives if they bind different input on the same axis of the same device category to the same action.
Definition
isAlternativeTo(otherBinding Other)
Arguments
otherBindingOtherbinding to check if it's an alternative
Return Values
Trueifthis and the other binding are alternatives of each other

clone

Description
Create a new instance of Binding with the same state as this instance.
Definition
clone()
Return Values
ClonedBindinginstance

copyInputStateFrom

Description
Copy binding input state from another binding.
Definition
copyInputStateFrom()
Return Values
integerretret
integertotaltotal

isSameSlot

Description
Check if this binding occupies the same binding slot as another binding on the same action.
Definition
isSameSlot()

getOppositeAxisComponent

Description
Get the opposite axis component for a given axis component.
Definition
getOppositeAxisComponent(axisComponent One)
Arguments
axisComponentOneof the constant values of Binding.AXIS_COMPONENT
Return Values
integerchangedValuechanged value

getOppositeInputComponent

Description
Get the opposite input component for a given input component.
Definition
getOppositeInputComponent(inputComponent One)
Arguments
inputComponentOneof the constant values of Binding.INPUT_COMPONENT
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area

makeId

Description
Make and assign a binding ID.
Definition
makeId()

needJapanesePlaystationButtonSwap

Description
Determine if we need to swap buttons for Japanese Playstation controllers by their convention.
Definition
needJapanesePlaystationButtonSwap()
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area pixles

swapJapanesePlaystationButtons

Description
Swaps buttons for Japanese Playstation controllers if contained in the given axis names.
Definition
swapJapanesePlaystationButtons(table axisNames)
Arguments
tableaxisNamesAxis names array, will be changed in place

toString

Description
Get a string representation of this binding.
Definition
toString()
Return Values
integernumPixelsnumber of pixels
integertotalNumPixelstotal number of pixels

BitmapElement

Description
Display element for images.
-- Used layers: "image" for the display image.
--@xmlConfig GuiElement#offset string [optional] Position offset of the displayed image relative to this element's origin in reference resolution, defaults to [0, 0]. Format: "[x]px [y]px".

setImageColor

Description
Set this element's image color.
Omitted (nil value) color values have no effect and the previously set value for that channel is used.
Definition
setImageColor(state GuiOverlay, r Red, g Green, b Blue, a Alpha)
Arguments
stateGuiOverlaystate for which the color is changed, use nil to set the default color
rRedcolor value
gGreencolor value
bBluecolor value
aAlphavalue (transparency)

setImageRotation

Description
Set this element's image overlay's rotation.
Definition
setImageRotation(float rotation)
Arguments
floatrotationRotation in radians

BoxLayoutElement

Description
Layout element which lays out child elements in regular rows or columns.
-- Exceptions are elements whose "layoutIgnore" property is true.
-- Used layers: "image" for a background image.
--@category GUI
--@xmlConfig GuiElement#alignmentX string [optional] Horizontal alignment of the layout, defaults to "left". Valid values are "left", "right" and "center".

getLayoutCells

Description
Extract a flow / cell data table from this box layout's elements.
Definition
getLayoutCells(ignoreVisibility Visibility)
Arguments
ignoreVisibilityVisibilityflag for element eligibility
Return Values
Flowsandcells as nested tables: [flowIndex][cell index] = cell data {element, flowSize, lateralSize}

getLayoutSizes

Description
Calculate layout sizes based on flow cell data.
Definition
getLayoutSizes()
Return Values
Listoflateral flow sizes, total lateral sizes (sum of lateral flow sizes), maximum flow size in direction of flow

getAlignmentOffset

Description
Get the layout space starting position offset for elements based on flow dimensions and alignments.
Definition
getAlignmentOffset(flowSize Flow, flowLateralSize Total)
Arguments
flowSizeFlowsize in flow direction (e.g. height for vertical flows)
flowLateralSizeTotalflow size orthogonal to flow direction (e.g. combined width of all columns for vertical flows)
Return Values
LayoutXstarting offset, layout Y starting offset, Layout X direction {-1|1}, Layout Y direction {-1|1}

getElementAlignmentOffset

Description
Calculate element offsets for margins and to counteract alignment updates in GuiElement.updateAbsolutePositions()
Definition
getElementAlignmentOffset(directionX Layout, directionY Layout)
Arguments
directionXLayoutX direction as a signed factor {-1|1}
directionYLayoutY direction as a signed factor {-1|1}
Return Values
elementXoffset, element Y offset

applyCellPositions

Description
Apply layout positions to all given cells' elements.
Definition
applyCellPositions(flowCells List, offsetStartX Layout, offsetStartY Layout, directionX Layout, directionY Layout, lateralFlowSizes List)
Arguments
flowCellsListof flows and their cell data
offsetStartXLayoutX starting offset
offsetStartYLayoutY starting offset
directionXLayoutX direction as a signed factor {-1|1}
directionYLayoutY direction as a signed factor {-1|1}
lateralFlowSizesListof lateral flow sizes (e.g. widths of columns in vertical flows)

focusLinkCells

Description
Link layout cells' elements for focus navigation.
Definition
focusLinkCells(flowCells List)
Arguments
flowCellsListof flows and their cell data

focusLinkChildElement

Description
Link a child element to others for focus navigation
Definition
focusLinkChildElement(element Current, previousElement Element, firstElement First, lastElement Last)
Arguments
elementCurrentelement
previousElementElementat previous position in layout flow, will be nil when the first element is being processed
firstElementFirstelement in layout
lastElementLastelement in layout

invalidateLayout

Description
Invalidate the layout, will reposition all elements and update focus navigation.
Definition
invalidateLayout(ignoreVisibility If)
Arguments
ignoreVisibilityIftrue, elements will be considered for layouting even if invisible

getFocusTarget

Description
Return the actual focus target when this box layout is being focused. This can be a previously focused element within
the layout (depends on rememberLastFocus attribute), a programmatically defined entry point based on the incoming
direction or simply the first layout element (when no other options apply).
Definition
getFocusTarget(incomingDirection Focus, moveDirection Actual)
Arguments
incomingDirectionFocusnavigation direction from where this layout is being entered
moveDirectionActualfocus navigation direction per input
Return Values
GuiElementwhichshould receive focus instead

ButtonElement

Description
Clickable button element.
-- Used layers: "image" for the background, "icon" for a button glyph.
-- All button UI callbacks do not require or provide any arguments.
--@category GUI
--@xmlConfig GuiElement#iconSize string [optional] Pixel size of button glyph in reference resolution. Format: "[width]px [height]px"

loadInputGlyphColors

Description
Load glyph overlay colors.
Definition
loadInputGlyphColors(profile If, xmlFile If, key XML)
Arguments
profileIfset, loads overlay properties from this button's GUI profile
xmlFileIfset, loads overlay properties from this button's XML configuration
keyXMLbase configuration node of this button

loadInputGlyph

Description
Load the actual input glyph symbols to display if an input action is defined on the button.
Definition
loadInputGlyph()

setKeyboardMode

Description
Set the keyboard mode flag.
Definition
setKeyboardMode()

setInputAction

Description
Set the input action for the display glyph by name.
Definition
setInputAction()

setImageUVs

Description
Set UV coordinates for the button background and/or icon.
Definition
setImageUVs()

getIsSelected

Description
Determine if this button is selected
Definition
getIsSelected()

getIsHighlighted

Description
Determine if this button is highlighted
Definition
getIsHighlighted()

getIconModifiedTextOffset

Description
Get modified text offset including changes from icon position and dimensions.
Definition
getIconModifiedTextOffset(float textOffsetX, float textOffsetY)
Arguments
floattextOffsetXScreen space text X offset
floattextOffsetYScreen space text Y offset
Return Values
floatModifiedX offset
floatModifiedY offset

getTextOffset

Description
Get text offset from element position including modifications from icon.
Definition
getTextOffset()

getText2Offset

Description
Get shadow text offset from element position including modifications from icon.
Definition
getText2Offset()

getIconSize

Description
Get the current icon size in screen space.
Definition
getIconSize()

updateSize

Description
Update size of element depending on content
Definition
updateSize()

ButtonOverlay

Description
Keyboard button display overlay.
-- Overlay type which displays a keyboard key button symbol.
--@category GUI

delete

Description
Delete this button overlay.
Definition
delete()

setColor

Description
Set this overlay's background color.
Definition
setColor(r Red, g Green, b Blue, a Alpha)
Arguments
rRedchannel [0, 1]
gGreenchannel [0, 1]
bBluechannel [0, 1]
aAlpha(transparency) channel [0, 1], 0 is fully transparent, 1 is opaque

renderButton

Description
Render this overlay with the given parameters.
Definition
renderButton(buttonText Text, posX Screen, posY Screen, height Button, alignment Text)
Arguments
buttonTextTextto display as the key value, e.g. "A", "Space", "Ctrl", etc.
posXScreenx position
posYScreeny position
heightButtondisplay height
alignmentTextalignment, one of the constants of RenderText.ALIGN_[...]

getButtonWidth

Description
Get the total display width of this button overlay for a given button text and height
Definition
getButtonWidth()

CareerScreen

Description
Career Screen.
Displays available save game slots.
-- @field savegameList Save game list

setIsWaitingForSaveGameInfo

Description
Set UI waiting state, which displays or hides a dialog that says to wait.
Definition
setIsWaitingForSaveGameInfo()

CharacterCreationScreen

Description
Character Selection Screen.

setCharacterIndex

Description
Set the index of the character. Is turned into a player and body pair.
Definition
setCharacterIndex()

updateCharacterWithSettings

Description
Update the character with the currently configured options.
Definition
updateCharacterWithSettings()

updateCharacter

Description
Update the character to match given options. Only reloads object if needed.
Definition
updateCharacter()

loadCharacterFinished

Description
Loading of the character object finished
Definition
loadCharacterFinished()

updateCharacterOptions

Description
Update the existing character with options that can be changed
Definition
updateCharacterOptions()

setHatHairNodeVisibility

Description
Set the visbility of the 'hat hair': special hair when wearing a hat
Definition
setHatHairNodeVisibility()

ChatDialog

Description
Multiplayer chat dialog
-- @field textElement User chat message input element

onMenuAxisUpDown

Description
Handle menu up/down input.
Scrolls through the chat history.
Definition
onMenuAxisUpDown()

ChatWindow

Description
HUD chat window.
-- Displays chat messages.
--@category GUI

new

Description
Create a new ChatWindow.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD atlas texture.
Return Values
tableChatWindowinstance

setChatMessages

Description
Set the chat message history reference for displaying.
The array is owned by the caller and must not be modified.
Definition
setChatMessages(table messages)
Arguments
tablemessagesMessages array as {i={msg=<message text>, sender=<sender user nickname>}}

scrollChatMessages

Description
Scroll chat messages by a given amount.
Definition
scrollChatMessages(int delta, int numMessages)
Arguments
intdeltaNumber of lines (positive or negative) to scroll
intnumMessagesNumber of currently stored chat messages

onMenuVisibilityChange

Description
Handle menu visibility state change.
Definition
onMenuVisibilityChange()

update

Description
Update element state.
Definition
update()

draw

Description
Draw the chat window.
Definition
draw()

setScale

Description
Set this element's UI scale.
Definition
setScale()

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()

createBackground

Description
Create the background overlay.
Definition
createBackground()

ColorPickerDialog

Description
Color Picker Dialog
-- Lets the player pick from a set of colors.
-- @field buttonTemplate Color button template which is cloned per color

setColors

Description
Set colors after opening.
Definition
setColors(table colors, table defaultColor)
Arguments
tablecolorsArray of colors {i={r, g, b, a}, or {i={name="name", color={r,g,b,a}}}
tabledefaultColorDefault color setting as {r, g, b, a}, must be contained in colors array

focusLinkColorButtons

Description
Apply custom grid-based focus linking
Definition
focusLinkColorButtons()

setInitialFocus

Description
Set the initial focus when entering this dialog.
Definition
setInitialFocus()

setCallback

Description
Set the dialog callback.
Definition
setCallback()

onClickColorButton

Description
Handle activation of a color button.
Definition
onClickColorButton()

ContextActionDisplay

Description
Player context action display element.
-- Displays information about the current interaction context. Includes action names and current input scheme button
glyphs.
--@category GUI

new

Description
Create a new instance of ContextActionDisplay.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas

setContext

Description
Sets the current action context.
This must be called each frame when a given context is active. The highest priority context is displayed or the one
which was set the latest if two or more contexts have the same priority.
Definition
setContext(string contextAction, string contextIconName, string targetText, int priority, string actionText)
Arguments
stringcontextActionInput action name of the context action
stringcontextIconNameName of the icon to display for the action context, use one of ContextActionDisplay.CONTEXT_ICON
stringtargetTextDisplay text which describes the context action target
intpriority[optional, default=0] Context priority, a higher number has higher priority.
stringactionText[optional] Context action description, if different from context action description

update

Description
Update the context action display state.
Definition
update()

resetContext

Description
Reset context state after drawing.
The context must be set anew on each frame.
Definition
resetContext()

draw

Description
Draw the context action display.
Definition
draw()

setScale

Description
Set the scale of this element.
Definition
setScale()

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()

getBackgroundPosition

Description
Get the position of the background element, which provides this element's absolute position.
Definition
getBackgroundPosition(scale Current, float width)
Arguments
scaleCurrentUI scale
floatwidthScaled background width in pixels
Return Values
floatXposition in screen space
floatYposition in screen space

createBackground

Description
Create an empty background overlay as a base frame for this element.
Definition
createBackground()

createComponents

Description
Create display components.
Definition
createComponents(string hudAtlasPath, table inputDisplayManager)
Arguments
stringhudAtlasPathPath to HUD atlas texture
tableinputDisplayManagerInputDisplayManager reference

createInputGlyph

Description
Create the input glyph element.
Definition
createInputGlyph()

createFrame

Description
Create the context display frame.
Definition
createFrame()

createActionIcons

Description
Create action context icons.
Only one of these will be visible at any time.
Definition
createActionIcons()

ControlsController

Description
Controls settings controller.
-- Handles the input controls model and control logic for settings screen controls pages.
--@category GUI

new

Description
Create a new ControlsController instance.
Definition
new()

setMessageCallback

Description
Set a callback for displaying status messages.
Callback signature: messageCallback(messageId, additionalText, addLine)
Definition
setMessageCallback(messageCallback A)
Arguments
messageCallbackAfunction which takes a message ID (see class constants), a optional list of additional strings and an optional addition flag (add instead of overwrite) to display a message.

setInputDoneCallback

Description
Set a callback to react on input capture completion.
Callback signature: inputDoneCallback(madeChange)
Definition
setInputDoneCallback(inputDoneCallback A)
Arguments
inputDoneCallbackAfunction to notify a collaborator that input gathering has finished and if there were any changes.

createDisplayAction

Description
Create a display action for displaying from bindings for a given axis direction.
Definition
createDisplayAction(deviceCategory Device, actionBinding Action, isAxisPositive If)
Arguments
deviceCategoryDevicecategory, only bindings of devices of this category are displayed
actionBindingActionbinding table reference: {action=Action, bindings={1=binding1, 2=binding2, ...}}
isAxisPositiveIftrue, the display action should show a positive action axis.
Return Values
{name="internalName",displayName="displayName",inputTexts={1=text1, 2=text2, ...}, inputBindings={1=binding1, 2=binding2, ...}, positiveInput=[true|false]}

getDeviceCategoryActionBindings

Description
Get available action bindings per device category, including current changes (even before saving).
Definition
getDeviceCategoryActionBindings(deviceCategory Device)
Arguments
deviceCategoryDevicecategory name
Return Values
ListofDisplayActionBinding instances

getMouseAxisDisplayText

Description
Get display text for a single mouse axis.
Definition
getMouseAxisDisplayText()

getGamepadAxisDisplayText

Description
Get display text for a single gamepad axis.
Definition
getGamepadAxisDisplayText()

getBindingInputDisplayText

Description
Get display text for input axis names of a binding.
Definition
getBindingInputDisplayText(Binding Binding)
Arguments
BindingBindingreference
Return Values
Display

saveChanges

Description
Save changed bindings to user configuration.
Definition
saveChanges()

discardChanges

Description
Discard any previously made binding changes.
Definition
discardChanges()

loadBindings

Description
Load action input bindings.
Definition
loadBindings()

onClickInput

Description
Handles clicking an input binding button for a given device category and action.
Definition
onClickInput(deviceCategory Input, bindingId ID, actionBinding Action)
Arguments
deviceCategoryInputdevice category
bindingIdIDof binding on the current device. E.g. 1 for main binding, 2 for secondary binding, etc.
actionBindingActionbinding table for the clicked action
Return Values
Trueifthe controller starts listening for input, false otherwise (also if it is already listening!)

beginWaitForInput

Description
Begin waiting for input.
Overrides the global input hooks keyEvent() and mouseEvent() as well as the global update() loop, depending on which
device is being scanned. Also see InputBinding:startInputCapture().
Definition
beginWaitForInput(deviceCategory Category, bindingIndex Binding, DisplayActionBinding DisplayActionBinding)
Arguments
deviceCategoryCategoryof device which is being scanned for input
bindingIndexBinding(primary, secondary, etc.) index which the scanned input will be assigned to.
DisplayActionBindingDisplayActionBindinginstance which describes the action binding to re-map.

onAbortInputGathering

Description
Input gathering abort event.
Definition
onAbortInputGathering()

onDeleteInputBinding

Description
Input gathering binding deletion event.
Definition
onDeleteInputBinding(DisplayActionBinding DisplayActionBinding, gatheringState {binding=DisplayActionBinding)
Arguments
DisplayActionBindingDisplayActionBindingreference of the binding to delete
gatheringState{binding=DisplayActionBindingreference of the binding to change, bindingIndex=Binding index}

onCaptureKeyboardInput

Description
Input gathering keyboard input event.
Definition
onCaptureKeyboardInput(keyName Key, isModifier True, inputValue 1, gatheringState {binding=DisplayActionBinding)
Arguments
keyNameKeyname as defined in Input
isModifierTrueif the key is used as a modifier for a combined input
inputValue1for pressed, 0 for inactive
gatheringState{binding=DisplayActionBindingreference of the binding to change, bindingIndex=Binding index, keyState={[keyName]=[lastValue]}}

onCaptureMouseInput

Description
Input gathering mouse input event.
Definition
onCaptureMouseInput(inputAxisName Mouse, isModifier True, inputValue Input, gatheringState {binding=DisplayActionBinding)
Arguments
inputAxisNameMouseaxis or button name as defined in Input
isModifierTrueif the input axis is used as a modifier for a combined input
inputValueInputvalue of the input axis
gatheringState{binding=DisplayActionBindingreference of the binding to change, bindingIndex=Binding index, mouseState={[axisName]=[lastValue]}}

onCaptureGamepadInput

Description
Input gathering gamepad / controller event.
Definition
onCaptureGamepadInput(deviceId Device, inputAxisName Axis, isModifier True, inputValue Input, gatheringState {binding=DisplayActionBinding)
Arguments
deviceIdDeviceID of the gamepad / controller which has received input
inputAxisNameAxisor button name as defined in Input
isModifierTrueif the input axis is used as a modifier for a combined input
inputValueInputvalue of the input axis
gatheringState{binding=DisplayActionBindingreference of the binding to change, bindingIndex=Binding index, gamepadState={[deviceId]={[axisName]=[lastValue]}}}

endWaitForInput

Description
Stop waiting for input.
Lifts the input override and notifies the screen listener.
Definition
endWaitForInput(madeChange If)
Arguments
madeChangeIftrue, the player has changed at least one binding.

lockInput

Description
Lock all UI input after capturing a new binding.
Definition
lockInput()

deleteBinding

Description
Delete a binding from its action binding table.
Definition
deleteBinding()
Return Values
boolTrueif an actual binding was deleted, false otherwise

assignKeyboardBinding

Description
Assign a (new) keyboard input binding.
Definition
assignKeyboardBinding(DisplayActionBinding DisplayActionBinding, bindingIndex Binding, keyames List)
Arguments
DisplayActionBindingDisplayActionBindinginstance which holds information about the binding to be added or updated
bindingIndexBindingindex to set, 1 primary, 2 secondary, etc.
keyamesListof input key names to bind
Return Values
Trueifa binding change was made, false otherwise

validateMouseCombo

Description
Check if the given axis names contain a supported mouse combo.
Definition
validateMouseCombo()

assignMouseBinding

Description
Assign a (new) mouse input binding.
Definition
assignMouseBinding(DisplayActionBinding DisplayActionBinding, inputAxisNames List, inputDirection Numeric)
Arguments
DisplayActionBindingDisplayActionBindinginstance which holds information about the binding to be added or updated
inputAxisNamesListof input axis names (axes and buttons) to bind
inputDirectionNumericvalue which defines the physical input axis direction component to bind. Values greater than or equal to 0 will be interpreted as positive, lesser than 0 as negative.
Return Values
Trueifa binding change was made, false otherwise

assignGamepadBinding

Description
Assign a (new) gamepad / controller input binding.
Definition
assignGamepadBinding(DisplayActionBinding DisplayActionBinding, bindingIndex Binding, deviceId Gamepad, inputAxisNames List, inputDirection Numeric)
Arguments
DisplayActionBindingDisplayActionBindinginstance which holds information about the binding to be added or updated
bindingIndexBindingindex to set, 1 primary, 2 secondary, etc.
deviceIdGamepad/ controller device ID of the input to bind
inputAxisNamesListof input axis names (axes and buttons) to bind
inputDirectionNumericvalue which defines the physical input axis direction component to bind. Values greater than or equal to 0 will be interpreted as positive, lesser than 0 as negative.
Return Values
Trueifa binding change was made, false otherwise

assignBinding

Description
Assign a (new) binding.
First tries to update an existing binding. If no binding with the given parameters exists to be updated, a new
binding is created instead, unless this would lead to an number of alternative bindings exceeding the maximum.
Definition
assignBinding(deviceId Binding, displayAction Cloned, bindingIndex Intended, inputAxisNames List, isPositiveAxis If, inputDirection Numeric, previousDeviceId [optional])
Arguments
deviceIdBindingdevice ID
displayActionClonedInputAction passed back from display and capture process
bindingIndexIntendedbinding index, 1 primary, 2 secondary, etc.
inputAxisNamesListof input axis names to bind
isPositiveAxisIftrue, the binding covers the positive part of the action's logical axis (always true for half-axis / button / key actions). False covers the negative part.
inputDirectionNumericvalue which defines the physical input axis direction component to bind. Values greater than or equal to 0 will be interpreted as positive, lesser than 0 as negative.
previousDeviceId[optional]Previous device ID of an existing binding. If not set, will use the given deviceId parameter instead.
Return Values
Trueifbinding has been assigned; reference to first colliding binding or nil

loadDefaultSettings

Description
Load default input binding settings from the game's profile template.
Handle with care, this will overwrite all the player's input binding settings.
Definition
loadDefaultSettings()

DataGrid

Description
Creating data grid

new

Description
@param table customMt custom metatable
Definition
new()
Return Values
tableinstanceinstance of object
Code
19function DataGrid:new(numRows, numColumns, customMt)
20 local self = {}
21 setmetatable(self, customMt or DataGrid_mt)
22
23 self.grid = {}
24 self.numRows = numRows
25 self.numColumns = numColumns
26 for i=1, numRows do
27 table.insert(self.grid, {})
28 end
29
30 return self
31end

delete

Description
Deletes data grid
Definition
delete()
Code
35function DataGrid:delete()
36 self.grid = nil
37end

getValue

Description
@param integer colIndex index of column
Definition
getValue()
Return Values
tablevaluevalue at the given position
Code
44function DataGrid:getValue(rowIndex, colIndex)
45 if rowIndex < 1 or rowIndex > self.numRows then
46 g_logManager:error("rowIndex out of bounds!")
47 printCallstack()
48 return nil
49 end
50 if colIndex < 1 or colIndex > self.numColumns then
51 g_logManager:error("colIndex out of bounds!")
52 printCallstack()
53 return nil
54 end
55
56 return self.grid[rowIndex][colIndex]
57end

setValue

Description
@param integer colIndex index of column
Definition
setValue(table value)
Arguments
tablevaluevalue at the given position
Code
64function DataGrid:setValue(rowIndex, colIndex, value)
65 if rowIndex < 1 or rowIndex > self.numRows then
66 g_logManager:error("rowIndex out of bounds!")
67 printCallstack()
68 return false
69 end
70 if colIndex < 1 or colIndex > self.numColumns then
71 g_logManager:error("colIndex out of bounds!")
72 printCallstack()
73 return false
74 end
75
76 self.grid[rowIndex][colIndex] = value
77 return true
78end

DepthOfFieldState

Description
Depth of field shader state.
-- This class wraps the depth of field shader parameter calls to allow convenient setting and resetting a specific
shader parameter state.
--@category GUI

new

Description
Create a new depth of field state.
This will record the currently set parameters which are restored when calling reset().
Definition
new(float nearCoCRadius, float nearBlurEnd, float farCoCRadius, float farBlurStart, float farBlurEnd)
Arguments
floatnearCoCRadiusNear circle of confusion radius (nearCoCRadius = 0 means no near blur (pinhole camera))
floatnearBlurEndDistance from the camera center where near blur ends
floatfarCoCRadiusFar circle of confusion radius (farCoCRadius = 0 means no far blur (pinhole camera))
floatfarBlurStartDistance from the camera center where far blur starts
floatfarBlurEndDistance from the camera center where far blur ends

recordState

Description
Record the current shader parameters for reset.
This is called on instantiation. If another state should be recorded, call this again afterwards.
Definition
recordState()

setParameters

Description
Set one or more parameters after instantiation.
If any of the parameters is omitted, the currently stored value is used.
Definition
setParameters(float nearCoCRadius, float nearBlurEnd, float farCoCRadius, float farBlurStart, float farBlurEnd)
Arguments
floatnearCoCRadiusNear circle of confusion radius (nearCoCRadius = 0 means no near blur (pinhole camera))
floatnearBlurEndDistance from the camera center where near blur ends
floatfarCoCRadiusFar circle of confusion radius (farCoCRadius = 0 means no far blur (pinhole camera))
floatfarBlurStartDistance from the camera center where far blur starts
floatfarBlurEndDistance from the camera center where far blur ends

apply

Description
Apply shader parameters which were provided on instantiation.
Definition
apply()

reset

Description
Reset the shader parameters to the state they were in when this object had been created.
Definition
reset()

createFullscreenBlur

Description
Create a depth of field state for a full screen blur effect.
Definition
createFullscreenBlur()

DirectSellDialog

Description
Vehicle selling or customization dialog
-- Opened when activating vehicle selling points.
-- @field headerText Dialog header text element

new

Description
Create a new DirectSellDialog instance.
Definition
new(table target, table custom_mt, table shopConfigScreen, table messageCenter)
Arguments
tabletargetDialogElement controller reference
tablecustom_mt[optional] Sub-class meta table for inheritance
tableshopConfigScreenShopConfigScreen reference for vehicle selling / customization
tablemessageCenterMessageCenter reference for local network UI event handling
Return Values
tableDirectSellDialoginstance

onClickOk

Description
Handle "sell" button event.
Definition
onClickOk()

onClickActivate

Description
Handle "customize" button event.
Definition
onClickActivate()

DisplayActionBinding

Description
Holds information about an action binding for display purposes.
-- This class is used to transfer input binding information between ControlsController and UI components.
--@category Input

new

Description
Creates a new DisplayActionBinding.
Definition
new(action InputAction, isPositive If, displayName Display, Binding Bindings)
Arguments
actionInputActionof this binding
isPositiveIftrue, this display action binding shows the binding for the positive input axis (always true for half-axis actions)
displayNameDisplayname of this action binding for the given input axis direction.
BindingBindingsassociated with the input axis component for the given action

setBindingDisplay

Description
Set display information for binding.
Definition
setBindingDisplay(Binding Binding, text Binding, column Display)
Arguments
BindingBindingreference contained in this instance
textBindingdisplay text (button/key/axes names)
columnDisplaycolumn index (1 for primary, 2 for secondary, etc)
Return Values
integernumPixelsnumber of pixels
integertotalNumPixelstotal number of pixels

EditFarmDialog

Description
Farm edit and create dialog.
-- Lets a player edit a farm's properties or create a new farm.
-- @field buttonTemplate Color button template which is cloned per color

new

Description
Create a new instance of EditFarmDialog.
Definition
new(table target, table custom_mt, table l10n, table farmManager)
Arguments
tabletargetOptional input target override
tablecustom_mtSub-class metatable
tablel10nI18N reference for localization
tablefarmManagerFarmManager reference for farm data access

setExistingFarm

Description
Set existing farm ID whose properties are to be modified.
If no farm ID is given, a new farm will be created.
Definition
setExistingFarm()

storeAvailableColors

Description
Find available farm colors and store them in fields.
Definition
storeAvailableColors()

onClickColorButton

Description
Handle activation of a color button.
Shadows parent method which exits the dialog right away.
Definition
onClickColorButton()

onClickActivate

Description
Handle dialog confirmation click / activation.
Depending on the mode, this will create a new farm or update an existing one.
Definition
onClickActivate()

Farm

Description
Permission types.

merge

Description
Merge another farm into this farm. Used for creating an SP game from an MP game. (this is mutating)
Definition
merge(table other)
Arguments
tableotherAnother Farm

getFarmhouse

Description
Get the farmhouse associated with the farm.
Definition
getFarmhouse()
Return Values
tablefarmhouseor nil

getSpawnPoint

Description
Get the spawnpoint associated with the farm(house).
Definition
getSpawnPoint()
Return Values
integerspawnpointnode or the career spawnpoint node.

getSleepCamera

Description
Get the sleep camera.
Definition
getSleepCamera()
Return Values
integerCameraor 0 if no farmhouse.

getActiveUsers

Description
Get a list of active users. Useful for using their connection ID
Definition
getActiveUsers()

isUserFarmManager

Description
Determine if a user is a manager of this farm.
Definition
isUserFarmManager(userId User)
Arguments
userIdUserID
Return Values
boolTrueif the user is a manager of this farm, false otherwise

getUserPermissions

Description
Get the farm permissions of a user.
Definition
getUserPermissions(userId User)
Arguments
userIdUserID
Return Values
tablePermissionhash table {permission=<hasPermission>}

setUserPermission

Description
Set a user's permission in this farm.
Definition
setUserPermission(userId User, string permission, bool hasPermission)
Arguments
userIdUserID
stringpermissionPermission key from Farm.PERMISSION
boolhasPermissionTrue if the permission is to be granted, false to be denied

promoteUser

Description
Promote a user to farm manager.
Definition
promoteUser()

demoteUser

Description
Demote a user from farm manager.
Definition
demoteUser()

setIsContractingFor

Description
Update contracting status
Definition
setIsContractingFor(noSendEvent boolean)
Arguments
noSendEventbooleanSend no event, forces setting of actual value without server feedback

changeBalance

Description
Add or remove money from the farm
Definition
changeBalance(number amount)
Arguments
numberamountAmount to add (positive) or remove (negative)

getBalance

Description
Get the current account balance of the farm.
Definition
getBalance()
Return Values
floatAccountbalance

getLoan

Description
Get the current loan of the farm.
Definition
getLoan()
Return Values
float

getHandTools

Description
Get a list of filenames for accessible handtools
Definition
getHandTools()

addUser

Description
Add a new user to the farm. This adds it to the players and active players list.
And also gives default permissions.
Definition
addUser()

removeUser

Description
Remove a user from the farm.
Definition
removeUser()

onUserJoinGame

Description
Called when a user joins the game. Active users is updated, and for spectator.
a new user might be added. Server only.
Definition
onUserJoinGame()

onUserQuitGame

Description
Called when a user quits the game. The active user list is updated. Server only.
Definition
onUserQuitGame()

FarmManager

Description
Multiplayer

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
27function FarmManager:new(customMt)
28 local self = AbstractManager:new(customMt or FarmManager_mt)
29
30 return self
31end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
43function FarmManager:loadMapData(xmlFile)
44 FarmManager:superClass().loadMapData(self)
45
46 if g_currentMission:getIsServer() then
47 g_currentMission:addUpdateable(self)
48
49 -- Create spectator farm
50 local spectatorFarm = Farm:new(true, g_client ~= nil, nil, true)
51 spectatorFarm.farmId = FarmManager.SPECTATOR_FARM_ID
52 spectatorFarm.isSpectator = true
53
54 spectatorFarm:register()
55
56 table.insert(self.farms, spectatorFarm)
57 self.farmIdToFarm[spectatorFarm.farmId] = spectatorFarm
58 end
59
60 addConsoleCommand("gsSetFarm", "Set farm for current player or vehicle", "consoleCommandSetFarm", self)
61
62 if g_addTestCommands then
63 addConsoleCommand("debugCreateFarm", "Create a new farm", "consoleCommandCreateFarm", self)
64 end
65end

unloadMapData

Description
Unload data on mission delete
Definition
unloadMapData()
Code
69function FarmManager:unloadMapData()
70 g_currentMission:removeUpdateable(self)
71
72 removeConsoleCommand("gsSetFarm")
73 if g_addTestCommands then
74 removeConsoleCommand("debugCreateFarm")
75 end
76
77 FarmManager:superClass().unloadMapData(self)
78end

saveToXMLFile

Description
Write field mission data to savegame file
Definition
saveToXMLFile(string xmlFilename)
Arguments
stringxmlFilenamefile path
Return Values
booleantrueif loading was successful else false
Code
84function FarmManager:saveToXMLFile(xmlFilename)
85 local xmlFile = createXMLFile("farmsXML", xmlFilename, "farms");
86
87 local index = 0
88 for i, farm in ipairs(self.farms) do
89 if farm.farmId ~= 0 then
90 local key = string.format("farms.farm(%d)", index)
91
92 farm:saveToXMLFile(xmlFile, key)
93 index = index + 1
94 end
95 end
96
97 saveXMLFile(xmlFile)
98 delete(xmlFile)
99end

loadFromXMLFile

Description
Load fieldjob data from xml savegame file
Definition
loadFromXMLFile(string filename)
Arguments
stringfilenamexml filename
Code
104function FarmManager:loadFromXMLFile(xmlFilename)
105 if xmlFilename == nil then
106 self:loadDefaults()
107 return false
108 end
109
110 local xmlFile = loadXMLFile("TempXML", xmlFilename)
111 if not xmlFile then
112 return false
113 end
114
115 local i = 0
116 while true do
117 local key = string.format("farms.farm(%d)", i)
118 if not hasXMLProperty(xmlFile, key) then
119 break
120 end
121
122 local farm = Farm:new(true, g_client ~= nil)
123
124 if not farm:loadFromXMLFile(xmlFile, key) then
125 farm:delete()
126 else
127 farm:register()
128
129 table.insert(self.farms, farm)
130 self.farmIdToFarm[farm.farmId] = farm
131 end
132
133 i = i + 1
134 end
135
136 self:mergeFarmsForSingleplayer()
137
138 -- Emulate an MP player join for local MP or SP game
139 if g_currentMission:getIsClient() then
140 local uniqueUserId = g_currentMission.missionDynamicInfo.isMultiplayer and getUniqueUserId() or FarmManager.SINGLEPLAYER_UUID
141 self:playerJoinedGame(uniqueUserId, g_currentMission:getServerUserId())
142 end
143
144 g_fieldManager:updateFieldOwnership()
145
146 delete(xmlFile)
147
148 return true
149end

mergeFarmlandsForSingleplayer

Description
Second step of merging: transfer all lands to the singleplayer farm
Definition
mergeFarmlandsForSingleplayer()

mergeObjectsForSingleplayer

Description
Third step of merging: move vehicles and bales to singleplayer farm
Definition
mergeObjectsForSingleplayer()

delete

Description
Deletes field mission manager
Definition
delete()
Code
236function FarmManager:delete()
237end

update

Description
Updates field mission ownage data from xml savegame file
Definition
update(string filename)
Arguments
stringfilenamexml filename
Code
242function FarmManager:update(dt)
243 if g_currentMission:getIsClient() then
244 if self.spFarmWasMerged and not self.mergedMessageShown then
245 g_gui:showInfoDialog({visible=true, text=g_i18n:getText("ui_farmedMergedSP"), dialogType=DialogElement.TYPE_INFO, isCloseAllowed=true})
246 self.mergedMessageShown = true
247 end
248 end
249end

getFarmForUniqueUserId

Description
Get farm for given userId. To be used when player is not in the game
Definition
getFarmForUniqueUserId()

getFarmByUserId

Description
Get farm for given userId. To be used when player is in the game.
Definition
getFarmByUserId()

updateFarms

Description
On client, update the list of farms and set farm for given farmId
Definition
updateFarms()

getFarms

Description
Get the array of known farms.
Callers should not modify this array.
Definition
getFarms()

transferMoney

Description
Transfer an amount of money from the current user's farm to a destination farm.
Triggers a network event which checks farm balances and applies the change. Successful execution requires the current
user to have permission to transfer money as well as their current farm to have a sufficient balance.
Definition
transferMoney()

removeUserFromFarm

Description
Remove player from their farm. Only works if the caller has permission (master user, farm manager)
Definition
removeUserFromFarm()

removeFarm

Description
Farm has been destroyed. Remove from lists
Definition
removeFarm()

FieldInfoDisplay

Description
HUD field information display element.
-- Displays dynamic information about the field which the player is currently standing in (or close by).
--@category GUI

new

Description
Create a new instance of FieldInfoDisplay.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas

setupRows

Description
Set up rows data structures.
Definition
setupRows()

setPlayer

Description
Set the local player reference.
Definition
setPlayer()

setFruitType

Description
Set the current fruit type to display.
Definition
setFruitType(int fruitTypeIndex, int fruitGrowthState)
Arguments
intfruitTypeIndexIndex of the field fruit type or a number <= 0 to clear the fruit type.
intfruitGrowthStateCurrent growth state of the given fruit type

setOwnerFarmId

Description
Set the field owner
Definition
setOwnerFarmId(int ownerFarmId)
Arguments
intownerFarmIdCurrent owner farm id

setFertilization

Description
Set the fertilization factor info to display.
Definition
setFertilization(float fertilizationFactor)
Arguments
floatfertilizationFactorCurrent fertilization factor to display, this will be converted to a percentage. Values < 0 clear this info.

setWeed

Description
Set the weed factor info to display.
Definition
setWeed(float fertilizationFactor)
Arguments
floatfertilizationFactorCurrent weed factor to display, this will be converted to a percentage. Values < 0 clear this info.

setPlowingRequired

Description
Set the plowing required display.
Definition
setPlowingRequired(bool isRequired)
Arguments
boolisRequiredIf true, will display that the current field needs to be plowed. Otherwise, the info is hidden.

setLimeRequired

Description
Set the lime required display.
Definition
setLimeRequired(bool isRequired)
Arguments
boolisRequiredIf true, will display that the current field needs lime. Otherwise, the info is hidden.

addCustomText

Description
Add a custom text row.
The custom text will be added in order of calls to this function after the default information.
Definition
addCustomText(string leftText, string rightText, table leftColor)
Arguments
stringleftTextText to be displayed on the left side in bold print
stringrightText[optional] Text to be displayed on the right side in regular print
tableleftColor[optional, default=<white>] Color of left text as an array {r, g, b, a}
Return Values
intDisplayrow index of the newly added custom text or 0 if it could not be added

clearCustomText

Description
Clear a custom text row previously added by FieldInfoDisplay:addCustomText().
Definition
clearCustomText(int rowIndex)
Arguments
introwIndex[optional] Custom text row index as returned by FieldInfoDisplay:addCustomText(). If no value is provided, all custom text is cleared.

clearInfoRow

Description
Clear a single info row's data.
Definition
clearInfoRow()

clearFieldData

Description
Clear all previously set field data.
This does not clear custom text rows, which need to be cleared specifically using clearCustomText().
Definition
clearFieldData()

onFieldDataUpdateFinished

Description
Called when FSDensityMapUtil.getFieldStatusAsync() in update() has finished.
Definition
onFieldDataUpdateFinished(table data)
Arguments
tabledataField information data as provided by processing in FSDensityMapUtil.getFieldStatusAsync()

updateSize

Description
Update the info display size depending on used rows.
Definition
updateSize()

draw

Description
Draw the display.
Definition
draw()

drawText

Description
Draw text parts of this display element.
Definition
drawText()

getBackgroundPosition

Description
Get the scaled background position.
Definition
getBackgroundPosition()

setScale

Description
Set this element's UI scale factor.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor

storeScaledValues

Description
Store scaled position and size values.
Definition
storeScaledValues()

createBackground

Description
Create the background overlay.
Definition
createBackground()

createComponents

Description
Create required display components.
Definition
createComponents()

createFrame

Description
Create the background frame element.
Definition
createFrame()

createRowListContainer

Description
Create row list container.
Definition
createRowListContainer()

createSeparators

Description
Create row separators.
Definition
createSeparators()

FillLevelsDisplay

Description
Vehicle HUD fill levels display element.
-- Displays fill level bars for the current vehicle configuration
--@category GUI

new

Description
Creates a new FillLevelsDisplay instance.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas.

setVehicle

Description
Set the currently controlled vehicle which provides display data.
Definition
setVehicle(table vehicle)
Arguments
tablevehicleCurrently controlled vehicle

updateFillLevelBuffers

Description
Update fill levels data.
Definition
updateFillLevelBuffers()

updateFillLevelFrames

Description
Update fill level frames display state.
Definition
updateFillLevelFrames()

update

Description
Update the fill levels state.
Definition
update()

draw

Description
Draw this element.
Definition
draw()

setScale

Description
Set this element's scale.
Definition
setScale()

getBackgroundPosition

Description
Get the position of the background element, which provides this element's absolute position.
Definition
getBackgroundPosition(scale Current, float width)
Arguments
scaleCurrentUI scale
floatwidthScaled background width in pixels
Return Values
floatXposition in screen space
floatYposition in screen space

storeScaledValues

Description
Calculate and store scaling values based on the current UI scale.
Definition
storeScaledValues()

createBackground

Description
Create an empty background overlay as a base frame for this element.
Definition
createBackground()

refreshFillTypes

Description
Refresh fill type data and elements.
Definition
refreshFillTypes(table fillTypeManager)
Arguments
tablefillTypeManagerFillTypeManager reference

createFillTypeFrames

Description
Create fill type frames for all known fill types.
Definition
createFillTypeFrames()

createFillTypeFrame

Description
Create a fill type frame for the display of a fill type level state.
Definition
createFillTypeFrame()

createFillTypeIcon

Description
Create an icon for a fill type.
Definition
createFillTypeIcon()

createFillTypeBar

Description
Create a fill type bar used to display a fill level.
The newly created bar is added to the given parent frame and an internal collection indexable by fill type index.
Definition
createFillTypeBar(string hudAtlasPath, table frame, float baseX, float baseY, table fillType)
Arguments
stringhudAtlasPathPath to HUD texture atlas
tableframeParent frame HUD element
floatbaseXOrigin X position in screen space
floatbaseYOrigin Y position in screen space
tablefillTypeFill type whose fill level is represented by the created bar

FocusManager

Description
The FocusManager controls which element in the menu system is currently focused
and allows menu control with only keyboard or gamepad.
For each participating gui element the focus state and the next focused gui element
in each direction is stored. This data is set up directly in the xml file of the gui screen
and loaded through the loadElementFromXML() function or manually loaded within code by using
the loadElementFromCustomValues() method.
Focus handling is independent for every screen in the GUI. To swap screens the setGui() method
has to be used.
The focus system is then controlled with 5 actions: MENU_UP, MENU_DOWN, MENU_RIGHT and MENU_LEFT to
change the currently focused element in the specified direction and MENU_ACCEPT to activate
the currently focused element.
-- When using dynamically changing objects which cannot be set directly in the XML file of the screen
the method createLinkageSystemForElements() can be used to set up direction links between the
passed elements automatically.
--@category GUI

setGui

Description
Set the active GUI for focus input.
Definition
setGui(Gui Screen)
Arguments
GuiScreenroot GuiElement

getElementById

Description
Get a focusable GuiElement in the current view by its ID.
Definition
getElementById()

getFocusedElement

Description
Get the currently focused GuiElement
Definition
getFocusedElement()

serveAutoFocusId

Description
Get a new automatic focus ID.
It's based on a simple integer increment and will be unique unless billions of elements require an ID.
Definition
serveAutoFocusId()

loadElementFromXML

Description
Load GuiElement focus data from its XML definition.
This is called at the end of GuiElement:loadFromXML().
Definition
loadElementFromXML()

loadElementFromCustomValues

Description
Add an element to the focus system with custom values.
The caller should ensure that explicitly set focus IDs are unique. If a duplicate ID is encountered, only the first
element with that focus ID is considered for focusing. The method returns a boolean value to indicate any problems
with data assignment. Callers can evaluate the value to check if the given parameters were valid. If in doubt or
when no elaborate focus navigation is needed, rely on automatic focus ID generation by omitting the ID parameter
(or set it to nil).
Definition
loadElementFromCustomValues(element Element, focusId Focus, focusChangeData Custom, focusActive If, isAlwaysFocusedOnOpen If)
Arguments
elementElementto add to focus system
focusIdFocusID for element
focusChangeDataCustomfocus navigation data for the element (map of direction to focus ID)
focusActiveIftrue, the element should be focused right now
isAlwaysFocusedOnOpenIftrue, the element is supposed to be focused when its parent view is opened.
Return Values
Trueifthe element and all of its children could be set up with the given values, false otherwise.

removeElement

Description
Remove a GuiElement from the current focus context.
Definition
removeElement()

linkElements

Description
Links an element's focus navigation to another element for a given direction.
The link is unidirectional from source to target. If bi-directional links are desired, call this method again with
swapped arguments.
Definition
linkElements(sourceElement Source, direction Navigation, targetElement Target)
Arguments
sourceElementSourceelement which receives the focus link.
directionNavigationdirection for the link, is not required to be the actual visual direction.
targetElementTargetelement

inputEvent

Description
Handles input and changes focus if required and possible.
Definition
inputEvent(action Name, value Input, eventUsed Usage)
Arguments
actionNameof navigation action which triggered the event, see InputAction
valueInputvalue [-1, 1]
eventUsedUsageflag, no action is taken if this is true
Return Values
Trueifthe input event has been consumed, false otherwise

getDirectionForAxisValue

Description
Get a direction value for a given menu input action and value
Definition
getDirectionForAxisValue()

isFocusInputLocked

Description
Checks if the focus manager has an input lock on input.
Definition
isFocusInputLocked(inputAxis InputAction, value Axis, True if)
Arguments
inputAxisInputActionaxis or action code
valueAxisvalue [-1, 1] or nil if not a directional axis
Trueiflocked, false otherwise

lockFocusInput

Description
Locks a given input axis action's input for a time. Until the delay has passed, the focus manager will not react to
that input.
Definition
lockFocusInput(inputAxis InputAction, delay Delay, value Axis)
Arguments
inputAxisInputActionaxis or action code
delayDelayin ms
valueAxisvalue [-1, 1], only relevant to identify directional axes

releaseMovementFocusInput

Description
Release a focus movement input lock on an action.
Called by the UI input handling code. Avoid calling this for anything else.
Definition
releaseMovementFocusInput(action Focus)
Arguments
actionFocusmovement input action name

resetFocusInputLocks

Description
Reset all locks of focus input.
Definition
resetFocusInputLocks()

getClosestPointOnBoundingBox

Description
Given a point and bounding box, get the closest other point on the bounding box circumference. If the point lies
within the bounding box, it is returned unchanged.
Definition
getClosestPointOnBoundingBox(x Point, y Point, boxMinX Bounding, boxMinY Bounding, boxMaxX Bounding, boxMaxY Bounding)
Arguments
xPointX
yPointY
boxMinXBoundingbox minimum point X
boxMinYBoundingbox minimum point Y
boxMaxXBoundingbox maximum point X
boxMaxYBoundingbox maximum point Y
Return Values
Closestpointx, y

getShortestBoundingBoxVector

Description
Calculate the shortest connecting line segment between two bounding boxes. Overlapping boxes will result in flipped
directions, so take care.
Definition
getShortestBoundingBoxVector()

checkElementDistance

Description
Checks the distance between two GuiElements with the aim of incrementally finding the closest other element in a
direction within a screen view.
Definition
checkElementDistance(curElement Current, other Other, dirX Scan, dirY Scan, curElementOffsetY Position, closestOther Previously, closestDistanceSq Squared)
Arguments
curElementCurrentchecking GuiElement
otherOtherGuiElement to compare
dirXScandirection vector x component, normalized to unit length
dirYScandirection vector y component, normalized to unit length
curElementOffsetYPositiony offset of current element's bounding volume, used when checking for wrap-around
closestOtherPreviouslyclosest other GuiElement
closestDistanceSqSquareddistance from the current checking element to the previously closest other GuiElement

getNextFocusElement

Description
Find the next other element to the one provided in a given navigation direction
Definition
getNextFocusElement(element GUI, direction Direction)
Arguments
elementGUIelement which needs a focus link
directionDirectionconstant [TOP | BOTTOM | LEFT | RIGHT]
Return Values
NextGUIelement in given direction which can be linked, actual scanning direction used (may change in wrap around scenarios)

getNestedFocusTarget

Description
Get an element's focus target at the deepest nesting depth, e.g. when multiple nested layouts point down to their
child elements until only a single element is left which points to itself.
Definition
getNestedFocusTarget(element GuiElement, direction Focus)
Arguments
elementGuiElementwhose focus target needs to be retrieved
directionFocusnavigation direction
Return Values
Focus

updateFocus

Description
Update the current focus target.
Definition
updateFocus(element GuiElement, isFocusMoving Only, direction Focus, updateOnly If)
Arguments
elementGuiElementwhich should be the new focus target
isFocusMovingOnlymove focus if this is true
directionFocusnavigation movement direction, one of FocusManager.[TOP | BOTTOM | LEFT | RIGHT]
updateOnlyIftrue, only updates the lock state of focus movement for the given parameters

setHighlight

Description
Activate a highlight on an element. Highlighted elements are only visually marked and do not receive focus activation.
Only one element will be highlighted at any time, usually corresponding to the current mouse over target.
Definition
setHighlight(element Element)
Arguments
elementElementto be highlighted.

unsetHighlight

Description
Remove highlight status from an element.
Definition
unsetHighlight(element Highlighted)
Arguments
elementHighlightedelement to revert

setFocus

Description
Set focus on a GuiElement or its focus target.
Applies overlay state and triggers onFocusEnter() on the target.
Definition
setFocus(element Element, direction Focus, ... Variable)
Arguments
elementElementwhose focus target (usually itself) receives focus.
directionFocusnavigation direction
...Variablearguments to pass on to the onFocusEnter callback of the target element
Return Values
Trueiffocus has changed, false otherwise

unsetFocus

Description
Removes focus from an element.
Applies overlay state and triggers onFocusLeave() on the target.
Definition
unsetFocus(element Element, ... Variable)
Arguments
elementElementwhich should lose focus
...Variablearguments to pass on to the onFocusLeave callback of the target element

setElementFocusOverlayState

Description
Set an elements focus overlay state for displaying.
Definition
setElementFocusOverlayState(element Target, isFocus If, handlePreviousState [optional])
Arguments
elementTargetelement
isFocusIftrue, the element's state will be set to focused. Otherwise, it's state will be either restored or set to normal.
handlePreviousState[optional]If true or undefined, makes the element store its previous overlay state before modification or restore it when isFocused is false.

requireLock

Description
Globally lock focus input.
Definition
requireLock()

releaseLock

Description
Release the global focus input lock.
Definition
releaseLock()

isLocked

Description
Check if focus input is locked.
Definition
isLocked()

isDirectionLocked

Description
Determine if focus navigation in a given direction is currently locked.
Definition
isDirectionLocked(direction Navigation)
Arguments
directionNavigationdirection as defined in constants
Return Values
Trueifnavigation in given direction is locked

hasFocus

Description
Determine if a GuiElement is currently focused.
Definition
hasFocus()

getFocusOverrideFunction

Description
Get a closure override function for elements' getFocusOverride() methods.
Definition
getFocusOverrideFunction(forDirections List, substitute Element, useSubstituteForFocus (Optional))
Arguments
forDirectionsListof directions to override
substituteElementto substitute as focus target in overridden direction
useSubstituteForFocus(Optional)If true, the substitute parameter will be used as the origin for finding the
next focus target in the overridden direction.

FrameElement

Description
Base display frame element. All GUI views (partial and full screen) inherit from this.
-- This element provides the functionality to register control IDs, which are then exposed as fields of the concrete
descendant class (e.g. MainScreen or PasswordDialog). The control IDs must be assigned verbatim to any control
in the corresponding configuration XML file. If a registered ID is not used, the field will not be assigned and
access will fail. Available field IDs are documented as field properties per class. When creating a new view, take
care to include the call to registerControls() in the constructor to declare and expose control elements as fields.
--@category GUI

clone

Description
Override of GuiElement:clone().
Also exposes registered control element fields.
Definition
clone()

copyAttributes

Description
Override of GuiElement:copyAttributes().
Also resets registered control IDs so they can be exposed as fields again.
Definition
copyAttributes()

getRootElement

Description
Get the frame's root GuiElement instance.
This is the first and only direct child of a FrameElement, as defined by the GUI instantiation logic. This method
will always return a GuiElement instance, even if a new one must be created first.
Definition
getRootElement()

registerControls

Description
Register a collection of control IDs for direct access in GUI views.
Definition
registerControls(controlIDs Table)
Arguments
controlIDsTablewhich holds control IDs as values, as they are required to be present in the view configuration.

exposeControlsAsFields

Description
Adds registered controls as fields to this FrameElement instance.
Called by the GUI system after loading.
The new fields will have the same name as the registered ID, so make sure there are no collision to avoid overrides
and that IDs are also valid as identifiers in Lua. If a control has been registered but no corresponding element is
available (e.g. when sub-classing and omitting some elements), the field will remain undefined. It's up to callers
to ensure that field configuration and usage in views matches.
Definition
exposeControlsAsFields(viewName View)
Arguments
viewNameViewname of this frame element

disableInputForDuration

Description
Set input disabling to a given duration.
Definition
disableInputForDuration(float duration)
Arguments
floatdurationInput disabling duration in milliseconds

isInputDisabled

Description
Check if input is currently disabled.
Definition
isInputDisabled()

setChangeScreenCallback

Description
Set a callback for requesting a view change from within a frame or screen view.
Definition
setChangeScreenCallback(func callback)
Arguments
funccallbackFunction reference, signature: function(sourceFrameElement, targetScreenClass, returnScreenClass)

setInputContextCallback

Description
Set a callback function for requesting a custom menu input context for this frame.
Definition
setInputContextCallback(func callback)
Arguments
funccallbackFunction reference, signature: function(isContextActive)

setPlaySampleCallback

Description
Set a callback function for requesting to play a sound sample.
Definition
setPlaySampleCallback(func callback)
Arguments
funccallbackFunction reference, signature: function(sampleName)

changeScreen

Description
Request a view change via the callback defined by setChangeScreenCallback().
Definition
changeScreen(table targetScreenClass)
Arguments
tabletargetScreenClassClass table of requested view (ScreenElement descendant, must be full view)

toggleCustomInputContext

Description
Request toggling of a custom menu input context for this frame via the callback defined by setInputContextCallback().
Definition
toggleCustomInputContext(bool isContextActive, string contextName)
Arguments
boolisContextActiveIf true, will activate a custom menu input context. Otherwise, will clear a previously
activated context.
stringcontextNameName of the custom input context. Use a unique identifier value.

playSample

Description
Request playing a sound sample identified by name.
Definition
playSample(string sampleName)
Arguments
stringsampleNameSample name, use one of GuiSoundPlayer.SOUND_SAMPLES

FSBaseMission

Description
(Un)loading stations

initialize

Description
Initialize mission after instantiation.
Create complex members and call dependency methods in here so that mission instantiation cannot fail.
Definition
initialize()

setHarvestScaleRatio

Description
Sets harvest ratios for fertilizer, plow, lime and weed factor
Definition
setHarvestScaleRatio(float sprayRatio, float plowRatio, float limeRatio, float weedRatio)
Arguments
floatsprayRatiofertilizer ratio
floatplowRatioplow ratio
floatlimeRatiolime ratio
floatweedRatioweed ratio

getHarvestScaleMultiplier

Description
Get harvest multiplier based on fertilizer, plow, lime and weed factor, 1 = best
Definition
getHarvestScaleMultiplier(integer fruitTypeIndex, float sprayFactor, float plowFactor, float limeFactor, float weedFactor)
Arguments
integerfruitTypeIndexfruit type index
floatsprayFactorfertilizer factor
floatplowFactorplow factor
floatlimeFactorlime factor
floatweedFactorweed factor
Return Values
floatmultiplierharvest multiplier

updateMenuAccessibleVehicles

Description
Check which vehicles are accessible and notify the menu.
Definition
updateMenuAccessibleVehicles()

addOwnedItem

Description
Add an item to the owned items collection.
Also notifies the shop.
Definition
addOwnedItem()

removeOwnedItem

Description
Remove an item from the owned items collection.
Also notifies the shop.
Definition
removeOwnedItem()

addLeasedItem

Description
Add an item to the leased items collection.
Also notifies the shop.
Definition
addLeasedItem()

removeLeasedItem

Description
Remove an item from the leased items collection.
Also notifies the shop.
Definition
removeLeasedItem()

updatePauseInputContext

Description
Set or revert the pause input context based on current state.
Definition
updatePauseInputContext()

updateSaving

Description
Update saving process.
Notifies the UI to display dialogs.
Definition
updateSaving()

onYesNoSavegameSelectDevice

Description
Savegame device selection confirmation dialog response callback.
Definition
onYesNoSavegameSelectDevice()

onSaveGameUpdateComplete

Description
Savegame overwrite completion callback.
Definition
onSaveGameUpdateComplete(int errorCode)
Arguments
interrorCodeSaving process status code, one of Savegame.ERROR_...

onYesNoSavegameOverwrite

Description
Savegame overwrite confirmation dialog response callback.
Definition
onYesNoSavegameOverwrite()

showAttachContext

Description
Display vehicle attachment context information for the current frame.
Definition
showAttachContext()

showTipContext

Description
Display vehicle tipping context information for the current frame.
Definition
showTipContext()

showFuelContext

Description
Display vehicle refueling context information for the current frame.
Definition
showFuelContext()

showFillDogBowlContext

Description
Display dog companion food bowl fill context information for the current frame.
Definition
showFillDogBowlContext()

getMoney

Description
Get money for farm or current player farm
Definition
getMoney(farmId integer)
Arguments
farmIdintegerif nil, then current farm (client only)

getHasPlayerPermission

Description
Get whether the current player has given permission.
Definition
getHasPlayerPermission(string permission, table connection, integer farmId, boolean checkClient)
Arguments
stringpermissionPermission to check
tableconnection[optional] Client connection to check permission for
integerfarmId[optional] Limit permission to given farm (otherwise any farm)
booleancheckClient[optional] if true it will only check the client permission

getIngameMap

Description
Get the in-game map rendering component.
Should only be used for UI.
Definition
getIngameMap()

startSaveCurrentGame

Description
Start saving the game.
Definition
startSaveCurrentGame(bool isDediSaving)
Arguments
boolisDediSavingIf true, this is a saving call on a dedicated server

saveSavegame

Description
Actually save the game locally.
Definition
saveSavegame()

getDoghouse

Description
Returns a doghouse
Definition
getDoghouse(integer farmId)
Arguments
integerfarmId
Return Values
tableinstanceof the doghouse
Code
3144function FSBaseMission:getDoghouse(farmId)
3145 for _, doghouse in pairs(self.doghouses) do
3146 if doghouse:getOwnerFarmId() == farmId then
3147 return doghouse
3148 end
3149 end
3150 return nil
3151end

registerHusbandry

Description
Register a husbandry in the mission.
Definition
registerHusbandry()

unregisterHusbandry

Description
Unregister a husbandry in the mission.
Definition
unregisterHusbandry()

getVehicleName

Description
Extract a concrete vehicle's display name from its store data.
Definition
getVehicleName(table vehicle)
Arguments
tablevehicleVehicle instance
Return Values
stringVehicledisplay name

registerActionEvents

Description
Register required input action events.
Definition
registerActionEvents()

registerPauseActionEvents

Description
Register action events for pause actions.
Event registration in this method is enclosed in an input binding registration context (InputBinding:beginActionEventsModification()).
Make sure that this is only called when all other registration-context altering code is done.
Definition
registerPauseActionEvents()

onToggleMenu

Description
Input event for "open menu".
Definition
onToggleMenu()

onToggleStore

Description
Input event for "open shop".
Definition
onToggleStore()

toggleChat

Description
Toggle chat display.
Called from input to open the chat dialog and from the chat dialog to close it again.
Definition
toggleChat()

onToggleRadio

Description
Input event for "toggle radio".
Definition
onToggleRadio()

onChangeTimescale

Description
Input event for "increase timescale" and "decrease timescale"
Definition
onChangeTimescale()

onShowHelpIconsChanged

Description
Handle a settings change for showing help icons.
Definition
onShowHelpIconsChanged()

onRadioVehicleOnlyChanged

Description
Handle a settings change for the radio vehicle only setting.
If the current radio state is active, the radio will start playing if the context fits (e.g. turn to global, and
player is on foot).
Definition
onRadioVehicleOnlyChanged()

onRadioIsActiveChanged

Description
Handle a settings change for the radio active state.
Definition
onRadioIsActiveChanged()

setRadioActionEventsState

Description
Set the active state for the radio action events.
Definition
setRadioActionEventsState()

subscribeMessages

Description
Subscribe to FS-specific event messages.
The BaseMission parent class unsubscribes from messages in delete(). No clean-up required in sub-classes like this.
Definition
subscribeMessages()

notifyPlayerFarmChanged

Description
Handle a local client changing the farm.
Definition
notifyPlayerFarmChanged()

GameInfoDisplay

Description
HUD general game information display.
-- Displays current game information. This includes weather, current account balance and time settings.
--@category GUI

new

Description
Create a new instance of GameInfoDisplay.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas

setMoneyUnit

Description
Set the money unit for displaying the account balance.
Definition
setMoneyUnit(int moneyUnit)
Arguments
intmoneyUnitMoney unit ID, any of [GS_MONEY_EURO | GS_MONEY_POUND | GS_MONEY_DOLLAR]. Invalid values are substituted by GS_MONEY_DOLLAR.

setMissionStats

Description
Set the MissionStats reference for displaying information.
Definition
setMissionStats(table missionStats)
Arguments
tablemissionStatsMissionStats reference, do not change

setMissionInfo

Description
Set the mission information reference for base information display.
Definition
setMissionInfo(table missionInfo)
Arguments
tablemissionInfoMissionInfo reference, do not change

setEnvironment

Description
Set the environment reference to use for weather information display.
Definition
setEnvironment(table environment)
Arguments
tableenvironmentEnvironment reference, do not change

setMoneyVisible

Description
Set visibility of the money display.
Definition
setMoneyVisible()

setTimeVisible

Description
Set visibility of time display.
Definition
setTimeVisible()

setTemperatureVisible

Description
Set visibility of temperature display.
Definition
setTemperatureVisible()

setWeatherVisible

Description
Set visibility of weather display.
Definition
setWeatherVisible()

setTutorialVisible

Description
Set visibility of tutorial progress display.
Definition
setTutorialVisible()

setTutorialProgress

Description
Set the current tutorial progress values.
Definition
setTutorialProgress(float progress)
Arguments
floatprogressProgress expressed as a number between 0 and 1

update

Description
Update the game info display state.
Definition
update()

updateTime

Description
Update time display.
Definition
updateTime()

updateTemperature

Description
Update temperature display.
Definition
updateTemperature()

updateWeather

Description
Update weather display
Definition
updateWeather()

getVisibleWidth

Description
Get the game info display's width based on its visible info boxes.
Definition
getVisibleWidth()
Return Values
floatGameinfo display width of visible elements in screen space

updateSizeAndPositions

Description
Update sizes and positions of this elements and its children.
Definition
updateSizeAndPositions()

draw

Description
Draw the game info display.
Definition
draw()

drawMoneyText

Description
Draw the text part of the money display.
Definition
drawMoneyText()

drawTimeText

Description
Draw the text part of the time display.
Definition
drawTimeText()

drawTemperatureText

Description
Draw the text part of the temperature display.
Definition
drawTemperatureText()

drawTutorialText

Description
Draw the text part of the tutorial progress display.
Definition
drawTutorialText()

animateWeatherChange

Description
Make an animation for a weather change.
Definition
animateWeatherChange()

addActiveWeatherAnimation

Description
Animate a weather icon becoming active.
Definition
addActiveWeatherAnimation()

addInactiveWeatherAnimation

Description
Animate a weather icon becoming inactive.
Definition
addInactiveWeatherAnimation()

addBecomeCurrentWeatherAnimation

Description
Animate a weather icon becoming the current weather icon.
Definition
addBecomeCurrentWeatherAnimation()

addWeatherPositionAnimation

Description
Animate weather icon position changes.
Definition
addWeatherPositionAnimation()

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor

setScale

Description
Set this element's UI scale factor.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()

createBackground

Description
Create the background overlay.
Definition
createBackground()

createComponents

Description
Create required display components.
Also adds a separator HUDElement instance as a field (".separator") to all info boxes.
Definition
createComponents()

createMoneyBox

Description
Create the money display box.
Definition
createMoneyBox()

createTimeBox

Description
Create the time display box.
Definition
createTimeBox()

createTemperatureBox

Description
Create the temperature display box.
Definition
createTemperatureBox()

createWeatherBox

Description
Create the weather display box.
Definition
createWeatherBox()

createWeatherIcon

Description
Create a weather icon for current and upcoming weather conditions.
Definition
createWeatherIcon(string hudAtlasPath, int weatherId, float boxHeight, table uvs, table color)
Arguments
stringhudAtlasPathPath to HUD texture atlas
intweatherIdWeather condition ID, as defined in WeatherType... constants
floatboxHeightScreen space height of the box which will hold this icon
tableuvsUV coordinates of the weather icon in the HUD texture atlas
tablecolorColor RGBA array
Return Values
tableWeathericon HUDElement instance

createTemperatureIcon

Description
Create a temperature icon to display stable or changing temperatures.
Definition
createTemperatureIcon(string hudAtlasPath, float leftX, float bottomY, float boxHeight, table uvs, table color)
Arguments
stringhudAtlasPathPath to HUD texture atlas
floatleftXScreen space left X position of newly created icon
floatbottomYScreen space bottom Y position of the parent box
floatboxHeightScreen space height of the parent box
tableuvsUV coordinates of the icon in the HUD texture atlas
tablecolorColor RGBA array
Return Values
tableTemperatureicon HUDElement instance

createClockHand

Description
Create a rotatable clock hand icon element.
Definition
createClockHand(string hudAtlasPath, float posX, float posY, table size, table uvs, table color, table pivot)
Arguments
stringhudAtlasPathPath to HUD texture atlas
floatposXScreen space X position of the clock hand
floatposYScreen space Y position of the clock hand
tablesizePixel size vector {width, height}
tableuvsUV coordinates of the icon in the HUD texture atlas
tablecolorColor RGBA array
tablepivotUV pixel space rotation pivot coordinates
Return Values
tableClockhand HUDElement instance

createTimeScaleArrow

Description
Create a time scale arrow icon element.
Definition
createTimeScaleArrow(string hudAtlasPath, float posX, float posY, table size, table uvs)
Arguments
stringhudAtlasPathPath to HUD texture atlas
floatposXScreen space X position of the arrow
floatposYScreen space Y position of the arrow
tablesizePixel size vector {width, height}
tableuvsUV coordinates of the icon in the HUD texture atlas
Return Values
tableTimescale arrow icon HUDElement instance

createVerticalSeparator

Description
Create and return a vertical separator element.
Definition
createVerticalSeparator()

createTutorialBox

Description
Create the tutorial progress box.
Definition
createTutorialBox()

GamepadSigninScreen

Description
Sign-In Screen before Main Menu.
-- Used in console version.
-- @field startText Button prompt text to start the game.

inputEvent

Description
GUI input event callback.
See GuiElement:inputEvent().
Definition
inputEvent()

signIn

Description
Event function for button sign in.
Definition
signIn()

GamePausedDisplay

Description
HUD game pause display element.
-- Displays a customizable message when the game is paused.
--@category GUI

new

Description
Create a new GamePausedDisplay.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD atlas texture.
Return Values
tableGamePausedDisplayinstance

setPauseText

Description
Set a custom text to display.
Definition
setPauseText()

onMenuVisibilityChange

Description
Handle menu visibility state change.
Definition
onMenuVisibilityChange()

setScale

Description
Set uniform UI scale.
Definition
setScale()

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()

createBackground

Description
Get this element's base background position.
Definition
createBackground()

createComponents

Description
Create required display components.
Definition
createComponents()

Gui

Description
Graphical User Interface controller.
-- Builds UI from configurations, provides dialog display and propagates UI input.
--@category GUI

loadProfiles

Description
Load UI profile data from XML.
Definition
loadProfiles(xmlFilename UI)
Arguments
xmlFilenameUIprofiles definition XML file path, relative to application root.

loadGui

Description
Load a UI screen view's elements from an XML definition.
Definition
loadGui(xmlFilename View, name Screen, controller FrameElement, isFrame [optional,)
Arguments
xmlFilenameViewdefinition XML file path, relative to application root.
nameScreenname
controllerFrameElementinstance which serves as the controller for loaded elements
isFrame[optional,default=false] If true, will interpret the loaded view as a frame to be used in multiple places.
Return Values
RootGuiElementinstance of loaded view or nil if the definition XML file could not be loaded.

loadGuiRec

Description
Recursively load and build a UI configuration.
Definition
loadGuiRec(xmlFile Opened, xmlNodePath Current, parentGuiElement Current, target Target)
Arguments
xmlFileOpenedGUI configuration XML file
xmlNodePathCurrentXML node path
parentGuiElementCurrentparent GuiElement
targetTargetof newly instantiated elements

resolveFrameReference

Description
Tries resolving a frame reference.
If no frame has been loaded with the name given by the reference, then the reference element itself is returned.
Otherwise, the registered frame is cloned and returned.
Definition
resolveFrameReference(self Gui, frameRefElement FrameReferenceElement)
Arguments
selfGuiinstance
frameRefElementFrameReferenceElementinstance to resolve
Return Values
ClonedFrameElementinstance or frameRefElement if resolution failed.

getProfile

Description
Get a UI profile by name.
Definition
getProfile()

getIsGuiVisible

Description
Determine if any menu or dialog is visible.
Definition
getIsGuiVisible()

getIsDialogVisible

Description
Determine if any dialog is visible.
Definition
getIsDialogVisible()

getActionEventId

Description
Get a menu action event ID by its name.
Modify GUI action events with care, as they are globally defined for an entire session.
Definition
getActionEventId()

showGui

Description
Display and return a screen identified by name.
Definition
showGui()
Return Values
RootGuiElementof screen or nil if the name did not match any known screen.

showDialog

Description
Display a dialog identified by name.
Definition
showDialog()
Return Values
RootGuiElementof dialog or nil if the name did not match any known dialog.

closeDialogByName

Description
Close a dialog identified by name.
Definition
closeDialogByName()

closeDialog

Description
Close a dialog identified by its root GuiElement.
This is always called when a dialog is closed, usually by itself.
Definition
closeDialog()

closeAllDialogs

Description
Close all open dialogs.
Definition
closeAllDialogs()

registerMenuInput

Description
Register menu input.
Definition
registerMenuInput()

mouseEvent

Description
GUI mouse event hook.
This is used primarily for mouse location checks, as button inputs are handled by InputBinding.
Definition
mouseEvent()

keyEvent

Description
GUI key event hook.
This is used for GuiElements which need to have direct access to raw key input, such as TextInputElement.
Definition
keyEvent()

update

Description
Update the GUI.
Propagates update to all active UI elements.
Definition
update()

draw

Description
Draw the GUI.
Propagates draw calls to all active UI elements.
Definition
draw()

notifyControls

Description
Notify controls of an action input with a value.
Definition
notifyControls(action Action, value Action)
Arguments
actionActionname as defined by loaded actions, see also scripts/input/InputAction.lua
valueActionvalue [-1, 1]
Return Values
Trueifany control has consumed the action event

onMenuInput

Description
Event callback for menu input.
Definition
onMenuInput()

onReleaseMovement

Description
Event callback for released movement menu input.
Definition
onReleaseMovement()

hasElementInputFocus

Description
Determine if a given GuiElement has input focus.
Definition
hasElementInputFocus()

getScreenInstanceByClass

Description
Get a screen controller instance by class for special cases.
Definition
getScreenInstanceByClass(table screenClass)
Arguments
tablescreenClassClass table of the requested screen
Return Values
tableScreenElementdescendant instance of the given class or nil if no such instance was registered

changeScreen

Description
Change the currently displayed screen.
Definition
changeScreen(table source, table screenClass, table returnScreenClass)
Arguments
tablesourceSource screen instance
tablescreenClassClass table of the requested screen to change to or nil to close the GUI
tablereturnScreenClass[optional] Class table of the screen which will be opened on a "back" action in the
new screen.
Return Values
tableRootGuiElement instance of target screen

makeChangeScreenClosure

Description
Make a change screen callback function which encloses the Gui self reference.
This avoids passing the reference around as a parameter or global reference.
Definition
makeChangeScreenClosure()

toggleCustomInputContext

Description
Toggle a custom menu input context for one of the managed frames or screens.
Definition
toggleCustomInputContext()

makeToggleCustomInputContextClosure

Description
Make a toggle custom input context function which encloses the Gui self reference.
Definition
makeToggleCustomInputContextClosure()

makePlaySampleClosure

Description
Make a play sample function which encloses the Gui self reference.
Definition
makePlaySampleClosure()

assignPlaySampleCallback

Description
Assign the play sample closure to a GUI element which has the PlaySampleMixin included.
Definition
assignPlaySampleCallback(table guiElement)
Arguments
tableguiElementGuiElement instance
Return Values
tableTheGuiElement instance given in the guiElement parameter

enterMenuContext

Description
Enter a new menu input context.
Menu views which require special input should provide a context name to not collide with the base menu input scheme.
Definition
enterMenuContext(string contextName)
Arguments
stringcontextName[optional] Custom menu input context name

leaveMenuContext

Description
Leave a menu input context.
This wraps the input context setting to check if the menu is actually active and the context should be reverted to
the state before entering the menu (or a custom menu input context within the menu).
Definition
leaveMenuContext()

addFrame

Description
Add the instance of a specific reusable GUI frame.
Definition
addFrame()

addScreen

Description
Add the instance of a specific GUI screen.
Definition
addScreen()

setCurrentMission

Description
Set the current mission reference for GUI screens.
Definition
setCurrentMission()

setEconomyManager

Description
Set the current economy manager for GUI screens.
The manager is initialized during mission loading.
Definition
setEconomyManager()

loadMapData

Description
Let the GUI (and its components) process map data when it's loaded.
Definition
loadMapData(int mapXmlFile)
Arguments
intmapXmlFileMap configuration XML file handle, do not close, will be handled by caller.

setClient

Description
Set the network client reference for GUI screens.
Definition
setClient()

setIsMultiplayer

Description
Set multiplayer state on screens which need to know about it.
Definition
setIsMultiplayer(bool isMultiplayer)
Arguments
boolisMultiplayerIf true, the GUI needs work in multiplayer mode. Otherwise, it's single player.

initGuiLibrary

Description
Source in UI modules.
Definition
initGuiLibrary(baseDir Base)
Arguments
baseDirBasescripts directory

GuiElement

Description
GUI Element base class.
All elements displayed in the game UI must be instances or descendants of this class.
-- All XML configuration properties as declared below (and in subclasses) are mirrored in guiProfiles.xml as key-value
pairs in the form of &ltValue name="property_name" value="value" /&gt. Profiles are able to inherit from other
profiles, so take care to check their hierarchy if any of your settings do not seem to have any effect. Directly set
properties in the XML configuration will always override profile values, however.
-- Layer properties, prefixed with "[layer]", interact with an overlay system and provide display images. Usable
layers, whose names are substituted for the prefix, are primarily "image" and "icon". UI elements define layer names
on their own and read them from these generated properties. Whenever an element requires a layer, it is described
in its documentation such as this one. Example for an icon layer focus color property:
iconFocusedColor="0.9 0.1 0.5 1.0".
-- A note regarding callbacks: All callbacks are called on an element's target first. When GUI elements are created from
configuration, their top-level view (e.g. MainScreen) is the callback target, i.e. MainScreen:callbackName() is
executed. Unless an element's target has been set to another value explicitly via code, this will always be the case.
--@category GUI
--@xmlConfig GuiElement#id string [optional] Element ID. Must be unique per GUI screen. If set on an element, will expose it as an indexable field on the view class (e.g. id="buttonOk" -> MainScreen.buttonOk). Use this feature sparingly, as it creates implicit coupling which leads to tedious debugging.

new

Description
Create a new GuiElement.
Definition
new(target Target)
Arguments
targetTargetScreenElement instance

loadFromXML

Description
Load element data from an XML definition file.
Definition
loadFromXML(xmlFile Definition, key XML)
Arguments
xmlFileDefinitionXML file handle
keyXMLnode path to this element's definition

loadProfile

Description
Load profile data for this element.
Definition
loadProfile(profile Loaded, applyProfile If)
Arguments
profileLoadedGUI profile
applyProfileIftrue, will re-calculate some dynamic properties. Use this when setting profiles dynamically at run time.

applyProfile

Description
Apply a GUI profile with a given name to this element.
Definition
applyProfile(profileName Name, bool force)
Arguments
profileNameNameof the profile to apply to this element
boolforce[optional] If true, will apply all profile settings, including position and size.

deleteFrame

Description
Delete any created frame overlays.
Definition
deleteFrame()

delete

Description
Delete this GuiElement.
Also deletes all child elements and removes itself from its parent and focus.
Definition
delete()

clone

Description
Create a deep copy clone of this GuiElement.
Definition
clone(parent Target, includeId [optional,, suppressOnCreate [optional,)
Arguments
parentTargetparent element of the cloned element
includeId[optional,default=false] If true, will also clone ID values
suppressOnCreate[optional,default=false] If true, will not trigger the "onCreate" callback

copyAttributes

Description
Copy all attributes from a source GuiElement to this GuiElement.
Definition
copyAttributes()

onGuiSetupFinished

Description
Called on a screen view's root GuiElement when all elements in a screen view have been created.
The event is propagated to all children, depth-first.
Definition
onGuiSetupFinished()

createFrame

Description
Create frame overlays if this element has a frame.
Definition
createFrame()

toggleFrameSide

Description
Toggle a frame side's visibility identified by index.
If this element has no frame this will have no effect.
Definition
toggleFrameSide(int sideIndex)
Arguments
intsideIndexIndex of the frame side, use one of GuiElement.FRAME_...

updateFramePosition

Description
Update the frame overlay positions if necessary.
Definition
updateFramePosition()

cutFrameBordersHorizontal

Description
Cut horizontal frame borders if a vertical frame side is thicker.
Definition
cutFrameBordersHorizontal()

cutFrameBordersVertical

Description
Cut vertical frame borders if a horizontal frame side is thicker.
Definition
cutFrameBordersVertical()

mouseEvent

Description
Mouse event hook for mouse movement checks.
Definition
mouseEvent()

inputEvent

Description
Handles an input event on a menu input action.
Input is first passed to the current GUI view, then to the focused element, then to the focus manager for navigation.
When a GUI element receives input, it should always propagate the input to its parent element first so they may
override behavior and/or set the event used flag. If properly inherited from GuiElement and descendants, this
behavior is guaranteed.
Definition
inputEvent(action Name, value Input, eventUsed If)
Arguments
actionNameof input action which was triggered.
valueInputvalue in the range of [-1, 1] for full axes and [0, 1] for half axes (includes buttons)
eventUsedIftrue, the event has been used by an input handler and should only be acted upon in exceptional cases.
Return Values
Trueifthe input event has been handled, false otherwise.

keyEvent

Description
Key event hook for raw keyboard input.
Definition
keyEvent()
Return Values
Trueifthe keyboard input has been processed by this element.

update

Description
Update this GuiElement.
Definition
update()

draw

Description
Draw this GuiElement.
If defined, triggers the "onDrawCallback".
Definition
draw()

onOpen

Description
Called on the root element of a screen view when it is opened.
This raises the "onOpenCallback" if defined and propagates to all children.
Definition
onOpen()

onClose

Description
Called on the root element of a screen view when it is closed.
This raises the "onCloseCallback" if defined and propagates to all children.
Definition
onClose()

shouldFocusChange

Description
Determine if this GuiElement should change focus in a given direction.
Definition
shouldFocusChange()

canReceiveFocus

Description
Determine if this GuiElement can receive focus.
Definition
canReceiveFocus()

onFocusLeave

Description
Called when this element loses focus.
This propagates to all children.
Definition
onFocusLeave()

onFocusEnter

Description
Called when this element becomes focused.
This propagates to all children.
Definition
onFocusEnter()

onFocusActivate

Description
Called when this element has focus and the focus activation action is triggered.
This propagates to all children.
Definition
onFocusActivate()

onHighlight

Description
Called when this element is highlighted.
This propagates to all children.
Definition
onHighlight()

onHighlightRemove

Description
Called when this element loses the highlight.
This propagates to all children.
Definition
onHighlightRemove()

storeOverlayState

Description

Store the current overlay state while another overrides it (e.g. pressed state)
Definition
storeOverlayState()

restoreOverlayState

Description
Restore a previously stored overlay state after an overriding state has expired
Definition
restoreOverlayState()

getHandleFocus

Description
Determine if this element can receive focus.
Definition
getHandleFocus()

setHandleFocus

Description
Set this elements capability to receive focus.
Definition
setHandleFocus()

addElement

Description
Add a child GuiElement to this GuiElement.
Definition
addElement()

removeElement

Description
Remove a child GuiElement from this GuiElement.
Definition
removeElement()

unlinkElement

Description
Safely remove this GuiElement from its parent, if it has a parent.
Definition
unlinkElement()

updateAbsolutePosition

Description
Update this elements absolute screen position.
This needs to be called whenever a position, alignment, origin or size value changes.
Definition
updateAbsolutePosition()

reset

Description
Resets the state of this GuiElement and its children.
Definition
reset()

isChildOf

Description
Check if this element is the child of another element.
This checks the full parent hierarchy.
Definition
isChildOf()

getFocusTarget

Description
Get the actual focus target, in case a child or parent element needs to be targeted instead.
Definition
getFocusTarget(incomingDirection (Optional), moveDirection (Optional))
Arguments
incomingDirection(Optional)If specified, may return different targets for different incoming directions.
moveDirection(Optional)Actual movement direction per input. This is the opposing direction of incomingDirection.
Return Values
GuiElementActualelement to focus.

setPosition

Description
Set this element's position.
Definition
setPosition()

move

Description
Modify this element's position (i.e. translate position).
Definition
move()

setAbsolutePosition

Description
Directly set the absolute screen position of this GuiElement.
Also updates children accordingly.
Definition
setAbsolutePosition()

setSize

Description
Set this element's size.
Definition
setSize()

setVisible

Description
Set this element's visibility.
Definition
setVisible()

getIsVisible

Description
Determine if this element is visible.
This checks both its current alpha value (set by fadeIn() / fadeOut()) as well as the visibility flag. If the parent
is invisible, then so is this element.
Definition
getIsVisible()

setDisabled

Description
Set this element's disabled state.
Disabled elements can be displayed differently and do not respond to input actions.
Definition
setDisabled(disabled If, doNotUpdateChildren If)
Arguments
disabledIftrue, disables the element. False enables it again.
doNotUpdateChildrenIftrue, does not apply the disabled state to child elements.

getIsDisabled

Description
Determine if this element is disabled.
Definition
getIsDisabled()

getIsSelected

Description
Determine if this element is currently selected.
Definition
getIsSelected()

getIsHighlighted

Description
Determine if this element is currently highlighted.
Definition
getIsHighlighted()

fadeIn

Description
Fade this element into visibility.
Definition
fadeIn()

fadeOut

Description
Fade this element out of visibility.
Definition
fadeOut()

setAlpha

Description
Directly set this element's alpha (transparency) value
Definition
setAlpha(alpha Transparency)
Arguments
alphaTransparencyvalue in the floating point range of [0, 1], where 0 is invisible and 1 is opaque.

getIsActive

Description
Determine if this element is active (not disabled and visible).
Does not take alpha value into account.
Definition
getIsActive()

setSoundSuppressed

Description
Toggle a flag to suppress UI sounds issued by this element or by the FocusManager when handling this element.
This setting will propagate to children.
Definition
setSoundSuppressed()

getSoundSuppressed

Description
Get the sound suppression flag from this element.
If the flag is set to true, no sounds should be played when interacting with this element.
Definition
getSoundSuppressed()

findDescendantsRec

Description

Recursively add descendant elements of a root to an accumulator list. If a predicate function is given, it is
evaluated per element and only elements which yield a true value for the function are added to the accumulator.
Definition
findDescendantsRec(accumulator List, rootElement Current, predicateFunction [optional])
Arguments
accumulatorListwhich receives descendant elements
rootElementCurrentelement root whose direction children are added (after optional evaluation)
predicateFunction[optional]If specified, will be evaluated per element (see getDescendants)

getDescendants

Description
Get all contained elements of this element in the entire hierarchy.
Descendants are traversed depth-first, meaning that if elements have been properly added, the element order mirrors
the order in the XML configuration (lines). Use this method sparingly, especially on high-level elements.
Optionally, a predicate function can be passed which filters descendant elements. The function must return true for
any desired element and false otherwise.
Definition
getDescendants(predicateFunction [optional])
Arguments
predicateFunction[optional]A function which determines if a descendant element should be returned. Must
take a GuiElement as an argument and return true if that element should be returned or false otherwise.
Return Values
Listofthis element's descendants in depth-first order with contiguous numeric indices.

getFirstDescendant

Description
Get the first descendant element of this element which matches a predicate function.
This is a shorthand for getDescendants() which returns just the first element matching the predicate function or nil
if no matching element exists.
Definition
getFirstDescendant(predicateFunction A)
Arguments
predicateFunctionAfunction which determines if a descendant element should be returned. Must take a
GuiElement as an argument and return true if that element should be returned or false otherwise.
Return Values
Firstmatchingdescendant element in depth-first order or nil, if no element matched the predicate function

getDescendantById

Description
Get a descendant element of this element by its ID.
This is a shorthand for getDescendants() with an ID matching predicate function.
Definition
getDescendantById(id Element)
Arguments
idElementid
Return Values
elementornil

getDescendantByName

Description
Get a descendant element of this element by its name.
This is a shorthand for getDescendants() with an ID matching predicate function.
Definition
getDescendantByName(name Element)
Arguments
nameElementname
Return Values
elementornil

updatePositionForOrigin

Description
Get the bit mask value for a position origin string value.
Definition
updatePositionForOrigin()

updateScreenAlign

Description
Get the bit mask value for a screen alignment string value.
Definition
updateScreenAlign()

getParentBorders

Description
Get the bottom left and top right corners of this element's parent's border rectangle.
If this element has no parent, the full screen's borders are returned (i.e. {0, 0, 1, 1})
Definition
getParentBorders()
Return Values
parentelementor full screen borders in an array: {minX, minY, maxX, maxY}

getBorders

Description
Get this element's border rectangle represented by minimum and maximum points.
Definition
getBorders()
Return Values
elementbordersin an array: {minX, minY, maxX, maxY}

getCenter

Description
Get this element's center position.
Definition
getCenter()

applyScreenAlignment

Description
Apply screen alignment to this element and its children.
Scales size, position and margin depending on alignment settings.
Definition
applyScreenAlignment()

setOverlayState

Description
Set this element's overlay state
Definition
setOverlayState(overlayState Overlay)
Arguments
overlayStateOverlaystate identified by one of the GuiOverlay.STATE_[...] constants.

getOverlayState

Description
Get this element's overlay state.
Definition
getOverlayState()

addCallback

Description
Add a callback to this element which was defined in its XML definition.
If this element has a target, the given function name will be called on the target. Otherwise, the function is
assumed to be global.
Definition
addCallback(xmlFile XML, key XML, funcName Name)
Arguments
xmlFileXMLfile handle
keyXMLnode path of this GuiElement's definition.
funcNameNameof the callback function

raiseCallback

Description
Raise a previously added callback by name.
Definition
raiseCallback()

extractIndexAndNameFromID

Description
Try to extract a field name and index from an element ID.
IDs in configurations may be indexed on definition (e.g. fillTypes[2]). This function extracts the list name and
index if such a case is found. Otherwise, it will return no index and the original element ID.
Definition
extractIndexAndNameFromID(elementId Element)
Arguments
elementIdElementID, to be used as a field name on a ScreenElement view.
Return Values
indexornil, field name

setId

Description
Try setting this element's ID from its XML definition.
Definition
setId()

include

Description
Include a mixin in this element.
See GuiMixin.lua for the details on usage and implementation of mixins.
Definition
include(guiMixinType Class)
Arguments
guiMixinTypeClasstable reference of a descendant of GuiMixin

toString

Description
Get a nice string representation for this GUI element.
Definition
toString()

GuiMixin

Description
GuiElement mixin base class.
-- Implements base functionality for GUI element mixins. All other GUI mixins should be descendants of this class.
-- Added methods:
GuiElement:hasIncluded(mixinType) Test if the GuiElement has included a mixin of the given type (class).
--@category GUI

new

Description
Create a new GuiMixin instance.
Subclasses need to provide their class type table for identification.
Definition
new(class Class, mixinType Class)
Arguments
classClassmetatable
mixinTypeClasstype table
Return Values
New

addTo

Description
Add a mixin to a GuiElement.
Adds mixin methods to the element which can then be used. A mixin's state is located in "element[mixinType]".
Definition
addTo()

hasIncluded

Description
Determine if a GuiElement has a mixin type included.
Definition
hasIncluded(GuiElement GuiElement, mixinType GuiMixin)
Arguments
GuiElementGuiElementinstance
mixinTypeGuiMixinclass reference

cloneMixin

Description
Clone mixin states for a mixin type from a source to a destination GuiElement instance.
Definition
cloneMixin()

clone

Description
Clone this mixin's state from a source to a destination GuiElement instance.
Definition
clone()

GuiOverlay

Description
GUI overlay manager.
-- Handles creation, loading and basic rendering of GUI overlays. This module has no interaction with Overlay.lua.
--@category GUI

loadOverlay

Description
Loads overlay data from XML or a profile into a table to turn it into an overlay.
Definition
loadOverlay()

loadXMLUVs

Description
Load overlay UV data from XML.
Definition
loadXMLUVs()

loadProfileUVs

Description
Load overlay UV data from a profile.
Definition
loadProfileUVs()

loadXMLColors

Description
Load overlay color data from XML.
Definition
loadXMLColors()

loadProfileColors

Description
Load overlay color data from a profile.
Definition
loadProfileColors()

createOverlay

Description
(Re-)Create an overlay.
Definition
createOverlay(Overlay Overlay, filename Path)
Arguments
OverlayOverlaytable, see loadOverlay()
filenamePathto image file (can also be a URL for web images)
Return Values
Overlaytablewith added image data

copyOverlay

Description
Copy an overlay.
Definition
copyOverlay()

deleteOverlay

Description
Delete an overlay.
Primarily releases the associated image file handle.
Definition
deleteOverlay()

getOverlayColor

Description
Get an overlay's color for a given overlay state.
Definition
getOverlayColor(Overlay Overlay, state GuiOverlay.STATE_[...])
Arguments
OverlayOverlaytable
stateGuiOverlay.STATE_[...]constant value
Return Values
Coloras{red, green, blue, alpha} with all values in the range of [0, 1]

getOverlayUVs

Description
Get an overlay's UV coordinates for a given overlay state.
Definition
getOverlayUVs(Overlay Overlay, state GuiOverlay.STATE_[...])
Arguments
OverlayOverlaytable
stateGuiOverlay.STATE_[...]constant value
Return Values
UVcoordinatesas {u1, v1, u2, v2, u3, v3, u4x, v4} with all values in the range of [0, 1]

renderOverlay

Description
Renders an overlay with the given parameters.
Definition
renderOverlay(Overlay Overlay, posX Screen, posY Screen, sizeX Screen, sizeY Screen, state GuiOverlay.STATE_[...])
Arguments
OverlayOverlaytable
posXScreenx position
posYScreeny position
sizeXScreenx size
sizeYScreeny size
stateGuiOverlay.STATE_[...]constant for the required display state

GuiProfile

Description
GUI element display profile.
-- Holds GuiElement property data for re-use similar to a HTML/CSS definition.
--@category GUI

new

Description
Create a new GuiProfile.
Definition
new(profiles Reference, traits Reference)
Arguments
profilesReferenceto loaded profiles table for inheritance checking.
traitsReferenceto loaded traits table for inheritance checking.
Return Values
NewGuiProfileinstance

loadFromXML

Description
Load profile data from XML.
Definition
loadFromXML(xmlFile XML, key Profile, presets Table, isTrait Whether)
Arguments
xmlFileXMLfile handle
keyProfileXML element node path
presetsTableof presets for symbol resolution, {preset name=preset value}
isTraitWhetherthis profile is a trait
Return Values
Trueifprofile values could be loaded, false otherwise.

getValue

Description
Get a string value from this profile (and its ancestors) by name.
Definition
getValue(name Name, default Default)
Arguments
nameNameof attribute value to retrieve
defaultDefaultvalue to use if the attribute is not defined.

getBool

Description
Get a boolean value from this profile (and its ancestors) by name.
Definition
getBool(name Name, default Default)
Arguments
nameNameof attribute value to retrieve
defaultDefaultvalue to use if the attribute is not defined.

getNumber

Description
Get a number value from this profile (and its ancestors) by name.
Definition
getNumber(name Name, default Default)
Arguments
nameNameof attribute value to retrieve
defaultDefaultvalue to use if the attribute is not defined.

GuiSoundPlayer

Description
GUI sound player.
-- This class loads known GUI sound samples as non-spatial samples to be played in the GUI (menu and HUD).
--@category GUI

new

Description
Create a new GuiSoundPlayer instance.
Definition
new(table soundManager)
Arguments
tablesoundManagerSoundManager reference

loadSounds

Description
Load GUI sound samples from definitions.
Definition
loadSounds()

playSample

Description
Play a GUI sound sample identified by name.
The sample must have been loaded when the GUI was created.
Definition
playSample(string sampleName)
Arguments
stringsampleNameName of the sample to play, use one of the identifiers in GuiSoundPlayer.SOUND_SAMPLES.

GuiUtils

Description
GUI utility functions.
--@category GUI

getNormalizedValues

Description
Transform an attribute string representing a list of numbers into an array and normalize the values.
Definition
getNormalizedValues(str Attribute, refSize Reference, defaultValue Default)
Arguments
strAttributestring containing numbers, either raw or with a pixel unit designation on each number (e.g. "12 24" or "12px 24px")
refSizeReferencesize for normalization, e.g. a reference screen resolution used to scale pixel values, {sizeX, sizeY}
defaultValueDefaultvalue to return if the "str" parameter value is nil
Return Values
arrayofnormalized values

get2DArray

Description
Transform an attribute string representing a 2D array into an actual array.
Definition
get2DArray(str Attribute, defaultValue Default)
Arguments
strAttributestring containing exactly 2 numbers
defaultValueDefaultvalue to return if the "str" parameter value is nil or invalid for transformation.
Return Values
arrayofthe 2 converted values as numbers: {value1, value2}

get4DArray

Description
Transform an attribute string representing a 4D array into an actual array.
Definition
get4DArray(str Attribute, defaultValue Default)
Arguments
strAttributestring containing exactly 4 numbers
defaultValueDefaultvalue to return if the "str" parameter value is nil or invalid for transformation.
Return Values
arrayofthe 4 converted values as numbers: {value1, value2, value3, value4}

getColorArray

Description
Transform an attribute string representing a 4D color array into an actual array.
Definition
getColorArray(str Attribute, defaultValue Default)
Arguments
strAttributestring containing exactly 4 numbers
defaultValueDefaultvalue to return if the "str" parameter value is nil or invalid for transformation.
Return Values
arrayofthe 4 converted values as numbers: {red, green, blue, alpha}

getUVs

Description
Transform an attribute string representing a UV array into an actual array and normalize the values.
Definition
getUVs(str Attribute, ref Texture, defaultValue Default)
Arguments
strAttributestring containing exactly 4 numbers, order and format: "x[px] y[px] sizeX[px] sizeY[px]"
refTexturereference size used to normalize pixel UV coordinates into unit sized UV coordinates
defaultValueDefaultvalue to return if the "str" parameter value is nil or invalid for transformation.
Return Values
arrayofthe UV coordinates as {u1, v1, u2, v2, u3, v3, u4, v4}

checkOverlayOverlap

Description
Check if a point lies within or a hotspot overlaps an overlay.
Definition
checkOverlayOverlap(posX Point, posY Point, overlayX Overlay, overlayY Overlay, overlaySizeX Overlay, overlaySizeY Overlay, hotspot If)
Arguments
posXPointor hotspot x position
posYPointor hotspot y position
overlayXOverlayx position
overlayYOverlayy position
overlaySizeXOverlaywidth
overlaySizeYOverlayheight
hotspotIfprovided as an array having 4 numbers for the bounding points of a rectangle {minX, minY, maxX, maxY}, will be checked if it overlaps the overlay area given by the other parameters.

HighPressureWasherPlaceable

Description

HighPressureWasher Activatable

new

Description
Creating placeable high pressure washer
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
20function HighPressureWasher:new(isServer, isClient, customMt)
21 local mt = customMt
22 if mt == nil then
23 mt = HighPressureWasher_mt
24 end
25
26 local self = Placeable:new(isServer, isClient, mt)
27 registerObjectClassName(self, "HighPressureWasher")
28
29 return self
30end

load

Description
Load high pressure washer
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
43function HighPressureWasher:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
44 if not HighPressureWasher:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
45 return false
46 end
47
48 local xmlFile = loadXMLFile("TempXML", xmlFilename)
49
50 self.lanceNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.highPressureWasher.lance#index"))
51 self.handtoolXML = Utils.getFilename(getXMLString(xmlFile, "placeable.highPressureWasher.handtool#filename"), self.baseDirectory)
52 self.playerInRangeDistance = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.highPressureWasher.playerInRangeDistance"), 3)
53 self.actionRadius = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.highPressureWasher.actionRadius#distance"), 15)
54
55 if self.isClient then
56 self.hpwSamples = {}
57 if self.isClient then
58 self.hpwSamples.compressor = g_soundManager:loadSampleFromXML(xmlFile, "placeable.highPressureWasher.sounds", "compressor", self.baseDirectory, self.nodeId, 0, AudioGroup.VEHICLE, nil, self)
59 self.hpwSamples.switch = g_soundManager:loadSampleFromXML(xmlFile, "placeable.highPressureWasher.sounds", "switch", self.baseDirectory, self.nodeId, 1, AudioGroup.VEHICLE, nil, self)
60 end
61
62 local filename = getXMLString(xmlFile, "placeable.highPressureWasher.exhaust#filename")
63 if filename ~= nil then
64 local i3dNode = g_i3DManager:loadSharedI3DFile(filename, self.baseDirectory, false, false, false)
65 if i3dNode ~= 0 then
66 local linkNode = Utils.getNoNil(I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.highPressureWasher.exhaust#index")), self.nodeId)
67 self.exhaustFilename = filename
68 self.exhaustNode = getChildAt(i3dNode, 0)
69 link(linkNode, self.exhaustNode)
70 setVisibility(self.exhaustNode, false)
71 delete(i3dNode)
72 end
73 end
74 end
75
76 delete(xmlFile)
77
78 self.isPlayerInRange = false
79 self.isTurnedOn = false
80 self.isTurningOff = false
81 self.turnOffTime = 0
82 self.turnOffDuration = 500
83 self.activatable = HighPressureWasherActivatable:new(self)
84 self.lastInRangePosition = {0,0,0}
85
86 return true
87end

delete

Description
Deleting placeable high pressure washer
Definition
delete()
Code
91function HighPressureWasher:delete()
92 self:setIsTurnedOn(false, nil, false)
93 if self.isClient then
94 if self.exhaustFilename ~= nil then
95 g_i3DManager:releaseSharedI3DFile(self.exhaustFilename, self.baseDirectory, true)
96 end
97 g_soundManager:deleteSamples(self.hpwSamples)
98 end
99
100 unregisterObjectClassName(self)
101 g_currentMission:removeActivatableObject(self.activatable)
102 HighPressureWasher:superClass().delete(self)
103end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
109function HighPressureWasher:readStream(streamId, connection)
110 HighPressureWasher:superClass().readStream(self, streamId, connection)
111 if connection:getIsServer() then
112 local isTurnedOn = streamReadBool(streamId)
113 if isTurnedOn then
114 local player = NetworkUtil.readNodeObject(streamId)
115 if player ~= nil then
116 self:setIsTurnedOn(isTurnedOn, player, true)
117 end
118 end
119 end
120end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
126function HighPressureWasher:writeStream(streamId, connection)
127 HighPressureWasher:superClass().writeStream(self, streamId, connection)
128 if not connection:getIsServer() then
129 streamWriteBool(streamId, self.isTurnedOn)
130 if self.isTurnedOn then
131 NetworkUtil.writeNodeObject(streamId, self.currentPlayer)
132 end
133 end
134end

activateHandtool

Description
Activate hand tool
Definition
activateHandtool(table player)
Arguments
tableplayerplayer
Code
139function HighPressureWasher:activateHandtool(player)
140 self:setIsTurnedOn(true, player, true)
141end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
146function HighPressureWasher:update(dt)
147 HighPressureWasher:superClass().update(self, dt)
148
149 if self.currentPlayer ~= nil then
150 local isPlayerInRange = self:getIsPlayerInRange(self.actionRadius, self.currentPlayer)
151 if isPlayerInRange then
152 self.lastInRangePosition = {getTranslation(self.currentPlayer.rootNode)}
153 else
154 local kx, _, kz = getWorldTranslation(self.nodeId)
155 local px, py, pz = getWorldTranslation(self.currentPlayer.rootNode)
156 local len = MathUtil.vector2Length(px-kx, pz-kz)
157
158 local x,y,z = unpack(self.lastInRangePosition)
159 x = kx + ((px-kx) / len) * (self.actionRadius-0.00001*dt)
160 z = kz + ((pz-kz) / len) * (self.actionRadius-0.00001*dt)
161 self.currentPlayer:moveToAbsoluteInternal(x, py, z)
162 self.lastInRangePosition = {x,y,z}
163
164 if self.currentPlayer == g_currentMission.player then
165 g_currentMission:showBlinkingWarning(g_i18n:getText("warning_hpwRangeRestriction"), 4000)
166 end
167 end
168 end
169
170 if self.isClient then
171 if self.isTurningOff then
172 if g_currentMission.time > self.turnOffTime then
173 self.isTurningOff = false
174 g_soundManager:stopSample(self.hpwSamples.compressor)
175 end
176 end
177 end
178
179 self:raiseActive()
180end

updateTick

Description
updateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
197function HighPressureWasher:updateTick(dt)
198 HighPressureWasher:superClass().updateTick(self, dt)
199 local isPlayerInRange, player = self:getIsPlayerInRange(self.playerInRangeDistance)
200
201 if isPlayerInRange and g_currentMission.accessHandler:canPlayerAccess(self, player) then
202 self.playerInRange = player
203 self.isPlayerInRange = true
204 g_currentMission:addActivatableObject(self.activatable)
205 else
206 self.playerInRange = nil
207 self.isPlayerInRange = false
208 g_currentMission:removeActivatableObject(self.activatable)
209 end
210end

setIsTurnedOn

Description
Set is turned on
Definition
setIsTurnedOn(boolean isTurnedOn, table player, boolean noEventSend)
Arguments
booleanisTurnedOnis turned on
tableplayerplayer
booleannoEventSendno event send
Code
217function HighPressureWasher:setIsTurnedOn(isTurnedOn, player, noEventSend)
218 HPWPlaceableTurnOnEvent.sendEvent(self, isTurnedOn, player, noEventSend)
219
220 if self.isTurnedOn ~= isTurnedOn then
221 if isTurnedOn then
222 self.isTurnedOn = isTurnedOn
223
224 if player ~= nil then
225 self.currentPlayer = player
226 self.currentPlayer:addDeleteListener(self, "onPlayerDelete")
227 if noEventSend ~= true then
228 self.currentPlayer:equipHandtool(self.handtoolXML, true, noEventSend)
229 self.currentPlayer.baseInformation.currentHandtool:addDeleteListener(self, "onHandtoolDelete")
230 end
231 end
232
233 if self.isClient then
234 g_soundManager:playSample(self.hpwSamples.switch)
235 g_soundManager:playSample(self.hpwSamples.compressor)
236
237 if self.isTurningOff then
238 self.isTurningOff = false
239 end
240 setVisibility(self.lanceNode, false)
241 end
242 else
243 self:onDeactivate()
244 end
245 if self.exhaustNode ~= nil then
246 setVisibility(self.exhaustNode, isTurnedOn)
247 end
248 end
249end

onPlayerDelete

Description
Definition
onPlayerDelete()
Code
253function HighPressureWasher:onPlayerDelete()
254 self.currentPlayer = nil
255 self:setIsTurnedOn(false, nil, nil)
256end

onHandtoolDelete

Description
Definition
onHandtoolDelete()
Code
260function HighPressureWasher:onHandtoolDelete()
261 self.currentPlayer = nil
262 self:setIsTurnedOn(false, nil, nil)
263end

onDeactivate

Description
On deactivate
Definition
onDeactivate()
Code
267function HighPressureWasher:onDeactivate()
268 if self.isClient then
269 g_soundManager:playSample(self.hpwSamples.switch)
270 g_soundManager:stopSample(self.hpwSamples.washing, true)
271 self.isTurningOff = true
272 self.turnOffTime = g_currentMission.time + self.turnOffDuration
273 end
274 self.isTurnedOn = false
275 setVisibility(self.lanceNode, true)
276 if self.currentPlayer ~= nil then
277 if self.currentPlayer:hasHandtoolEquipped() then
278 self.currentPlayer.baseInformation.currentHandtool:removeDeleteListener(self, "onHandtoolDelete")
279 self.currentPlayer:unequipHandtool()
280 end
281 self.currentPlayer:removeDeleteListener(self, "onPlayerDelete")
282 self.currentPlayer = nil
283 end
284end

getIsActiveForInput

Description
Get is active for input
Definition
getIsActiveForInput()
Return Values
booleanisActiveForInputis active for input
Code
289function HighPressureWasher:getIsActiveForInput()
290 if self.isTurnedOn and self.currentPlayer == g_currentMission.player and not g_gui:getIsGuiVisible() then
291 return true
292 end
293 return false
294end

getIsActiveForSound

Description
Get is active for sound
Definition
getIsActiveForSound()
Return Values
booleanisActiveForSoundis active for sound
Code
299function HighPressureWasher:getIsActiveForSound()
300 return self:getIsActiveForInput()
301end

canBeSold

Description
Get can be sold in current state
Definition
canBeSold()
Return Values
boolean
stringwarningMessagewarning message displayed in the shop
Code
307function HighPressureWasher:canBeSold()
308 local warning = g_i18n:getText("shop_messageReturnVehicleInUse")
309 if self.currentPlayer ~= nil then
310 return false, warning
311 end
312 return true, nil
313end

Horse

Description
Minimum daily riding time for a horse below which it will lose fitness.

new

Description
Definition
new()
Code
22function Horse:new(isServer, isClient, owner, fillTypeIndex, customMt)
23 local self = RideableAnimal:new(isServer, isClient, owner, fillTypeIndex, customMt or Horse_mt)
24
25 self.name = g_animalNameManager:getRandomName()
26
27 self.fitnessScale = 0.0
28 self.fitnessScaleSent = 0.0
29
30 self.healthScale = 1.0
31 self.healthScaleSent = 1.0
32
33 self.ridingTimer = 0.0
34
35 self.horseDirtyFlag = self:getNextDirtyFlag()
36
37 return self
38end

readStream

Description
Definition
readStream()
Code
42function Horse:readStream(streamId)
43 Horse:superClass().readStream(self, streamId)
44
45 self.name = streamReadString(streamId)
46 self.fitnessScale = streamReadFloat32(streamId)
47 self.healthScale = streamReadFloat32(streamId)
48 self.ridingTimer = streamReadFloat32(streamId)
49end

writeStream

Description
Definition
writeStream()
Code
53function Horse:writeStream(streamId)
54 Horse:superClass().writeStream(self, streamId)
55
56 streamWriteString(streamId, self.name)
57 streamWriteFloat32(streamId, self.fitnessScale)
58 streamWriteFloat32(streamId, self.healthScale)
59 streamWriteFloat32(streamId, self.ridingTimer)
60end

readUpdateStream

Description
Definition
readUpdateStream()
Code
64function Horse:readUpdateStream(streamId, timestamp, connection)
65 Horse:superClass().readUpdateStream(self, streamId, timestamp, connection)
66
67 -- server to client only
68 if connection:getIsServer() then
69 if streamReadBool(streamId) then
70 self.fitnessScale = NetworkUtil.readCompressedPercentages(streamId, 7)
71 self.healthScale = NetworkUtil.readCompressedPercentages(streamId, 7)
72 end
73 end
74end

writeUpdateStream

Description
Definition
writeUpdateStream()
Code
78function Horse:writeUpdateStream(streamId, connection, dirtyMask)
79 Horse:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
80
81 -- server to client only
82 if not connection:getIsServer() then
83 if streamWriteBool(streamId, bitAND(dirtyMask, self.horseDirtyFlag) ~= 0) then
84 NetworkUtil.writeCompressedPercentages(streamId, self.fitnessScaleSent, 7)
85 NetworkUtil.writeCompressedPercentages(streamId, self.healthScaleSent, 7)
86 end
87 end
88end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
92function Horse:loadFromXMLFile(xmlFile, key)
93 Horse:superClass().loadFromXMLFile(self, xmlFile, key)
94
95 self.name = getXMLString(xmlFile, key.."#name") or self.name
96 self.fitnessScale = getXMLFloat(xmlFile, key.."#fitnessScale") or self.fitnessScale
97 self.healthScale = getXMLFloat(xmlFile, key.."#healthScale") or self.healthScale
98 self.ridingTimer = getXMLFloat(xmlFile, key.."#ridingTimer") or self.ridingTimer
99 self.fitnessScaleSent = self.fitnessScale
100end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
104function Horse:saveToXMLFile(xmlFile, key, usedModNames)
105 Horse:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
106
107 setXMLString(xmlFile, key.."#name", self.name)
108 setXMLFloat(xmlFile, key.."#fitnessScale", self.fitnessScale)
109 setXMLFloat(xmlFile, key.."#healthScale", self.healthScale)
110 setXMLFloat(xmlFile, key.."#ridingTimer", self.ridingTimer)
111end

setName

Description
Definition
setName()
Code
115function Horse:setName(name)
116
117 if self.name ~= nil and self.name ~= name then
118 self.name = name
119 g_messageCenter:publish(MessageType.HUSBANDRY_ANIMALS_CHANGED, self.owner)
120 end
121end

getName

Description
Definition
getName()
Code
125function Horse:getName()
126 return self.name
127end

getValueScale

Description
Definition
getValueScale()
Code
131function Horse:getValueScale()
132 -- dirt scale should only count 10%
133 return 0.90 * (self.fitnessScale * self.healthScale) + 0.10 * (1-self.dirtScale)
134end

setFitnessScale

Description
Definition
setFitnessScale()
Code
138function Horse:setFitnessScale(scale, noEventSend)
139 self.fitnessScale = scale
140 if math.abs(self.fitnessScaleSent - self.fitnessScale) > 0.01 then
141 self.fitnessScaleSent = self.fitnessScale
142 g_messageCenter:publish(MessageType.HUSBANDRY_ANIMALS_CHANGED, self.owner)
143
144 if noEventSend == nil or not noEventSend then
145 self:raiseDirtyFlags(self.horseDirtyFlag)
146 end
147 end
148end

getFitnessScale

Description
Definition
getFitnessScale()
Code
152function Horse:getFitnessScale()
153 return self.fitnessScale
154end

setHealthScale

Description
Definition
setHealthScale()
Code
158function Horse:setHealthScale(scale, noEventSend)
159 self.healthScale = scale
160 if math.abs(self.healthScaleSent - self.healthScale) > 0.01 then
161 self.healthScaleSent = self.healthScale
162 g_messageCenter:publish(MessageType.HUSBANDRY_ANIMALS_CHANGED, self.owner)
163
164 if noEventSend == nil or not noEventSend then
165 self:raiseDirtyFlags(self.horseDirtyFlag)
166 end
167 end
168end

getHealthScale

Description
Definition
getHealthScale()
Code
172function Horse:getHealthScale()
173 return self.healthScale
174end

getTodaysRidingTime

Description
Get the riding time of this horse for the current day in milliseconds.
Definition
getTodaysRidingTime()

deactivateRiding

Description
Definition
deactivateRiding()
Code
183function Horse:deactivateRiding(noEventSend)
184 if self.rideableVehicle ~= nil then
185 self.rideableVehicle:setFitnessChangedCallback(nil, nil)
186 end
187
188 Horse:superClass().deactivateRiding(self, noEventSend)
189end

onLoadedRideable

Description
Definition
onLoadedRideable()
Code
193function Horse:onLoadedRideable(rideableVehicle, vehicleLoadState, arguments)
194 Horse:superClass().onLoadedRideable(self, rideableVehicle, vehicleLoadState, arguments)
195
196 if self.rideableVehicle ~= nil then
197 self.rideableVehicle:setFitnessChangedCallback(self.onFitnessChangedCallback, self)
198 end
199end

onFitnessChangedCallback

Description
Definition
onFitnessChangedCallback()
Code
203function Horse:onFitnessChangedCallback(deltaTime)
204 self.ridingTimer = self.ridingTimer + deltaTime
205end

updateFitness

Description
Definition
updateFitness()
Code
209function Horse:updateFitness()
210 if self.isServer then
211 local fitness = self:getFitnessScale()
212
213 if self.ridingTimer < Horse.DAILY_MINIMUM_RIDING_TIME then
214 fitness = fitness - 0.02
215 else -- add capped gain
216 local fitnessGain = math.min(0.1, 0.1 * self.ridingTimer / Horse.DAILY_TARGET_RIDING_TIME)
217 fitness = fitness + fitnessGain
218 end
219
220 fitness = MathUtil.clamp(fitness, 0.0, 1.0)
221 self:setFitnessScale(fitness)
222 end
223
224 self.ridingTimer = 0.0
225end

HUD

Description
Heads-up display.
-- The HUD displays information for the player when in game.
--@category GUI

new

Description
Create a new HUD instance.
Definition
new(bool isServer, bool isServer, bool isConsoleVersion, table messageCenter, table l10n, table inputManager, table inputDisplayManager, table modManager, table fillTypeManager, table fruitTypeManager, table guiSoundPlayer)
Arguments
boolisServerIf true, the running game instance is a server
boolisServerIf true, the running game instance is a client
boolisConsoleVersionIf true, we are running on console
tablemessageCenterMessageCenter reference for message subscriptions
tablel10nI18N reference for text localization
tableinputManagerInputBinding reference
tableinputDisplayManagerInputDisplayManager reference
tablemodManagerModManager reference
tablefillTypeManagerFillTypeManager reference
tablefruitTypeManagerFruitTypeManager reference
tableguiSoundPlayerGuiSoundPlayer reference

createDisplayComponents

Description
Create all required display components.
Definition
createDisplayComponents(uiScale Current)
Arguments
uiScaleCurrentUI scale

delete

Description
Delete the HUD and all its display components.
Definition
delete()

subscribeMessages

Description
Subscribe to relevant state messages.
Definition
subscribeMessages()

setScale

Description
Set the scale of the HUD.
Definition
setScale(float scale)
Arguments
floatscaleNew scale value

drawControlledEntityHUD

Description
Draw the HUD components for the currently controlled entity (player or vehicle).
Definition
drawControlledEntityHUD()

drawInputHelp

Description
Draw the input help display panel and vehicle schema.
Definition
drawInputHelp()

drawTopNotification

Description
Draw a notification at the top center of the screen if one has been set.
Definition
drawTopNotification()

drawBlinkingWarning

Description
Draw a blinking warning if necessary.
Definition
drawBlinkingWarning()

drawPresentationVersion

Description
Draw the presentation mode logo.
Definition
drawPresentationVersion()

drawFading

Description
Draw the screen fade effect.
Definition
drawFading()

drawOverlayAtPositionWithDimensions

Description
Draw an overlay at a given screen space position with given dimensions.
Omitting a parameter will use the last setting of that parameter (or initial setting if parameter is never supplied).
Definition
drawOverlayAtPositionWithDimensions(table overlay, float screenX, float screenY, float screenWidth, float screenHeight)
Arguments
tableoverlayOverlay instance to draw
floatscreenXDrawing origin X position in screen space
floatscreenYDrawing origin Y position in screen space
floatscreenWidthDrawing horizontal size in screen space
floatscreenHeightDrawing vertical size in screen space

drawOverlayAtPosition

Description
Draw an overlay at a given screen space position.
Omitting a parameter will use the last setting of that parameter.
Definition
drawOverlayAtPosition(table overlay, float screenX, float screenY)
Arguments
tableoverlayOverlay instance to draw
floatscreenXDrawing origin X position in screen space
floatscreenYDrawing origin Y position in screen space

drawSideNotification

Description
Draw notification texts at the side of the screen.
Definition
drawSideNotification()

drawBaseHUD

Description
Draw the regular HUD for career mode.
Definition
drawBaseHUD()

drawCommunicationDisplay

Description
Draw the platform communication display (chat or speaker icons).
Definition
drawCommunicationDisplay()

setTutorialProgress

Description
Set the tutorial progress.
Definition
setTutorialProgress(float progress)
Arguments
floatprogressProgress expressed as a number between 0 and 1

drawGamePaused

Description
Draw a pause notification with a message text and synchronizing background if the menu is visible.
Definition
drawGamePaused(bool beforeMissionStart)
Arguments
boolbeforeMissionStartIf true, draw a special overlay for cases when the menu has not yet loaded but the world is already visible.

drawVehicleName

Description
Draw the current vehicle name if it's active.
Definition
drawVehicleName()

drawInGameMessageAndIcon

Description
Draw the message window and icon at the bottom of the screen.
Definition
drawInGameMessageAndIcon()

drawMissionCompleted

Description
Show a "mission accomplished" message.
Definition
drawMissionCompleted()

drawMissionFailed

Description
Show a "mission failed" message.
Definition
drawMissionFailed()

showInGameMessage

Description
Display an in-game message in a window at the bottom.
This calls InGameMessage:showMessage(title, message, duration, controls, callback, target).
Definition
showInGameMessage()

showBlinkingWarning

Description
Display a blinking warning text.
Definition
showBlinkingWarning(string text, int duration, int priority)
Arguments
stringtextWarning text
intduration[optional, default=2000] Duration of warning visibility in milliseconds
intpriority[optional, default=0] Warning priority value. If a new warning is triggered with the same or higher priority as a current
one, the current warning is replaced.

addMoneyChange

Description
Accumulate a money transaction amount by type until shown by HUD.showMoneyChange().
Definition
addMoneyChange(int moneyType, float amount)
Arguments
intmoneyTypeType of transaction from EconomyManager.MONEY_TYPE_XYZ
floatamountAmount of money

showMoneyChange

Description
Display a money change notification at the right side of the screen.
Definition
showMoneyChange(int moneyType, string text)
Arguments
intmoneyTypeType of transaction from EconomyManager.MONEY_TYPE_XYZ
stringtextSpecific money type label (e.g. "loan interest")

addExtraPrintText

Description
Add an extra text to display in the input help panel for this frame.
Definition
addExtraPrintText()

showVehicleName

Description
Display the name of a vehicle at the bottom of the screen for a short time.
Definition
showVehicleName(string vehicleName)
Arguments
stringvehicleNameName of a vehicle

addSideNotification

Description
Add a notification to be displayed at the right side of the screen.
Definition
addSideNotification(table color)
Arguments
tablecolorColor as an RGBA array

addTopNotification

Description
Add a notification to be displayed in a frame at the top of the screen.
Definition
addTopNotification(string title, string text, string info, table iconKey, int duration)
Arguments
stringtitleNotification title
stringtextNotification message text
stringinfoAdditional info text
tableiconKey[optional] Icon key for a display icon, use a value from TopNotification.ICON
intduration[optional] Display duration in milliseconds. Negative values or nil default to a long-ish standard duration.

hideTopNotification

Description
Hide a current notification shown by HUD:addTopNotification().
Definition
hideTopNotification()

getIsFading

Description
Check if the HUD is currently fading the screen.
Definition
getIsFading()

setGameInfoPartVisibility

Description
Set the visibility of the game info display parts by flags.
Definition
setGameInfoPartVisibility(partFlags Combination)
Arguments
partFlagsCombinationof values from HUD.GAME_INFO_PART

onMenuVisibilityChange

Description
Handle menu visibility changes.
Keeps track of the menu visibility to block relevant processes.
Definition
onMenuVisibilityChange()

onPauseGameChange

Description
Handle game pause state changes.
Definition
onPauseGameChange(bool isPaused, string pauseText)
Arguments
boolisPaused[optional] If true, the game is currently paused. If not set, will not change the pause state.
stringpauseText[optional] Text to display on the pause element

setIsVisible

Description
Set HUD visibility.
Definition
setIsVisible(bool isVisible)
Arguments
boolisVisibleIf true, the HUD is made visible. If false, it's made invisible.

setInputHelpVisible

Description
Set input help visibility.
Definition
setInputHelpVisible(bool isVisible)
Arguments
boolisVisibleIf true, the input help is displayed. If false, it's made invisible

setFieldInfoVisible

Description
Set field info display visibility.
Definition
setFieldInfoVisible(bool isVisible)
Arguments
boolisVisibleIf true, the field info display is shown. If false, it's hidden.

addCustomInputHelpEntry

Description
Add a custom input help entry which is displayed until removed.
Custom entries will be displayed in order of addition after any automatically detected input help entries and before
vehicle extensions.
Definition
addCustomInputHelpEntry()

clearCustomInputHelpEntries

Description
Clear all custom input help entries.
Definition
clearCustomInputHelpEntries()

getIsVisible

Description
Check if the HUD is visible.
Definition
getIsVisible()
Return Values
boolIftrue, the HUD is currently visible.

setControlledVehicle

Description
Set current controlled vehicle.
Definition
setControlledVehicle(table vehicle)
Arguments
tablevehicleVehicle reference or nil (not controlling a vehicle)

setIsControllingPlayer

Description
Set current player controlling state.
Definition
setIsControllingPlayer(bool isControllingPlayer)
Arguments
boolisControllingPlayerIf true, the player is controlling their character on foot.

setMoneyUnit

Description
Set the money unit (currency) to display.
Definition
setMoneyUnit(int unit)
Arguments
intunitOne of [GS_MONEY_EURO | GS_MONEY_POUND], any other value will display a universal dollar sign.

showAchievementMessage

Description
Display an achievement message.
Definition
showAchievementMessage()

showAttachContext

Description
Display vehicle attachment context information for the current frame.
Definition
showAttachContext()

showTipContext

Description
Display vehicle tipping context information for the current frame.
Definition
showTipContext()

showFuelContext

Description
Display vehicle refueling context information for the current frame.
Definition
showFuelContext()

showFillDogBowlContext

Description
Display dog bowl refilling context information for the current frame.
Definition
showFillDogBowlContext()

setPlayer

Description
Set the reference to the current player.
Definition
setPlayer()

setConnectedUsers

Description
Set the references to the currently connected users.
Definition
setConnectedUsers()

updateMessageAndIcon

Description
Update in-game message window and icon.
Definition
updateMessageAndIcon()

update

Description
Update base HUD state.
Definition
update()

updateBlinkingWarning

Description
Update the blinking warning if one is set.
Definition
updateBlinkingWarning()

updateMap

Description
Update the in-game map.
Definition
updateMap()

updateVehicleName

Description
Update vehicle name display when a vehicle was entered.
Definition
updateVehicleName()

fadeScreen

Description
Fade the screen.
Definition
fadeScreen(int direction, int duration, func callbackFunc, table callbackTarget)
Arguments
intdirectionIf > 0 will fade to opaque (i.e. black screen), if < 0 will fade to transparent (i.e. clear)
intdurationTarget duration of the fade animation in milliseconds
funccallbackFunc[optional] Callback function which is called when the fading animation completes
tablecallbackTarget[optional] Callback function target which is passed to the callback function as its first
argument if provided

loadIngameMap

Description
Load graphics and settings for the in-game map.
Definition
loadIngameMap(string ingameMapFilename, int ingameMapWidth, int ingameMapHeight)
Arguments
stringingameMapFilenamePath to map image
intingameMapWidthWidth of the map (X)
intingameMapHeightHeight of the map (Y)

setIngameMapSize

Description
Set the size index of the in-game map.
Definition
setIngameMapSize(int sizeIndex)
Arguments
intsizeIndexOne of [IngameMap.STATE_MINIMAP | IngameMap.STATE_MAP | IngameMap.STATE_OFF]

getIngameMap

Description
Get the in-game map reference.
Definition
getIngameMap()

isInGameMessageActive

Description
Check if the in-game message is currently active.
Definition
isInGameMessageActive()

mouseEvent

Description
Mouse event function.
Only delegates input to components.
Definition
mouseEvent()

setEnvironment

Description
Set the environment reference to use for weather information display.
Definition
setEnvironment(table environment)
Arguments
tableenvironmentEnvironment reference, do not change

setMissionInfo

Description
Set the mission information reference for base information display.
Definition
setMissionInfo(table missionInfo)
Arguments
tablemissionInfoMissionInfo reference, do not change

setMissionStats

Description
Set the mission statistics reference for base information display.
Definition
setMissionStats(table missionStats)
Arguments
tablemissionStatsMissionStats reference, do not change

setInGameIconOnPickup

Description
Set the in-game icon display when picking up an egg or nugget.
Definition
setInGameIconOnPickup()

scrollChatMessages

Description
Scroll chat messages by a given amount.
Definition
scrollChatMessages(int delta, int numMessages)
Arguments
intdeltaNumber of lines (positive or negative) to scroll
intnumMessagesNumber of currently stored chat messages

setChatWindowVisible

Description
Set chat window visibility.
When disabled, the chat display will linger for some time.
Definition
setChatWindowVisible()

setChatMessagesReference

Description
Set the chat messages array reference for the chat window.
The array is owned by the caller and must not be modified by consumers.
Definition
setChatMessagesReference()

registerInput

Description
Register input events of HUD components.
Definition
registerInput()

HUDDisplayElement

Description
HUD display element whose subclasses implement more complex HUD display subsystems.
--@category GUI

new

Description
Create a new HUD display element.
Definition
new(table subClass, table overlay, table parentHudElement)
Arguments
tablesubClassSubclass metatable for inheritance
tableoverlayWrapped Overlay instance
tableparentHudElement[optional] Parent HUD element of the newly created HUD element
Return Values
tableHUDDisplayElementinstance

setVisible

Description
Set this element's visibility with optional animation.
Definition
setVisible(bool isVisible, bool animate)
Arguments
boolisVisibleTrue is visible, false is not.
boolanimateIf true, the element will play an animation before applying the visibility change.

setScale

Description
Simplification of scale setter because these high-level elements always use a uniform scale.
Definition
setScale()

storeOriginalPosition

Description
Store the current element position as its original positions.
Definition
storeOriginalPosition()

getHidingTranslation

Description
Get the screen space translation for hiding.
Override in sub-classes if a different translation is required.
Definition
getHidingTranslation()
Return Values
floatScreenspace X translation
floatScreenspace Y translation

animationSetPositionX

Description
Animation setter function for X position.
Definition
animationSetPositionX()

animationSetPositionY

Description
Animation setter function for Y position.
Definition
animationSetPositionY()

animateHide

Description
Animate this element on hiding.
Definition
animateHide()

animateShow

Description
Animate this element on showing.
Definition
animateShow()

onAnimateVisibilityFinished

Description
Called when a hiding or showing animation has finished.
Definition
onAnimateVisibilityFinished()

HUDElement

Description
Lightweight HUD UI element.
-- Wraps an Overlay instance to display and provides a transform hierarchy of child HUDElement instances.
--@category GUI

new

Description
Create a new HUD element.
Definition
new(table subClass, table overlay, table parentHudElement)
Arguments
tablesubClassSubclass metatable for inheritance
tableoverlayWrapped Overlay instance
tableparentHudElement[optional] Parent HUD element of the newly created HUD element
Return Values
tableHUDElementinstance

delete

Description
Delete this HUD element and all its children.
This will also delete the overlay and thus release its engine handle.
Definition
delete()

addChild

Description
Add a child HUD element to this element.
Definition
addChild(table childHudElement)
Arguments
tablechildHudElementHUDElement instance which is added as a child.

removeChild

Description
Remove a child HUD element from this element.
Definition
removeChild(table childHudElement)
Arguments
tablechildHudElementHUDElement instance which is removed as a child.

setPosition

Description
Set a HUD element's absolute screen space position.
If the element has any children, they will be moved with this element.
Definition
setPosition()

setRotation

Description
Set this HUD element's rotation.
Does not affect children. If no center position is given, the element's pivot values are used (default to 0)
Definition
setRotation(float rotation, float centerX, float centerY)
Arguments
floatrotationRotation in radians
floatcenterX[optional] Rotation pivot X position offset from overlay position in screen space
floatcenterY[optional] Rotation pivot Y position offset from overlay position in screen space

setRotationPivot

Description
Set this HUD element's rotation pivot point.
Definition
setRotationPivot(float pivotX, float pivotY)
Arguments
floatpivotXPivot x position offset from element position in screen space
floatpivotYPivot y position offset from element position in screen space

getRotationPivot

Description
Get this HUD element's rotation pivot point.
Definition
getRotationPivot()
Return Values
floatPivotx position offset from element position in screen space
floatPivoty position offset from element position in screen space

getPosition

Description
Get this HUD element's position.
Definition
getPosition()
Return Values
floatXposition in screen space
floatYposition in screen space

setScale

Description
Set this HUD element's scale.
This will move and scale children proportionally.
Definition
setScale(float scaleWidth, float scaleHeight)
Arguments
floatscaleWidthWidth scale factor
floatscaleHeightHeight scale factor

getScale

Description
Get this HUD element's scale.
Definition
getScale()
Return Values
widthscalefactor
heightscalefactor

setAlignment

Description
Set this HUD element's positional alignment.
See Overlay:setAlignment for positioning logic.
Definition
setAlignment(int vertical, int horizontal)
Arguments
intverticalVertical alignment value [Overlay.ALIGN_VERTICAL_BOTTOM | Overlay.ALIGN_VERTICAL_MIDDLE | Overlay.ALIGN_VERTICAL_TOP]
inthorizontalHorizontal alignment value [Overlay.ALIGN_HORIZONTAL_LEFT | Overlay.ALIGN_HORIZONTAL_CENTER | Overlay.ALIGN_HORIZONTAL_RIGHT]

setVisible

Description
Set this HUD element's visibility.
Definition
setVisible()

getVisible

Description
Get this HUD element's visibility.
Definition
getVisible()

getColor

Description
Get this HUD element's color.
Definition
getColor()
Return Values
floatRedvalue
floatGreenvalue
floatBluevalue
floatAlphavalue

getAlpha

Description
Get this HUD element's color alpha value.
Definition
getAlpha()
Return Values
floatAlphavalue

getWidth

Description
Get this HUD element's width in screen space.
Definition
getWidth()

getHeight

Description
Get this HUD element's height in screen space.
Definition
getHeight()

setDimension

Description
Set this HUD element's width and height.
Either value can be omitted (== nil) for no change.
Definition
setDimension()

resetDimensions

Description
Reset this HUD element's dimensions to their default values.
Resets width, height, scale and pivot.
Definition
resetDimensions()

setColor

Description
Set this HUD element overlay's color.
Children are unaffected.
Definition
setColor()

setAlpha

Description
Set this HUD element overlay's color alpha value only.
Definition
setAlpha()

setImage

Description
Set this HUD element overlay's image file.
Definition
setImage()

setUVs

Description
Set this HUD element overlay's UV coordinates.
Definition
setUVs()

update

Description
Update this HUD element's state.
Definition
update()

draw

Description
Draw this HUD element and all of its children in order of addition.
Definition
draw()

scalePixelToScreenVector

Description
Convert a vector from pixel values into scaled screen space values.
Definition
scalePixelToScreenVector(table vector2D)
Arguments
tablevector2DArray of two pixel values

scalePixelToScreenHeight

Description
Convert a vertical pixel value into scaled screen space value.
Definition
scalePixelToScreenHeight(float height)
Arguments
floatheightVertical pixel value

scalePixelToScreenWidth

Description
Convert a horizontal pixel value into scaled screen space value.
Definition
scalePixelToScreenWidth(float width)
Arguments
floatwidthHorizontal pixel value

normalizeUVPivot

Description
Convert a texture space pivot to an element-local pivot.
Definition
normalizeUVPivot(table uvPivot, table uvs)
Arguments
tableuvPivotArray of two pixel pivot coordinates in texture space
tableuvsArray of UV coordinates as {x, y, width, height}

HUDFrameElement

Description
HUD background frame element.
-- Displays a transparent frame with a thick bottom bar for use as a background in HUD elements.
--@category GUI

new

Description
Create a new instance of FrameElement.
Definition
new(string hudAtlasPath, float posX, float posY, float width, float height, table parent)
Arguments
stringhudAtlasPathPath to the HUD atlas texture
floatposXInitial X position in screen space
floatposYInitial Y position in screen space
floatwidthFrame width in screen space
floatheightFrame height in screen space
tableparent[optional] Parent HUDElement which will receive this frame as its child element

createComponents

Description
Create display components.
Definition
createComponents()

setDimension

Description
Set frame element dimensions.
Override from HUDElement to preserve border positioning and sizes.
Definition
setDimension()

HUDPopupMessage

Description
HUD popup message.
-- Displays a modal popup message which requires a player input to be accepted / dismissed or expires after a given
time.
--@category GUI

new

Description
Create a new instance of HUDPopupMessage.
Definition
new(string hudAtlasPath, l10n I18N, inputManager InputBinding, InputDisplayManager InputDisplayManager, IngameMap IngameMap)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
l10nI18Nreference for text localization
inputManagerInputBindingreference for custom input context handling
InputDisplayManagerInputDisplayManagerfor input glyph display
IngameMapIngameMapreference used to notify the map when a message is shown
Return Values
tableHUDPopupMessageinstance

showMessage

Description
Show a new message.
Definition
showMessage(string title, string message, int duration, table controls, function callback, table target)
Arguments
stringtitleTitle text
stringmessageMain message text
intdurationMessage display duration in milliseconds. If set to 0, will cause the message to be
displayed for a duration derived from the message length. If set to <0, will cause the message to be displayed
for a very long time.
tablecontrols[optional] Array of InputHelpElement instance for input hint row display
functioncallback[optional] Function to be called when the message is acknowledged or expires
tabletarget[optional] Callback target which is passed as the first argument to the given callback function

setPaused

Description
Set the game's paused state on this element.
If the game is paused, the message timer is stopped and no new messages are displayed.
Definition
setPaused()

getVisible

Description
Get this HUD element's visibility.
Definition
getVisible()

DisplayElement:getHidingTranslation

Description
Get the screen space translation for hiding.
Override in sub-classes if a different translation is required.
Definition
DisplayElement:getHidingTranslation()
Return Values
floatScreenspace X translation
floatScreenspace Y translation

onMenuVisibilityChange

Description
Handle menu visibility changes.
Definition
onMenuVisibilityChange()

assignCurrentMessage

Description
Assign a new current message and adjust display state accordingly.
This also resizes the message box according to the required space.
Definition
assignCurrentMessage()

getTitleHeight

Description
Get the display height of the current message's title.
Definition
getTitleHeight()

getTextHeight

Description
Get the display height of the current message's text.
Definition
getTextHeight()

getInputRowsHeight

Description
Get the display height of the current message's input rows.
Definition
getInputRowsHeight()

animateHide

Description
Animate this element on showing.
Definition
animateHide()

startMessage

Description
Start displaying a message dequeued from the currently pending messages.
Sets all required display and input state.
Definition
startMessage()

finishMessage

Description
Finish displaying a message after it has either elapsed or been acknowledged by the player.
Resets display and input state and triggers any provided message callback.
Definition
finishMessage()

update

Description
Update this element's state.
Definition
update()

updateCurrentMessage

Description
Update the current message.
Disables this popup when time runs out and dequeues a pending messages for displaying.
Definition
updateCurrentMessage()

updateButtonGlyphs

Description
Update button glyphs when the player input mode has changed.
Definition
updateButtonGlyphs()

setInputActive

Description
Enable / disable input events for message confirmation / skipping.
Definition
setInputActive()

onConfirmMessage

Description
Event function for either InputAction.SKIP_MESSAGE_BOX or InputAction.MENU_ACCEPT.
Definition
onConfirmMessage()

draw

Description
Draw the message.
Definition
draw()

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor

setScale

Description
Set uniform UI scale.
Definition
setScale()

setDimension

Description
Set this HUD element's width and height.
Definition
setDimension()

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()

createBackground

Description
Create the background overlay.
Definition
createBackground()

createComponents

Description
Create required display components.
Definition
createComponents()

createInputRow

Description
Create components for an input button row.
Definition
createInputRow()

HUDTextDisplay

Description
HUD text display.
-- Displays a formatted single-line text with optional animations.
--@category GUI

new

Description
Create a new HUDTextDisplay.
Definition
new(float posX, float posY, float textSize, int textAlignment, table textColor, bool textBool)
Arguments
floatposXScreen space X position of the text display
floatposYScreen space Y position of the text display
floattextSizeText size in reference resolution pixels
inttextAlignmentText alignment as one of RenderText.[ALIGN_LEFT | ALIGN_CENTER | ALIGN_RIGHT]
tabletextColorText display color as an array {r, g, b, a}
booltextBoolIf true, will render the text in bold
Return Values
tableHUDTextDisplayinstance

setText

Description
Set the text to display.
Definition
setText(string text, float textSize, int textAlignment, table textColor, bool textBool)
Arguments
stringtextDisplay text
floattextSizeText size in reference resolution pixels
inttextAlignmentText alignment as one of RenderText.[ALIGN_LEFT | ALIGN_CENTER | ALIGN_RIGHT]
tabletextColorText display color as an array {r, g, b, a}
booltextBoolIf true, will render the text in bold

setScale

Description
Set the text display UI scale.
Definition
setScale()

setVisible

Description
Set this element's visibility.
Definition
setVisible(bool isVisible, bool animate)
Arguments
boolisVisibleVisibility state
boolanimateIf true, will play the currently set animation on becoming visible or and reset it when necessary.

setAlpha

Description
Set the global alpha value for this text display.
The alpha value will be multiplied with any text color alpha channel value.
Definition
setAlpha()

setTextColorChannels

Description
Set the text color by channels.
Use for dynamic changes and animation.
Definition
setTextColorChannels()

setTextShadow

Description
Set the text shadow state.
Definition
setTextShadow(bool isShadowEnabled, table shadowColor)
Arguments
boolisShadowEnabledIf true, will cause a shadow to be rendered under the text
tableshadowColorShadow text color as an array {r, g, b, a}

setAnimation

Description
Set an animation tween (sequence) for this text display.
The animation can be played when calling HUDTextDisplay:setVisible() with the "animate" paramter set to true.
Definition
setAnimation()

update

Description
Update this element's state.
Definition
update()

draw

Description
Draw the text.
Definition
draw()

HusbandryModuleFoodSpillage

Description
Creating manager

delete

Description
Deletes instance
Definition
delete()
Code
29function HusbandryModuleFoodSpillage:delete()
30end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
34function HusbandryModuleFoodSpillage:initDataStructures()
35 HusbandryModuleFoodSpillage:superClass().initDataStructures(self)
36
37 self.spillageAreas = {}
38 self.foodToDrop = 0
39 self.spillageFillType = FillType.UNKNOWN
40 self.lineOffset = 0
41 self.cleanlinessFactor = 0.0
42 self.hasCleanliness = false
43end

load

Description
Loads data from xml
Definition
load(table xmlFile, string xmlKey, table rootNode)
Arguments
tablexmlFilehandle
stringxmlKeyfrom which to read the configuration
tablerootNodeof the husbandry
Return Values
booleantrueif loading was successful else false
Code
51function HusbandryModuleFoodSpillage:load(xmlFile, configKey, rootNode, owner)
52 if not HusbandryModuleFoodSpillage:superClass().load(self, xmlFile, configKey, rootNode, owner) then
53 return false
54 end
55
56 if not hasXMLProperty(xmlFile, configKey) then
57 return false
58 end
59
60 local i = 0
61 while true do
62 local areaKey = string.format("%s.area(%d)", configKey, i)
63 if not hasXMLProperty(xmlFile, areaKey) then
64 break
65 end
66 local start = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, areaKey .. "#startNode"))
67 local width = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, areaKey .. "#widthNode"))
68 local height = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, areaKey .. "#heightNode"))
69
70 if start ~= nil and width ~= nil and height ~= nil then
71 table.insert(self.spillageAreas, {start = start, width = width, height = height})
72 end
73 i = i + 1
74 end
75
76 local spillageFillType = getXMLString(xmlFile, configKey .. "#fillType")
77 if spillageFillType ~= nil then
78 local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(spillageFillType)
79 if fillTypeIndex ~= nil then
80 self.spillageFillType = fillTypeIndex
81 end
82 end
83
84 self.hasCleanliness = true
85
86 return self.spillageFillType ~= nil and #self.spillageAreas > 0
87end

readStream

Description
Reads network stream
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
Code
94function HusbandryModuleFoodSpillage:readStream(streamId, connection)
95 HusbandryModuleFoodSpillage:superClass().readStream(self, streamId, connection)
96
97 if self.hasCleanliness then
98 self.cleanlinessFactor = streamReadUInt8(streamId) / 255
99 end
100end

writeStream

Description
Writes network stream
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
Code
106function HusbandryModuleFoodSpillage:writeStream(streamId, connection)
107 HusbandryModuleFoodSpillage:superClass().writeStream(self, streamId, connection)
108
109 if self.hasCleanliness then
110 local cleanliness = math.floor(self.cleanlinessFactor * 255 + 0.5)
111 streamWriteUInt8(streamId, cleanliness)
112 end
113end

readUpdateStream

Description
Read updates from network stream
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdnetwork stream identification
integertimestamp
tableconnectionconnection information
Code
120function HusbandryModuleFoodSpillage:readUpdateStream(streamId, timestamp, connection)
121 HusbandryModuleFoodSpillage:superClass().readUpdateStream(self, streamId, timestamp, connection)
122
123 if self.hasCleanliness then
124 self.cleanlinessFactor = streamReadUInt8(streamId) / 255
125 end
126end

writeUpdateStream

Description
Write updates from network stream
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
integerdirtyMaskis used to check if we need to update
Code
133function HusbandryModuleFoodSpillage:writeUpdateStream(streamId, connection, dirtyMask)
134 HusbandryModuleFoodSpillage:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
135
136 if self.hasCleanliness then
137 local cleanliness = math.floor(self.cleanlinessFactor * 255 + 0.5)
138 streamWriteUInt8(streamId, cleanliness)
139 end
140end

onIntervalUpdate

Description
Update water usage
Definition
onIntervalUpdate(float dayToInterval)
Arguments
floatdayToInterval
Code
145function HusbandryModuleFoodSpillage:onIntervalUpdate(dayToInterval)
146 HusbandryModuleFoodSpillage:superClass().onIntervalUpdate(self, dayToInterval)
147 self:updateCleanlinessFactor(dayToInterval)
148end

loadFromXMLFile

Description
Loads information from attributes and node. Retrives from xml file information.
Definition
loadFromXMLFile(table xmlFile, string key)
Arguments
tablexmlFileXML file handler
stringkeyXML base key
Code
183function HusbandryModuleFoodSpillage:loadFromXMLFile(xmlFile, key)
184 HusbandryModuleFoodSpillage:superClass().loadFromXMLFile(self, xmlFile, key)
185
186 if self.hasCleanliness then
187 self.cleanlinessFactor = Utils.getNoNil(getXMLFloat(xmlFile, key.."#cleanlinessFactor"), self.cleanlinessFactor)
188 self.foodToDrop = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foodToDrop"), self.foodToDrop)
189 end
190end

updateFoodSpillage

Description
Update spillage mechanics.
Definition
updateFoodSpillage(float spillageDelta)
Arguments
floatspillageDeltaamount of food to increase
Return Values
floatfooddropped
Code
205function HusbandryModuleFoodSpillage:updateFoodSpillage(spillageDelta)
206 local foodDropped = 0
207
208 if self.hasCleanliness and self.cleanlinessFactor > 0 and spillageDelta > g_densityMapHeightManager:getMinValidLiterValue(self.spillageFillType) then
209 local i = math.random(1, #self.spillageAreas)
210 local spillageArea = self.spillageAreas[i]
211 local xs,_,zs = getWorldTranslation(spillageArea.start)
212 local xw,_,zw = getWorldTranslation(spillageArea.width)
213 local xh,_,zh = getWorldTranslation(spillageArea.height)
214 local ux, uz = xw - xs, zw - zs
215 local vx, vz = xh - xs, zh - zs
216 local vLength = MathUtil.vector2Length(vx,vz)
217 local sx = xs + (math.random() * ux) + (math.random() * vx)
218 local sz = zs + (math.random() * uz) + (math.random() * vz)
219 local ex = xs + (math.random() * ux) + (math.random() * vx)
220 local ez = zs + (math.random() * uz) + (math.random() * vz)
221 local sy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, sx, 0.0, sz)
222 local ey = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, ex, 0.0, ez)
223 local dropped, lineOffset = DensityMapHeightUtil.tipToGroundAroundLine(nil, spillageDelta, self.spillageFillType, sx,sy,sz, ex,ey,ez, 0, vLength, self.lineOffset, false, nil)
224
225 foodDropped = dropped
226 self.lineOffset = lineOffset
227 end
228
229 return foodDropped
230end

getFoodSpillageLevel

Description
Get spillage level
Definition
getFoodSpillageLevel()
Return Values
floatspillagetotal
Code
235function HusbandryModuleFoodSpillage:getFoodSpillageLevel()
236 local totalLevel = 0
237 for _, spillageArea in ipairs(self.spillageAreas) do
238 local xs,_,zs = getWorldTranslation(spillageArea.start)
239 local xw,_,zw = getWorldTranslation(spillageArea.width)
240 local xh,_,zh = getWorldTranslation(spillageArea.height)
241 local fillLevel = DensityMapHeightUtil.getFillLevelAtArea(self.spillageFillType, xs, zs, xw, zw, xh, zh)
242 totalLevel = totalLevel + fillLevel
243 end
244 return totalLevel
245end

getSpillageFactor

Description
Definition
getSpillageFactor()
Code
249function HusbandryModuleFoodSpillage:getSpillageFactor()
250 if self.hasCleanliness then
251 return self.cleanlinessFactor
252 end
253
254 return nil
255end

I3DUtil

Description
Sets the world direction for a given object

checkChildIndex

Description
Checks if given index is valid
Definition
checkChildIndex(integer node, string index)
Arguments
integernodeid of an object
stringindexindex
Return Values
booleanisActivateableis activateable
booleanisValidtrue if index is valid else false

indexToObject

Description
Returns index of object
Definition
indexToObject(table components, string index, table mappings)
Arguments
tablecomponentscomponents (also (integer) id of root node possible)
stringindexindex
tablemappingsid to index mapping table
Return Values
tableinstanceinstance of object
integeridid of object
integeridid of used root node

setNumberShaderByValue

Description
Sets the number shader attributes
Definition
setNumberShaderByValue(integer numbers, float value, integer precision, boolean showZero)
Arguments
integernumbersid of the node containing the number shapes
floatvaluevalue
integerprecisionprecision
booleanshowZerotrue if zero should be shown
Return Values
tableselfreturns the instance

wakeUpObject

Description
Wake up a collision object
Definition
wakeUpObject(integer node)
Arguments
integernodeid of a collision object
Return Values
boolreturntrue if successful

setWorldDirection

Description
limitedAxis 3: 0 degree = x axis, 90 degree = y axis
Definition
setWorldDirection(integer node, float dirX, float dirY, float dirZ, float upX, float upY, float upZ, integer limitedAxis, float minRot, float maxRot)
Arguments
integernodeid of object
floatdirXdirX
floatdirYdirY
floatdirZdirZ
floatupXupX
floatupYupY
floatupZupZ
integerlimitedAxisindex of limited axis
floatminRotminRot
floatmaxRotmaxRot
Return Values
floatreturnsthe change delta

setDirection

Description
Sets direction for a given object (only if the direction is valid)
Definition
setDirection(integer node, float dirX, float dirY, float dirZ, float upX, float upY, float upZ)
Arguments
integernodeid of object
floatdirXdirX
floatdirYdirY
floatdirZdirZ
floatupXupX
floatupYupY
floatupZupZ
Return Values
tableselfreturns the instance

setShaderParameterRec

Description
Sets a shader parameter recursivly
Definition
setShaderParameterRec(integer node, string shaderParam, float x, float y, float z, float w)
Arguments
integernodeid of the top node
stringshaderParamthe name of the shader param
floatxx
floatyy
floatzz
floatww
Return Values
boolreturntrue if successful

getNodesByShaderParam

Description
Gets a list of nodes with shaderParam assigned to it
Definition
getNodesByShaderParam(integer node, string shaderParam, table nodes)
Arguments
integernodeid of the top node
stringshaderParamthe name of the shader param
tablenodesa list of nodes
Return Values

IndexChangeSubjectMixin

Description
Index change subject mixin.
-- Add this mixin to a GuiElement to implement an observer pattern for index changes (e.g. paging, options, lists).
-- Added methods:
GuiElement:addIndexChangeObserver(observer, indexChangeCallback): Register an observer to be notified on index changes
observer is passed to the index change callback as the first argument, typically you would use "self"
indexChangeCallback must be a function with the signature function(observer, index, count)
GuiElement:notifyIndexChange(index, count): Called by the decorated GuiElement when the index or number of indexed items changes, triggers callbacks
index is the new index after the current change
count is the number of indexed items which may or may not have changed
--@category GUI

addTo

Description
See GuiMixin:addTo().
Definition
addTo()

addIndexChangeObserver

Description
Add an index change observer with a callback.
Definition
addIndexChangeObserver(GuiElement Decorated, observer Observer, indexChangeCallback Function(observer,)
Arguments
GuiElementDecoratedGuiElement instance which has received this method
observerObserverobject instance
indexChangeCallbackFunction(observer,index, count), where index is the new index and count the current number of indexable items

notifyIndexChange

Description
Notify observers of an index change.
Definition
notifyIndexChange(GuiElement Decorated, index New, count Indexable)
Arguments
GuiElementDecoratedGuiElement instance which has received this method
indexNewindex
countIndexableitem count

clone

Description
Clone this mixin's state from a source to a destination GuiElement instance.
Definition
clone()

IndexStateElement

Description
Index state display element.
-- Displays a visual element per screen page to let the player see an indication of their current list, page or multi-
option selection index. The element points at a UI element which supports indexed access, such as ListElement,
PageElement or MultiTextOption. For other cases, UI views directly manipulate the states (e.g. cycling hints in the
loading screen).
--@category GUI
--@xmlConfig GuiElement#stateElementTemplateId string ID of a descendant, sibling or sibling's descendant GUI element which is duplicated per page. The element should be configured to have different visuals for normal and selected GuiOverlay states (layers).

locateStateElementTemplate

Description
Find and store the state element template which is configured in #stateElementTemplateId.
The function searches from this elements parent downwards, so any descendant of this element or its siblings may
contain the state element template.
Definition
locateStateElementTemplate()

locateIndexableElement

Description
Find and store the indexable element which is configured in #indexableElementId.
The function first locates the current view root (if possible) and then searches downwards. The search is broader
than locateStateElementTemplate() to allow more flexibility in UI design and configuration.
Definition
locateIndexableElement()

onIndexChange

Description
Event handler for index changes.
Definition
onIndexChange(index New, count (New))
Arguments
indexNewindex
count(New)item count

setPageCount

Description
Set the page count.
Clears current page elements and rebuilds as many as needed from the configured template.
Definition
setPageCount(count Number, initialIndex [optional])
Arguments
countNumberof page indicators to display
initialIndex[optional]Page index to set after rebuilding

setPageIndex

Description
Set the current page index and update display states.
Definition
setPageIndex(index New)
Arguments
indexNewpage index

IngameMap

Description
In-game map display element.
-- This class is used to display the game map both in the HUD as well as in the in-game menu.
--@category GUI

new

Description
Create a new instance of IngameMap.
Definition
new(string hudAtlasPath, table inputDisplayManager)
Arguments
stringhudAtlasPathPath to the HUD atlas texture
tableinputDisplayManagerInputDisplayManager reference

delete

Description
Delete this element and all of its components.
Definition
delete()

setFullscreen

Description
Set full-screen mode (for map overview) without affecting the mini-map state.
Definition
setFullscreen()

getHotspotIndex

Description
Get the index of a hotspot in the hotspots list.
Definition
getHotspotIndex()

cycleVisibleHotspot

Description
Get the next or previous visible hotspot in order from a current hotspot.
Definition
cycleVisibleHotspot(table currentHotspot, table categoriesHash, int direction)
Arguments
tablecurrentHotspotCurrently selected hotspot
tablecategoriesHashTable of valid hotspot categories to cycle, keys are categories
intdirection1 for next, -1 for previous

getHeight

Description
Override from HUDElement.
Return zero height when turned off, because the map is only invisible.
Definition
getHeight()

getRequiredHeight

Description
Get required display height on screen including all auxiliary elements and texts.
Definition
getRequiredHeight()

setSize

Description
Set the map size.
Definition
setSize(float width, float height)
Arguments
floatwidthWidth of the map in screen space
floatheightHeight of the map in screen space

setPosition

Description
Set the map's position.
This sets the actual map display's position to the given values. This elements background is offset accordingly.
Definition
setPosition(float posX, float posY)
Arguments
floatposXNew map X position in screen space
floatposYNew map Y position in screen space

setIsVisible

Description
Set the map's visibility (= active state).
Definition
setIsVisible()

onToggleMapSize

Description
Called when the input for map size toggle is pressed and then released.
Definition
onToggleMapSize()

registerInput

Description
Register map size toggle input event.
Definition
registerInput()

update

Description
Update the map's state.
Definition
update()

updatePlayerPosition

Description
Update the data about the player's current position.
Definition
updatePlayerPosition()

updatePlayerArrow

Description
Update the arrow indicating the player's current position.
Definition
updatePlayerArrow()

updateMapHeightZoomFactor

Description
Update map zoom and visibility state.
Definition
updateMapHeightZoomFactor()
Return Values
boolTrueif the left border of the map has been reached
boolTrueif the right border of the map has been reached
boolTrueif the top border of the map has been reached
boolTrueif the bottom border of the map has been reached

updateInputGlyphs

Description
Update input display glyphs with the current input context.
Definition
updateInputGlyphs()

updateMapUVs

Description
Update map overlay UVs based on the currently focused position, e.g. a player or hotspot.
Definition
updateMapUVs()
Return Values
booleantrueif loading was successful else false
boolTrueif the left border of the map has been reached
boolTrueif the right border of the map has been reached
boolTrueif the top border of the map has been reached
boolTrueif the bottom border of the map has been reached

draw

Description
Draw the map as hud element
Definition
draw()
Return Values
booleantrueif loading was successful else false

drawPlayerArrow

Description
Draw the current player's arrow.
Definition
drawPlayerArrow()
Return Values
tableachievementachievement object

drawMapLabel

Description
Draw the map label on top of the map display.
Definition
drawMapLabel()
Return Values
tableinstanceinstance of object

drawMap

Description
Draw the map.
Definition
drawMap(float alpha, bool isStandalone)
Arguments
floatalpha[optional] Map opacity value
boolisStandalone[optional] If true, will draw the map border and other elements.
Return Values
booleantrueif loading was successful else false

drawPointsOfInterest

Description
Draw map hotspot and arrow elements.
Definition
drawPointsOfInterest()
Return Values
booleantrueif loading was successful else false

drawOtherPlayerArrows

Description
Draw arrows for other players' positions.
Definition
drawOtherPlayerArrows()
Return Values
booleantrueif added successful else false

drawEnterableArrows

Description
Draw arrows for enterable vehicles controlled by players.
Definition
drawEnterableArrows()
Return Values
tablehelpera random helper object

renderHotspots

Description
Draw all known hotspots on the map.
Definition
renderHotspots()
Return Values
integerhelperIndexa random helper index

drawHotspot

Description
Draw a single hotspot on the map.
Definition
drawHotspot()
Return Values
tablehelperthe helper object

drawPlayersCoordinates

Description
Draw the player's current coordinates as text.
Definition
drawPlayersCoordinates()
Return Values
tablehelperthe helper object

drawLatencyToServer

Description
Draw current latency to server as text.
Definition
drawLatencyToServer()
Return Values
booleansuccesstrue if helper is marked else false

setScale

Description
Set this element's scale.
Definition
setScale(float uiScale)
Arguments
floatuiScaleCurrent UI scale applied to both width and height of elements
Return Values
integernumOfHelperstotal number of helpers

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Return Values
tableinstanceinstance of object

getBackgroundPosition

Description
Get the base position of the entire element.
Definition
getBackgroundPosition()
Return Values
booleantrueif loading was successful else false

createBackground

Description
Create the empty background overlay.
Definition
createBackground()
Return Values
booleantrueif loading was successful else false

createComponents

Description
Create required display components.
Definition
createComponents(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
Return Values
booleantrueif loading was successful else false

createFrame

Description
Create the map frame.
Definition
createFrame()
Return Values
booleantrueif added successful else false

createToggleMapSizeGlyph

Description
Create the input glyph for map size toggling.
Definition
createToggleMapSizeGlyph()
Return Values
tablenpca random npc object

createPlayerMapArrow

Description
Create the map arrow for the player's position.
Definition
createPlayerMapArrow()
Return Values
integernpcIndexa random npc index

createOtherMapArrowOverlay

Description
Create an arrow overlay used for other player's and their vehicles in multiplayer.
Definition
createOtherMapArrowOverlay()
Return Values
tablenpcthe npc object

IngameMapElement

Description
In-game map element.
-- Controls input on the map in the in-game menu with objectives, vehicles, etc. The actual map rendering is deferred to
the map component of the current mission. The map reference and terrain size must be set during mission
initialization via the setIngameMap() and setTerrainSize() methods.
--@category GUI
--@xmlConfig GuiElement#cursorId string ID of element to use as a cursor on the map.

addCursorDeadzone

Description
Add a dead zone wherein the map will not react to cursor inputs.
Used this to designate areas where other controls should receive cursor input which would otherwise be used up by
the map (e.g. in full-screen mode in the map overview screen in-game). The deadzones will also restrict cursor
movement.
Definition
addCursorDeadzone()

clearCursorDeadzones

Description
Clear cursor dead zones.
Definition
clearCursorDeadzones()

isCursorInDeadzones

Description
Check if a cursor position is within one of the stored deadzones.
Definition
isCursorInDeadzones()

mouseEvent

Description
Custom mouse event handling for the in-game map.
Directly handles zoom, click and drag events on the map. See input events and IngameMapElement:checkAndResetMouse()
for the state checking code required to bypass player mouse input bindings.
Definition
mouseEvent()

updateBaseMapValues

Description
Update base map element values for displaying as an embedded UI element.
Definition
updateBaseMapValues()

setIngameMap

Description
Set the IngameMap reference to use for display.
Definition
setIngameMap()

setTerrainSize

Description
Set the current map's terrain size for map display.
Definition
setTerrainSize()

registerActionEvents

Description
Register non-GUI input action events.
Definition
registerActionEvents()

removeActionEvents

Description
Remove non-GUI input action events.
Definition
removeActionEvents()

onHorizontalCursorInput

Description
Event function for horizontal cursor input bound to InputAction.AXIS_LOOK_LEFTRIGHT_VEHICLE.
Definition
onHorizontalCursorInput()

onVerticalCursorInput

Description
Event function for vertical cursor input bound to InputAction.AXIS_LOOK_UPDOWN_VEHICLE.
Definition
onVerticalCursorInput()

onAccept

Description
Event function for gamepad cursor accept input bound to InputAction.INGAMEMAP_ACCEPT.
Definition
onAccept()

onZoomInput

Description
Event function for map zoom input bound to InputAction.AXIS_ACCELERATE_VEHICLE and InputAction.AXIS_BRAKE_VEHICLE.
Definition
onZoomInput(inputValue Zoom, direction Zoom)
Arguments
inputValueZoominput value
directionZoominput sign value, 1 for zoom in, -1 for zoom out

checkAndResetMouse

Description
Check if mouse input was active before a bound input was triggered and queue a reset of the mouse state for the next
frame.
Mouse input continuously sets the mouse input flag (self.useMouse) but does not receive any events when the mouse
is inert. Therefore we need to set and reset the state each frame to make sure we can seamlessly switch between mouse
and gamepad input on the map element while at the same time preventing any player bindings from interfering with the
custom mouse input logic of this class.
Definition
checkAndResetMouse()

InGameMenu

Description
In-Game Menu.
-- Displays the main in-game menu with several pages, depending on the game state and mode (e.g. tutorial or
multiplayer). This menu can be extended and modified by adding and removing pages. Default pages for the base game
are always loaded but can also be removed (effectively just disabled). Custom pages can be entirely new or modified
sub-classes of the default pages. See methods InGameMenu:addPage() and InGameMenu:removePage() for details.
--@category GUI
-- @field header Header panel

new

Description
Create a new instance of InGameMenu.
Definition
new(table target, table custom_mt, table messageCenter, table l10n, table savegameController, table inputManager, table fruitTypeManager, table fillTypeManager, table storeManager, table shopController, table shopConfigScreen, table placementScreen, bool isConsoleVersion)
Arguments
tabletargetCallback target
tablecustom_mtSub-class meta table
tablemessageCenterMessageCenter reference
tablel10nI18N reference for text localization
tablesavegameControllerSavegameController reference for savegame persistence
tableinputManagerInputBinding reference
tablefruitTypeManagerFruitTypeManager reference for fruit type information access
tablefillTypeManagerFillTypeManager reference for fill type information access
tablestoreManagerStoreManager reference
tableshopControllerShopController reference
tableshopConfigScreenShopConfigScreen reference
tableplacementScreenPlacementScreen reference
boolisConsoleVersionIf true, the game is running on a console
Return Values
tableinstanceinstance of object

setMode

Description
Set the menu mode.
Switches the menu between pause menu mode or shop mode.
Definition
setMode(int menuMode)
Arguments
intmenuModeOne of [InGameMenu.MODE_MENU | InGameMenu.MODE_SHOP]
Return Values
tableinstanceinstance of object

setInGameMap

Description
Set the in-game map component to use by pages.
Definition
setInGameMap()
Return Values
tablebrandColorbrandColor object

setTerrainSize

Description
Set the current terrain size to use by pages.
Definition
setTerrainSize()
Return Values
tablefarmhouseor nil

setMissionFruitTypes

Description
Set the known fruit types when loaded for the mission.
Definition
setMissionFruitTypes()
Return Values
integerspawnpointnode or the career spawnpoint node.

setSellingStations

Description
Set the current list of selling stations for displaying.
Definition
setSellingStations()
Return Values
integerCameraor 0 if no farmhouse.

setAccessibleVehicles

Description
Set the current list of accessible vehicles for displaying.
Definition
setAccessibleVehicles()
Return Values
boolTrueif the user is a manager of this farm, false otherwise

setBanStorage

Description
Set the reference to the ban storage.
Definition
setBanStorage()
Return Values
tablePermissionhash table {permission=<hasPermission>}

setConnectedUsers

Description
Set the current list of connected users for displaying.
Definition
setConnectedUsers()
Return Values
floatAccountbalance

setClient

Description
Set the network client reference.
Definition
setClient()
Return Values
float

setServer

Description
Set the network server reference.
Definition
setServer()
Return Values
tableinstanceinstance of object

updateHasMasterRights

Description
Update master rights status.
Definition
updateHasMasterRights()
Return Values
booleantrueif loading was successful else false

updateGarageItems

Description
Update garage items display data.
Definition
updateGarageItems()
Return Values
booleantrueif loading was successful else false

onLoadMapFinished

Description
Called when the mission is fully loaded.
Used for late initialization of UI components which rely on mission information.
Definition
onLoadMapFinished()
Return Values
tabledataData for the menu

initializePausePages

Description
Initialize pages for the pause mode.
Definition
initializePausePages()
Return Values
tableinstanceInstance of object

initializeShopPages

Description
Initialize pages for the shop mode.
Definition
initializeShopPages()
Return Values
booleantrueif loading was successful else false

setupMenuPages

Description
Set up displayed menu pages and their tabs.
Definition
setupMenuPages()
Return Values
tableinstanceinstance of object

setupMenuButtonInfo

Description
Define default properties and retrieval collections for menu buttons.
Definition
setupMenuButtonInfo()
Return Values
booleantrueif loading was successful else false

addPageTab

Description
Add a page tab in the menu header.
Call this synchronously with InGameMenu:registerPage() to ensure a correct order of pages and tabs.
Definition
addPageTab()
Return Values
fruittypeindex to be planted

setPageTabEnabled

Description
Set enabled state of a page tab in the header.
Definition
setPageTabEnabled()
Return Values
floatsprayFactorthe spray factor of the given field

rebuildTabList

Description
Rebuild page tab list in order.
Definition
rebuildTabList()
Return Values
floatplowFactorthe plow factor of the given field

setEnvironment

Description
Set environment reference on loading.
Definition
setEnvironment()
Return Values
floatplowFactorthe lime factor of the given field

setMissionInfo

Description
Set mission info data on loading.
Definition
setMissionInfo()
Return Values
floatplowFactorthe weed factor of the given field

setPlayerFarm

Description
Set the player's current farm reference.
Definition
setPlayerFarm()
Return Values
floatareaarea found
floattotalAreatotal area checked

setPlayer

Description
Set the reference to the current player.
Definition
setPlayer()

setCurrentUserId

Description
Set the current user ID.
Definition
setCurrentUserId()
Return Values
tableinstanceinstance of object

setManureTriggers

Description
Set manure triggers of the current map/mission.
Definition
setManureTriggers()
Return Values
booleantrueif loading was successful else false

setHusbandries

Description
Set the reference to the current husbandries collection.
Definition
setHusbandries()
Return Values
booleantrueif loading was successful else false

leaveCurrentGame

Description
Reset menu state and go back to the main menu.
Definition
leaveCurrentGame()
Return Values
Listofvehicles. Each element is a table with filanema and configuration properties.
Reward

exitMenu

Description
Exit the menu if allowed.
Definition
exitMenu()

exitMenuFromConfig

Description
Exit the menu from the shop configuration screen.
Definition
exitMenuFromConfig()

reset

Description
Reset menu state (and all pages).
Definition
reset()
Return Values
floatmultiplierharvest multiplier

onOpen

Description
Handle in-game menu opening event.
Definition
onOpen()
Return Values
tableinstanceof the doghouse

onClose

Description
Handle in-game menu closing event.
Definition
onClose()
Return Values
stringVehicledisplay name

onButtonSaveGame

Description
Button function for saving the game.
Definition
onButtonSaveGame()
Return Values
mixedvalueValue of the setting. The type depends on the setting

onButtonBack

Description
Button function for backing out of the menu.
Definition
onButtonBack()
Return Values
booleansuccessfulReturns true, if the setting was changed

onButtonQuit

Description
Button function for quitting the game to the main menu.
Definition
onButtonQuit()
Return Values
tableinstanceinstance of object

onButtonGarage

Description
Button function for switching to the garage view.
Definition
onButtonGarage()
Return Values
tableselfinstance

onButtonShop

Description
Button function for switching to the shop view from the garage.
Definition
onButtonShop()
Return Values
Trueifthe element and all of its children could be set up with the given values, false otherwise.

onButtonRepair

Description
Button function for repairing an owned vehicle in the garage.
Definition
onButtonRepair()
Return Values
Trueifthe input event has been consumed, false otherwise

onYesNoRepairDialog

Description
Handle confirmation of vehicle repairing.
Definition
onYesNoRepairDialog()
Return Values
Closestpointx, y

onVehicleRepairEvent

Description
Handle a local vehicle repaired event.
Updates the garage view buttons if currently viewing the repaired vehicle.
Definition
onVehicleRepairEvent()
Return Values
NextGUIelement in given direction which can be linked, actual scanning direction used (may change in wrap around scenarios)

onButtonAcceptItem

Description
Button function for explicit clicking of item details action buttons.
Definition
onButtonAcceptItem()
Return Values
Focus

onButtonSwitchOwnedLeased

Description
Button function for switching owned / leased items in the garage.
Definition
onButtonSwitchOwnedLeased()
Return Values
Trueiffocus has changed, false otherwise

startPlacementMode

Description
Enter placement mode.
Definition
startPlacementMode()
Return Values
Trueifnavigation in given direction is locked

startSavingGameDisplay

Description
Enter saving mode.
Definition
startSavingGameDisplay()
Return Values
RootGuiElementinstance of loaded view or nil if the definition XML file could not be loaded.

updatePages

Description
Update page enabled states.
Definition
updatePages()
Return Values
ClonedFrameElementinstance or frameRefElement if resolution failed.

updatePageTabDisplay

Description
Update page tabs display after any page changes.
Definition
updatePageTabDisplay()
Return Values
RootGuiElementof screen or nil if the name did not match any known screen.

clearMenuButtonActions

Description
Clear menu button actions, events and callbacks.
Definition
clearMenuButtonActions()
Return Values
RootGuiElementof dialog or nil if the name did not match any known dialog.

assignMenuButtonInfo

Description
Assign menu button information to the in-game menu buttons.
Definition
assignMenuButtonInfo()
Return Values
Trueifany control has consumed the action event

setPageSelectorTitles

Description
Get page titles from currently visible pages and apply to the selector element.
Definition
setPageSelectorTitles()
Return Values
tableScreenElementdescendant instance of the given class or nil if no such instance was registered

setShopDetailMode

Description
Switch to or from shop detail mode.
This can switch to a category's item list, the owned object or leased object overview by passing in the corresponding
detail page.
Definition
setShopDetailMode()
Return Values
tableRootGuiElement instance of target screen

update

Description
Update the menu state each frame.
This uses a state machine approach for the game saving process.
Definition
update()
Return Values
tableTheGuiElement instance given in the guiElement parameter

openFinancesScreen

Description
Directly switch to the finances screen.
Definition
openFinancesScreen()
Return Values
New

openFarmsScreen

Description
Directly switch to the farms screen.
Definition
openFarmsScreen()
Return Values
tablewith added image data

setMasterServerConnectionFailed

Description
Notify the menu that the master server could not be connected to.
Definition
setMasterServerConnectionFailed()
Return Values
Coloras{red, green, blue, alpha} with all values in the range of [0, 1]

setMasterUserLocal

Description
Set the menu state to master user.
Called by the mission if the current player is a master user.
Definition
setMasterUserLocal()
Return Values
UVcoordinatesas {u1, v1, u2, v2, u3, v3, u4x, v4} with all values in the range of [0, 1]

showConfigurationScreen

Description
Show the vehicle configuration screen for a given store item.
Definition
showConfigurationScreen()
Return Values
NewGuiProfileinstance

inputEvent

Description
Custom input handling to check shop toggle button when in shop mode.
Definition
inputEvent()
Return Values
Trueifprofile values could be loaded, false otherwise.

onMenuActionClick

Description
Handle a menu action click by calling one of the menu button callbacks.
Definition
onMenuActionClick()
Return Values
intCameranode ID (view point, child of camera base node)
intCamerabase node ID (view target, parent of camera node)
boolTrueif no callback was present and no action was taken, false otherwise

onClickOk

Description
Handle menu confirmation input event.
Definition
onClickOk()

onClickBack

Description
Handle menu back input event.
Definition
onClickBack()
Return Values
CameraXworld space position
CameraZworld space position
CameraYrotation in radians

onClickCancel

Description
Handle menu cancel input event.
Bound to quite the game to the main menu.
Definition
onClickCancel()

onClickActivate

Description
Handle menu active input event.
Bound to save the game.
Definition
onClickActivate()

onMoneyChanged

Description
Handle a balance change in game.
Definition
onMoneyChanged()

onSlotUsageChanged

Description
Handle a change of the current slot usage.
Definition
onSlotUsageChanged()
Return Values
xdirectionmovement [-1, 1]
Zdirectionmovement [-1, 1]

onSelectItemBuyDetail

Description
Handle selection of a detail item element when in buy mode.
Definition
onSelectItemBuyDetail()

onSelectItemSellDetail

Description
Handle selection of a detail item element in the garage.
Definition
onSelectItemSellDetail()
Return Values
arrayofnormalized values

onYesNoRestartTutorial

Description
Handle tutorial restart confirmation dialog response.
Definition
onYesNoRestartTutorial()
Return Values
arrayofthe 2 converted values as numbers: {value1, value2}

onYesNoEnd

Description
Server end game confirmation dialog response callback.
Definition
onYesNoEnd()
Return Values
arrayofthe 4 converted values as numbers: {value1, value2, value3, value4}

onClickPageSelection

Description
Handle activation of page selection.
Definition
onClickPageSelection()
Return Values
arrayofthe 4 converted values as numbers: {red, green, blue, alpha}

onPagePrevious

Description
Handle previous page event.
Definition
onPagePrevious()
Return Values
arrayofthe UV coordinates as {u1, v1, u2, v2, u3, v3, u4, v4}

onPageNext

Description
Handle next page event.
Definition
onPageNext()
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

onPageChange

Description
Handle changing to another menu page.
Definition
onPageChange()
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

updateButtonsPanel

Description
Update the buttons panel when a given page is visible.
Definition
updateButtonsPanel()
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

getPageButtonInfo

Description
Get button actions and display information for a given menu page.
Definition
getPageButtonInfo()
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

onPageUpdate

Description
Handle a page being disabled.
Definition
onPageUpdate()
Return Values
arrayofdisplay information, {i={colors={true=[{r,g,b,a} colorblind], false=[{r,g,b,a} default], iconFilename=path,
iconUVs={u1, v1, u2, v2, u3, v3, u4, v4}, description=text, fruitTypeIndex=index}}

onConnectionFailedDialogClick

Description
Handle saving game confirmation when losing master server connection.
Definition
onConnectionFailedDialogClick()
Return Values
arrayofdisplay information, {i={colors={true={i={r,g,b,a}}, false={i={r,g,b,a}}}, description=text}}

onVehiclesChanged

Description
Called from the mission controller when vehicles are modified.
Definition
onVehiclesChanged()
Return Values
arrayofdisplay information, {i={colors={true={i={r,g,b,a}}, false={i={r,g,b,a}}}, description=text}}

onClickBrand

Description
Handle clicking on a brand in shop mode.
Definition
onClickBrand()
Return Values
floatXposition in screen space
floatYposition in screen space

onClickItemCategory

Description
Handle clicking on an item category in shop mode.
Definition
onClickItemCategory()

notifyValidateSavegameList

Description
Notify the player when validating the savegame list.
Will prompt to select a storage device or inform that the chosen device has no more space available.
Definition
notifyValidateSavegameList()
Return Values
floatWidthscale factor
floatHeightscale factor

notifyStartSaving

Description
Notify the player that the game is saving, block input via dialog until the operation finishes.
Definition
notifyStartSaving()

notifySaveComplete

Description
Notify the menu when a save completes successfully so we can set the saving state flag.
Definition
notifySaveComplete()
Return Values
tableSettingsModelinstance

notifySavegameNotSaved

Description
Notify the player that the savegame could not be saved.
Definition
notifySavegameNotSaved()
Return Values
tableCurrentlyactive (changed) settings value

notifyOverwriteSavegame

Description
Prompt the player to confirm overwriting an existing savegame.
Definition
notifyOverwriteSavegame()
Return Values
boolTrueif any setting has been changed, false otherwise

notifySaveFailedNoSpace

Description
Notify the player that saving failed because the current device has no more space, ask to select another device.
Definition
notifySaveFailedNoSpace()
Return Values
boolTrueif any setting has been changed, false otherwise

registerPage

Description
Register a page frame element in the menu.
This does not add the page to the paging component of the menu.
Definition
registerPage(table pageFrameElement, int position, function enablingPredicateFunction)
Arguments
tablepageFrameElementPage FrameElement instance
intposition[optional] Page position index in menu
functionenablingPredicateFunction[optional] A function which returns the current enabling state of the page
at any time. If the function returns true, the page should be enabled. If no argument is given, the page is
always enabled.
Return Values
boolTrueif no callback was present and no action was taken, false otherwise

unregisterPage

Description
Unregister a page frame element identified by class from the menu.
This does not remove the page from the paging component of the menu or the corresponding page tab from the header.
Definition
unregisterPage(table pageFrameClass)
Arguments
tablepageFrameClassFrameElement descendant class of a page which was previously registered
Return Values
boolTrueif there was a page of the given class and it was unregistered
tableUnregisteredpage controller instance or nil
tableUnregisteredpage root GuiElement instance or nil
tableUnregisteredpage tab ListElement instance of nil
boolTrueif there was a page of the given class and it was unregistered
tableUnregisteredpage controller instance or nil
tableUnregisteredpage root GuiElement instance or nil
tableUnregisteredpage tab ListElement instance of nil

addPage

Description
Add a page frame to be displayed in the menu at runtime.
The page will be part of the in-game menu until restarting the game or removing the page again.
-- @usage
local frameController = CustomFrameElement:new(...) -- create controller instance
g_gui:loadGui("<frame layout XML path>", "<frame name>", frameController, true) -- load UI components, attach controller
local enablePage = function() -- define predicate function which returns true when the page should be enabled
return self.example.isSkyBlue
end
self:addPage(frameController, position, enablePage) -- add page to menu (self)
-- @param table pageFrameElement FrameElement instance which is used as a page.
Definition
addPage(int position, string tabIconFilename, table tabIconUVs, function enablingPredicateFunction)
Arguments
intpositionPosition index of added page, starting from left at 1 going to right.
stringtabIconFilenamePath to the texture file which contains the icon for the page tab in the header
tabletabIconUVsUV array for the tab icon. Format: {x, y, width, height} in pixels on the texture.
functionenablingPredicateFunction[optional] A function which returns the current enabling state of the page
at any time. If the function returns true, the page should be enabled. If no argument is given, the page is
always enabled.

removePage

Description
Remove a page from the menu at runtime by its class type.
The removed page is also deleted, including all of its children. Note that this method removes the page for an entire
game run, because the UI is loaded on game start. If you only need to disable a page, use InGameMenu:setPageEnabled()
instead.
-- The method will not remove game default pages, but only disable them.
-- @usage
self:removePage(CustomFrameElement) -- where CustomFrameElement is a sub-class of FrameElement
-- @param table pageFrameClass Class table of a FrameElement sub-class
Definition
removePage()

setPageEnabled

Description
Set the enabled state of a page identified by its controller class type.
This will also set the controller's state, so it can react to being enabled/disabled. The setting will persist
through calls to InGameMenu:reset() and must be reverted manually, if necessary.
Definition
setPageEnabled(table pageFrameClass, bool isEnabled)
Arguments
tablepageFrameClassClass table of a FrameElement sub-class
boolisEnabledTrue for enabled, false for disabled

updateGarageButtonInfo

Description
Update the button information for the garage.
Definition
updateGarageButtonInfo()
Return Values
{name="internalName",displayName="displayName",inputTexts={1=text1, 2=text2, ...}, inputBindings={1=binding1, 2=binding2, ...}, positiveInput=[true|false]}

makeSelfCallback

Description
Make a callback which encloses the self reference and handles arbitrary arguments afterwards.
Definition
makeSelfCallback()
Return Values
ListofDisplayActionBinding instances

InGameMenuAnimalsFrame

Description
In-game menu animals statistics frame.
-- Displays information for all owned animal pens and horses.
--@category GUI

new

Description
Create a new InGameMenuAnimalsFrame instance.
Definition
new(table subclass_mt, table messageCenter, table l10n, table animalManager, table animalFoodManager, table fillTypeManager)
Arguments
tablesubclass_mt[optional] Meta table of subclass
tablemessageCenterMessageCenter reference for local message subscriptions
tablel10nI18N reference for localization
tableanimalManagerAnimalManager reference for animal type and information resolution
tableanimalFoodManagerAnimalFoodManager reference for food mixture information
tablefillTypeManagerFillTypeManager reference for fill type resolution
Return Values
Display
tableInGameMenuAnimalsFrameinstance

initialize

Description
Late initialization.
Definition
initialize()
Return Values
Trueifthe controller starts listening for input, false otherwise (also if it is already listening!)

setHusbandries

Description
Set the reference to the husbandries collection.
The husbandries are defined as {<husbandry ID> = AnimalHusbandry}
Definition
setHusbandries()
Return Values
boolTrueif an actual binding was deleted, false otherwise

buildLivestockListItem

Description
Build a livestock list item for a husbandry.
Definition
buildLivestockListItem()
Return Values
Trueifa binding change was made, false otherwise

buildHorseListItems

Description
Build animal list items for all horses in a horse husbandry.
Definition
buildHorseListItems()
Return Values
Trueifa binding change was made, false otherwise

rebuildAnimalList

Description
Rebuild the animal list from husbandry data.
Definition
rebuildAnimalList()
Return Values
Trueifa binding change was made, false otherwise

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
Trueifbinding has been assigned; reference to first colliding binding or nil

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableDirectSellDialoginstance

setStatusBarValue

Description
Modify a status bar's value, applying the correct size and color as needed.
Definition
setStatusBarValue(table statusBarElement, float value, float startOffset, table profiles, float overrideStatusValue)
Arguments
tablestatusBarElementBitmapElement instance which receives a new size and profile depending on the value
floatvalueFractional value in the range of [0, 1]
floatstartOffsetStart offset value in the range of [0, 1], value will be displayed from there on until 1.
tableprofilesLarge or small status bar profile table, either InGameMenuAnimalsFrame.PROFILE.STATUS_BAR_LARGE or InGameMenuAnimalsFrame.PROFILE.STATUS_BAR_SMALL
floatoverrideStatusValue[optional] If provided, tests this value against the color thresholds instead of the given status bar value
Return Values
Flowsandcells as nested tables: [flowIndex][cell index] = cell data {element, flowSize, lateralSize}

displayRequirement

Description
Display a husbandry requirements row with the given data.
If no label text is specified, the row will be hidden.
Definition
displayRequirement()
Return Values
Listoflateral flow sizes, total lateral sizes (sum of lateral flow sizes), maximum flow size in direction of flow

displayCondition

Description
Display a husbandry conditions row with the given data.
If no label text is specified, the row will be hidden.
Definition
displayCondition()
Return Values
LayoutXstarting offset, layout Y starting offset, Layout X direction {-1|1}, Layout Y direction {-1|1}

sumFillLevelInfos

Description
Sum up the values of an array of animal husbandry fill level info tables.
The fill level info tables have the form of {fillType=fillType, fillLevel=fillLevel, capacity=capacity}. The method
assumes that the array contains only different instances of the same fill type.
Definition
sumFillLevelInfos()
Return Values
elementXoffset, element Y offset

updateLivestockHusbandryProductionDisplay

Description
Update production display for a livestock husbandry.
WIP, no assets ready for testing!
Definition
updateLivestockHusbandryProductionDisplay()
Return Values
whichshould receive focus instead

updateHusbandryConditionsDisplay

Description
Update base conditions (dirt, water, straw) display for a husbandry.
Definition
updateHusbandryConditionsDisplay()
Return Values
floatModifiedX offset
floatModifiedY offset

updateHusbandryFoodDisplay

Description
Update food levels and capacities display for a husbandry.
Definition
updateHusbandryFoodDisplay()

displayHorse

Description
Display data of a single horse in the detail view.
Definition
displayHorse()
Return Values
Trueifthe input event has been handled, false otherwise.

displayLivestock

Description
Display data of a livestock husbandry (pigs, cows, etc.) in the detail view.
Definition
displayLivestock()
Return Values
Trueifthe keyboard input has been processed by this element.

updateMenuButtons

Description
Update contextual menu buttons.
Definition
updateMenuButtons()
Return Values
Actualelement to focus.

renameCurrentHorse

Description
Rename the currently selected horse if the new name has been confirmed.
Definition
renameCurrentHorse()
Return Values
Listofthis element's descendants in depth-first order with contiguous numeric indices.

getFoodDescription

Description
Get a formatted food description text for an animal type.
Definition
getFoodDescription()
Return Values
Firstmatchingdescendant element in depth-first order or nil, if no element matched the predicate function

onButtonRename

Description
Handle "rename" button activation when a horse is selected.
Definition
onButtonRename()
Return Values
elementornil

onListSelectionChanged

Description
Handle animal list selection changes.
Definition
onListSelectionChanged()
Return Values
elementornil

InGameMenuContractsFrame

Description
Exposed controls usable as fields in this frame, identified in configuration.

new

Description
Create a new InGameMenuContractsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
parentelementor full screen borders in an array: {minX, minY, maxX, maxY}

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
elementbordersin an array: {minX, minY, maxX, maxY}

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
floatXaspect scale factor
floatYaspect scale factor

setButtonsForState

Description
Update the state of the frame buttons.
Definition
setButtonsForState()

updateList

Description
Request a mission list update, but remember the position of the selection
If the mission is still in the list, the selection stays
Definition
updateList()
Return Values
indexornil, field name

updateDetailContents

Description
Update the contents of the contract detail screen (context sensitive)
Definition
updateDetailContents()
Return Values
Actualelement to focus.

updateFarmersBox

Description
Update the content of the box with farmer information, using the field.
Definition
updateFarmersBox()
Return Values
boolTrueif the page changed

InGameMenuFinancesFrame

Description
Financial overview of the player's farm for the in-game menu.
-- Displays current balance and loan situation as well as past and present incomes and expenses.
--@category GUI

new

Description
Create a new InGameMenuFinancesFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
Page

initialize

Description
Initialize the finances frame after component creation.
Definition
initialize()
Return Values
PagecontainerGuiElement instance

setClient

Description
Set networking client reference.
Definition
setClient()
Return Values
intPageindex

setEnvironment

Description
Set the mission environment reference.
Definition
setEnvironment()
Return Values
intPagemapping index

setPlayerFarm

Description
Set the player's current farm reference.
Definition
setPlayerFarm()
Return Values
boolTrueif the event was not used, false if it was used.

setHasMasterRights

Description
Set the player's master rights status.
Definition
setHasMasterRights()
Return Values
boolTrueif the event was not used, false if it was used.

getPastDays

Description
Get the array of days before today counting back to the number of displayed past days.
The method resolves days to display labels which can be used directly.
Definition
getPastDays()
Return Values
boolTrueif the event was not used, false if it was used.

setupFinancesTable

Description
Late setup of finances table called on initialization.
Definition
setupFinancesTable()
Return Values
boolTrueif the event was not used, false if it was used.

updateBalance

Description
Update the current balance display text.
Definition
updateBalance()
Return Values
boolTrueif the event was not used, false if it was used.

updateLoan

Description
Update the loan display text.
Definition
updateLoan()
Return Values
boolTrueif the event was not used, false if it was used.

updateDayTotals

Description
Update the expenses/incomes total for all displayed days.
Definition
updateDayTotals()
Return Values
numberoflist items in data source

updateFinancesFooter

Description
Update statically positioned totals display.
Definition
updateFinancesFooter()
Return Values
tableArrayof button info as {i={inputAction=<action name>, text=<optional display text>, callback=<optional callback>}}

updateFinancesTable

Description
Update table display data.
Definition
updateFinancesTable()
Return Values
DataCellornil if not found.

updateFinances

Description
Update finances display.
Definition
updateFinances()
Return Values
DataCellornil if not found.

updateFinancesLoanButtons

Description
Update loan button active states.
Definition
updateFinancesLoanButtons()
Return Values
ListofSortCell for the requested column name

updateMoneyUnit

Description
Update the current money unit.
Also applies the unit change to the borrow/repay button labels.
Definition
updateMoneyUnit()
Return Values
indexofselected row

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
dataRowinstanceor nil, selected data index or 0

buildDataRow

Description
Build a table data row for a given financial statistic.
Definition
buildDataRow()
Return Values
dataRowinstanceor nil (element not part of table row)

onButtonBorrow

Description
Handle borrow money action.
Definition
onButtonBorrow()
Return Values
numberofdata view rows

onButtonRepay

Description
Handle repay money action.
Definition
onButtonRepay()
Return Values
Actualelement to focus.

InGameMenuFrameElement

Description
Base class for frame elements for the in-game menu.
--@category GUI

new

Description
Create a new InGameMenuFrameElement instance.
Definition
new()

initialize

Description
Late initialization of a menu frame.
Override in sub-classes.
Definition
initialize()

getHasCustomMenuButtons

Description
Check if this menu frame requires menu button customization.
Definition
getHasCustomMenuButtons()

getMenuButtonInfo

Description
Get custom menu button information.
Definition
getMenuButtonInfo()
Return Values
tableArrayof button info as {i={inputAction=<action name>, text=<optional display text>, callback=<optional callback>}}

setMenuButtonInfo

Description
Set custom menu button information.
Definition
setMenuButtonInfo(table menuButtonInfo)
Arguments
tablemenuButtonInfoArray of button info as {i={inputAction=<action name>, text=<optional display text>, callback=<optional callback>}} or nil to reset.

setMenuButtonInfoDirty

Description
Set the menu button info dirty flag which causes the menu to update the buttons from this element's information.
Definition
setMenuButtonInfoDirty()

isMenuButtonInfoDirty

Description
Get the menu button info dirty state (has changed).
Definition
isMenuButtonInfoDirty()

clearMenuButtonInfoDirty

Description
Clear menu button dirty flag.
Definition
clearMenuButtonInfoDirty()

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()

requestClose

Description
Request to close the frame.
Frames can contain logic (e.g. saving pending changes) which should be handled before closing. Use this method in
sub-classes request closing the frame so it can wrap up first. If a callback is provided and the initial request
could not close the frame, the callback will be called as soon as the frame can be closed.
Definition
requestClose()

onFrameOpen

Description
Called when this frame is opened by its container.
Definition
onFrameOpen()

onFrameClose

Description
Called when this frame is closed by its container.
Definition
onFrameClose()

InGameMenuGameSettingsFrame

Description
Current savegame settings page for the in-game menu.
--@category GUI

new

Description
Create a new InGameMenuGameSettingsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
Thenewsorting order

initialize

Description
Initialize the game settings frame with concrete page references.
This must be called after loading, since page frames are cloned and references cannot be injected in the constructor.
Definition
initialize()
Return Values
tableAchievementMessageinstance

setMissionInfo

Description
Set the current mission's info.
Required to get current settings and to modify game name.
Definition
setMissionInfo()
Return Values
floatXposition in screen space
floatYposition in screen space

setManureTriggers

Description
Set the currently known manure triggers in the game for helper manure refill settings.
Definition
setManureTriggers()

setHasMasterRights

Description
Set master rights status of the current game instance / player.
Definition
setHasMasterRights()
Return Values
tableChatWindowinstance

updateGameSettings

Description
Update settings display with values from the current mission info / savegame.
Definition
updateGameSettings()
Return Values
floatXposition in screen space
floatYposition in screen space

updatePauseButtonState

Description
Update the pause buttons visuals for pausing/unpausing based on the game state.
Definition
updatePauseButtonState()

assignStaticTexts

Description
Assign static option settings texts.
Definition
assignStaticTexts()
Return Values
intDisplayrow index of the newly added custom text or 0 if it could not be added

assignTimeScaleTexts

Description
Assign time scale setting texts.
Definition
assignTimeScaleTexts()
Return Values
floatXposition in screen space
floatYposition in screen space

assignDirtTexts

Description
Assign dirt setting texts.
Definition
assignDirtTexts()

assignPlantGrowthTexts

Description
Assign plant growth texts.
Definition
assignPlantGrowthTexts()
Return Values
floatGameinfo display width of visible elements in screen space

assignAutoSaveTexts

Description
Assign auto save texts.
Definition
assignAutoSaveTexts()
Return Values
tableWeathericon HUDElement instance

assignDynamicTexts

Description
Assign game state dependent setting texts.
Definition
assignDynamicTexts()
Return Values
tableTemperatureicon HUDElement instance

updateToolTipBoxVisibility

Description
Update visibility of tool tip box, only show when there is text to display.
Definition
updateToolTipBoxVisibility()
Return Values
tableClockhand HUDElement instance

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tableTimescale arrow icon HUDElement instance

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableGamePausedDisplayinstance

onEnterPressedSavegameName

Description
Handle accepting savegame name input.
Definition
onEnterPressedSavegameName()
Return Values
boolIftrue, the HUD is currently visible.

onToolTipBoxTextChanged

Description
Handle changing of the tool tip text.
Definition
onToolTipBoxTextChanged()
Return Values
tableHUDDisplayElementinstance

InGameMenuGeneralSettingsFrame

Description
General game settings page for the in-game menu.
--@category GUI

new

Description
Create a new InGameMenuGeneralSettingsFrame instance.
Definition
new(table subclass_mt, table settingsModel)
Arguments
tablesubclass_mt[optional] Meta table of subclass
tablesettingsModelSettingsModel reference which handles settings display state across the UI
Return Values
floatScreenspace X translation
floatScreenspace Y translation

updateGeneralSettings

Description
Update display values from settings.
Definition
updateGeneralSettings()

updateToolTipBoxVisibility

Description
Update visibility of tool tip box, only show when there is text to display.
Definition
updateToolTipBoxVisibility()
Return Values
tableHUDElementinstance

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
floatPivotx position offset from element position in screen space
floatPivoty position offset from element position in screen space

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()

onClickCheckbox

Description
Handle clicks on a check box.
Definition
onClickCheckbox()
Return Values
floatXposition in screen space
floatYposition in screen space

onClickMultiOption

Description
Handle clicks on a multi option element.
Definition
onClickMultiOption()

onClickNativeHelp

Description
Handle a button click on the native help button which is only visible and active on XBOX.
Definition
onClickNativeHelp()
Return Values
widthscalefactor
heightscalefactor

onToolTipBoxTextChanged

Description
Handle changing of the tool tip text.
Definition
onToolTipBoxTextChanged()

InGameMenuHelpFrame

Description
Exposed controls usable as fields in this frame, identified in configuration.

new

Description
Create a new InGameMenuHelpFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
floatRedvalue
floatGreenvalue
floatBluevalue
floatAlphavalue

setMissionBaseDirectory

Description
Set the current mission's base directory to let this frame load images from that location.
Definition
setMissionBaseDirectory()

createList

Description
Set up UI elements for a given category index.
Definition
createList()

loadHelpLine

Description
Load help category texts.
Definition
loadHelpLine()

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
floatAlphavalue

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableHUDPopupMessageinstance

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
floatScreenspace X translation
floatScreenspace Y translation

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()

onHelpLineListSelectionChanged

Description
Handle a change of row in the current category's help list.
Definition
onHelpLineListSelectionChanged()
Return Values
tableHUDTextDisplayinstance

InGameMenuMapFrame

Description
Map overview frame of the in-game menu.
-- Displays the current map with markers for points of interest and terrain overlays.
--@category GUI

new

Description
Create a new InGameMenuMapFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
boolTrueif the left border of the map has been reached
boolTrueif the right border of the map has been reached
boolTrueif the top border of the map has been reached
boolTrueif the bottom border of the map has been reached

createInputGlyphs

Description
Create input help glyphs.
Definition
createInputGlyphs()

initialize

Description
Initialize map frame after GUI setup.
Definition
initialize()

onLoadMapFinished

Description
Called by InGameMenu when a map has finished loading.
Definition
onLoadMapFinished()

toggleMapInput

Description
Toggle map overview-specific input.
Make sure this is called exactly once for activation and deactivation each when the map frame is opened or closed.
Definition
toggleMapInput()
Return Values
boolTrueif the left border of the map has been reached
boolTrueif the right border of the map has been reached
boolTrueif the top border of the map has been reached
boolTrueif the bottom border of the map has been reached

disableAlternateBindings

Description
Disable alternate bindings for menu navigation.
This will disable some default bindings which interfere with camera controls (e.g. D-Pad on controller). Whenever any
input event is modified, this method must be called again afterwards.
Definition
disableAlternateBindings()

getContextBoxPositionAndOrientation

Description
Get the context box position and orientation for a given hotspot.
Definition
getContextBoxPositionAndOrientation()
Return Values
floatScreenspace X position
floatScreenspace Y position
stringOrientationvalue, one of InGameMenuMapFrame.CONTEXT_BOX_ORIENTATION
floatRotationangle value

updateContextBoxPosition

Description
Update the position of the hotspot context box if it's active.
Definition
updateContextBoxPosition()

setInGameMap

Description
Set the IngameMap reference in this frame's required IngameMapElement for display.
Definition
setInGameMap()
Return Values
floatXposition in screen space after the last glyph

setTerrainSize

Description
Set the terrain size for use in the ingameMapElement.
Definition
setTerrainSize()
Return Values
floatXposition in screen space after the last glyph

setMissionFruitTypes

Description
Set the fruit types used in the current mission.
Definition
setMissionFruitTypes()
Return Values
floatScreenspace height used by the combo header (0 if invisible)

setClient

Description
Set the client connection object for event dispatching.
Definition
setClient()
Return Values
tableInputhelp elements
floatScreenspace height used by the returned help elements

setPlayerFarm

Description
Set the current player's farm ID.
Definition
setPlayerFarm()

assignFilterData

Description
Assign filter data after map loading.
Definition
assignFilterData()
Return Values
intMaximumnumber of entries to show

assignCropTypeFilterData

Description
Assign display data for the crop type filters.
Definition
assignCropTypeFilterData()
Return Values
booleanisAllowedisAllowed

assignGroundStateFilterData

Description
Assign display data for the ground state filters (growth and soil state).
Definition
assignGroundStateFilterData()
Return Values
tableComboInputGlyphElement instance

assignGroundStateColors

Description
Assign colors for ground state (growth or soil) elements.
Definition
assignGroundStateColors()
Return Values
tableComboheader HUDElement

resetUIDeadzones

Description
Reset the UI dead zones for the map.
Definition
resetUIDeadzones()
Return Values
floatDisplayheight in screen space

setStaticUIDeadzone

Description
Set a static UI dead zone for the map to make it ignore cursor/mouse input within that screen region.
This dead zone is always in effect, regardless of map mode.
Definition
setStaticUIDeadzone()
Return Values
floatModifiedinput help panel drawing vertical offset

onOverviewOverlayFinished

Description
Called when the overview overlay is finished for display.
Definition
onOverviewOverlayFinished()
Return Values
tableSideNotificationinstance

onFarmlandOverlayFinished

Description
Called when the farmland overlay is finished for display.
Definition
onFarmlandOverlayFinished()
Return Values
tableSpeakerDisplayinstance

generateOverviewOverlay

Description
(Re-)Generate the map overlay for crop types, growth and soil states.
Definition
generateOverviewOverlay()
Return Values
tableOverlayinstance

generateFarmlandOverlay

Description
(Re-)Generate the map overlay for farmlands.
Definition
generateFarmlandOverlay()
Return Values
tableHUDElementinstance

setFilterIconState

Description
Set the display state of a filter icon based on the current filter settings.
Definition
setFilterIconState()
Return Values
tableTopNotificationinstance

toggleFarmlandsHotspotFilterSettings

Description
Toggle hotspot filter settings for the farmlands view mode.
Definition
toggleFarmlandsHotspotFilterSettings()
Return Values
floatScreenspace X translation
floatScreenspace Y translation

showContextInput

Description
Show input buttons based on the current map selection context.
Definition
showContextInput()

updateContextInputBarVisibility

Description
Update the context input bar's visibility.
Turns it invisible if there are no buttons visile, otherwise turns it visible.
Definition
updateContextInputBarVisibility()
Return Values
boolIftrue, the HUD extension should be drawn in the current frame.

showContextMarker

Description
Show marker button according to context.
Definition
showContextMarker()
Return Values
floatModifiedinput help panel drawing vertical offset

showContextBox

Description
Show the context box for a selected hotspot.
Definition
showContextBox()
Return Values
tableHUDextension instance or nil of no extension has been registered for the given specialization

hideContextBox

Description
Hide the hotspot context box.
Definition
hideContextBox()
Return Values
tableArrayof overlay descriptions: {overlay=overlay, x=0, y=0, rotation=0, invertX=false, invisibleBorderRight=vehicle.schemaOverlay.invisibleBorderRight, invisibleBorderLeft=vehicle.schemaOverlay.invisibleBorderLeft}
floatScreenspace height of root vehicle schema overlay

setMapSelectionItem

Description
Set the map selection to a hotspot.
Definition
setMapSelectionItem()

getHotspotData

Description
Get display data for a selectable map hotspot.
Definition
getHotspotData()
Return Values
floatMinimumX position (left)
floatMaximumX position (right)
stringDescriptiontext
stringDisplayimage file path
tableDisplayimage UVs
tableVehicleinstance if a vehicle has been selected, or nil otherwise

setColorBlindMode

Description
Set the current color blind mode.
Updates colors on buttons and overlays.
Definition
setColorBlindMode(bool isActive)
Arguments
boolisActiveIf true, color blind mode is active

initializeFilterButtonState

Description
Initialize filter buttons with the current filter state.
Definition
initializeFilterButtonState()
Return Values
tableSchemaOverlay instance

resetFarmlandSelection

Description
Reset farmland selection state.
Definition
resetFarmlandSelection()
Return Values
tableInGameMenuAnimalsFrameinstance

checkPlaceablesOnFarmland

Description
Check if there are any placeables owned by the player on a given farmland.
Definition
checkPlaceablesOnFarmland()
Return Values
floatScreenspace X position
floatScreenspace Y position
stringOrientationvalue, one of InGameMenuMapFrame.CONTEXT_BOX_ORIENTATION
floatRotationangle value

onMoneyChanged

Description
Handle changes to farm balance values.
Definition
onMoneyChanged(int farmId, float newBalance)
Arguments
intfarmIdID of farm whose current balance has changed
floatnewBalanceNew balance value of the given farm

onDrawPostIngameMap

Description
Called after the in-game map has been drawn.
Draws the mode-dependent state overlay on top of the map
Definition
onDrawPostIngameMap()

onClickMapOverviewSelector

Description
Handle clicking the map overview selector which switches map overlay context (crop types, growth states, soil states).
Definition
onClickMapOverviewSelector()

onFilterButtonSelect

Description
Handle filter button focus or highlight activation.
Definition
onFilterButtonSelect()
Return Values
stringDescriptiontext
stringDisplayimage file path
tableDisplayimage UVs
tableVehicleinstance if a vehicle has been selected, or nil otherwise

onFilterButtonUnselect

Description
Handle filter button focus or highlight deactivation.
Definition
onFilterButtonUnselect()

setFilterButtonDisplayEnabled

Description
Set the display state of a filter button.
Definition
setFilterButtonDisplayEnabled()

toggleFilter

Description
Toggle filter state on filter button click.
Definition
toggleFilter()

onClickCropFilter

Description
Handle activation of a crop type filter.
Definition
onClickCropFilter(table element, int fruitTypeIndex)
Arguments
tableelementClicked button element
intfruitTypeIndexFruit type index as valid in the current mission.
Return Values
intListindex corresponding to the farm ID or 1 if it could not be found or was the spectator farm ID

onClickGrowthFilter

Description
Handle activation of a growth state filter.
Definition
onClickGrowthFilter(table element, int growthStateIndex)
Arguments
tableelementClicked button element
intgrowthStateIndexGrowth state index
Return Values
dataRowinstancewith prices data for the given selling point

onClickSoilFilter

Description
Handle activation of a soil state filter.
Definition
onClickSoilFilter(table element, int growthStateIndex)
Arguments
tableelementClicked button element
intgrowthStateIndexSoil state index
Return Values
floatSortingvalue, see TableElement:setCustomSortFunction(...)

onClickHotspot

Description
Handle clicking / activating a map hotspot.
Definition
onClickHotspot()
Return Values
floatCurrentfill level >= 0 or a value < 0 if no storage exists for the requested fill type index
floatTotalcapacity for the fill type >= 0 or a value < 0 if no storage exists for the requested fill type index

onClickMap

Description
Handle clicking within the map.
Definition
onClickMap()

onFarmlandStateChanged

Description
Called from FarmlandManager whenever a significant farmland change (mainly ownership) occurs.
Definition
onFarmlandStateChanged()
Return Values
tableTableElement.DataRowinstance

onVehicleReset

Description
Handle ResetVehicleEvent local event.
Definition
onVehicleReset()
Return Values
dataRowinstancewith vehicle data for the given vehicle

onClickSwitchMapMode

Description
Handle activation of map mode switch button.
Definition
onClickSwitchMapMode()
Return Values
floatSortingvalue, see TableElement:setCustomSortFunction(...)

onYesNoReset

Description
Dialog confirmation callback for resetting a vehicle.
Definition
onYesNoReset()
Return Values
Trueifthe server matches the current filter settings, false otherwise

notifyPause

Description
Notify this frame when pausing the game.
Definition
notifyPause()
Return Values
dataRowinstancewith server data

selectFirstHotspot

Description
Select the first visible hotspot on the map
Definition
selectFirstHotspot()
Return Values
tableLandscapingScreeninstance

updateInputGlyphTransform

Description
Fit an input glyph into its corresponding placeholder GuiElement instance.
Definition
updateInputGlyphTransform()
Return Values
tablenewLandscapingScreenController instance

updateInputGlyphs

Description
Update input glyphs when input context changes.
Definition
updateInputGlyphs()
Return Values
intNodeID of the actual indicator shape in the loaded indicator asset
intNodeID of the attached light source of the loaded indicator asset

onYesNoBuyFarmland

Description
Handle confirmation result of farmland buying dialog.
Definition
onYesNoBuyFarmland()

onYesNoSellFarmland

Description
Handle confirmation result of farmland selling dialog.
Definition
onYesNoSellFarmland()
Return Values
tablecategorieslist of categories

registerInput

Description
Register input actions.
Definition
registerInput()
Return Values
tablePlacementScreeninstance

onMenuActivate

Description
Menu activate event, bound to vehicle enter, place visit or buying farmlands.
Definition
onMenuActivate()
Return Values
Trueifthe placement is valid, false otherwise
stringReasonof being invalid

onMenuCancel

Description
Menu cancel event, bound to hotspot tagging, vehicle reset or selling farmlands.
Definition
onMenuCancel()

onSwitchVehicle

Description
Switch vehicle action event, bound to cycle visible hotspots.
Definition
onSwitchVehicle()
Return Values
tableShopConfigScreeninstance

InGameMenuMultiplayerFarmsFrame

Description
Exposed controls usable as fields in this frame, identified in configuration.

new

Description
Create a new InGameMenuMultiplayerFarmsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
floatFuelcapacity in liters

initialize

Description
Late initialization after frame cloning.
Definition
initialize()
Return Values
floatBaseprice
floatUpgradeprice
boolTrueif there are changes

setCurrentUserId

Description
Set the reference to the current user.
Definition
setCurrentUserId()

setUsers

Description
Set the current users reference.
Definition
setUsers()

setPlayer

Description
Set the reference to the current player.
Definition
setPlayer()
Return Values
intNumberof used config option elements

setPlayerFarm

Description
Set the reference to the current player's farm.
Definition
setPlayerFarm()
Return Values
tableNewcollection of filtered owned items

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tableArrayof brands in the form of {i={id = brand.index, iconFilename = brand.image, label = brand.title}}

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableArrayof vehicle categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

buildFarmListItems

Description
Build the farm list items from the known farms.
Definition
buildFarmListItems()
Return Values
tableArrayof tool categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

updateFarmList

Description
Update farm list.
Definition
updateFarmList()
Return Values
tableArrayof object categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

getListFarmIndex

Description
Get the list index for a given farm ID.
Definition
getListFarmIndex(int farmId)
Arguments
intfarmIdFarm ID
Return Values
tableArrayof placeable categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}
intListindex corresponding to the farm ID or 1 if it could not be found or was the spectator farm ID

updateFarmBalance

Description
Update a farm's balance display.
Definition
updateFarmBalance()
Return Values
intNextusable attribute slot index after these fill types

updateFarmPlayers

Description
Update displayed player names on a farm.
Definition
updateFarmPlayers()
Return Values
intNumberof attributes used for text data

updateMenuButtons

Description
Update context menu buttons.
Definition
updateMenuButtons()
Return Values
tableinstanceInstance of object

joinFarm

Description
Let the current player join a given farm.
The player will leave their current farm (can be spectator farm) and join the new farm if possible. This sends
a PlayerSetFarmEvent which will check any farm password on the server side. In response, a PlayerSetFarmAnswerEvent
is sent back. The method will try using a previously recorded farm password if one has been received during a join
event.
Definition
joinFarm()
Return Values
booleansuccesssuccess

leaveFarm

Description
Let the current player leave their farm.
The player will join the spectator farm and be able to choose a new farm to join.
Definition
leaveFarm()
Return Values

deleteFarm

Description
Delete a given farm
The current player must have admin privileges on the server and the farm must be empty.
Definition
deleteFarm()
Return Values
float
float
float
float
float
float

editFarm

Description
Show a dialog to edit farm properties.
The current player must have farm manager or administrator privileges on the server.
Definition
editFarm()

createFarm

Description
Show a dialog to create a new farm
The current player must have administrator privileges on the server.
Definition
createFarm()

onPlayerSetFarmAnswer

Description
Handle an answer to PlayerSetFarmEvent.
Definition
onPlayerSetFarmAnswer(int answerState, int farmId, string password)
Arguments
intanswerStatePlayerSetFarmAnswerEvent.STATE member
intfarmIdIf the state is OK, will contain the newly joined farm
stringpasswordIf the state is OK, will contain the newly joined farm's password

onFarmPasswordEntered

Description
Handle confirmation of farm password input when joining a farm.
Definition
onFarmPasswordEntered()

onPermissionChanged

Description
Handle changes to user permissions.
If the current user's permissions change, update the menu buttons in case they were elevated to farm manager status.
Definition
onPermissionChanged()

onFarmCreated

Description
Handle creation of a new farm.
Definition
onFarmCreated()
Return Values
tableselfinstance of class event

onFarmsChanged

Description
Handle state update of any farm.
Definition
onFarmsChanged()
Return Values
tableinstanceinstance of event

onPlayerFarmChanged

Description
Handle a player changing their farm.
Definition
onPlayerFarmChanged()
Return Values
tableselfinstance of class event

onFarmMoneyChanged

Description
Handle a balance change of a farm.
Definition
onFarmMoneyChanged()
Return Values
tableinstanceinstance of event

onClickLeft

Description
Handle clicking on the left navigation button.
Definition
onClickLeft()
Return Values
tableselfinstance of class event

onClickRight

Description
Handle clicking on the right navigation button.
Definition
onClickRight()
Return Values
tableinstanceinstance of event

onClickFarm

Description
Handle a click / activation of a farm item.
Definition
onClickFarm()
Return Values
tableinstanceInstance of object

onDoubleClickFarm

Description
Handle a double click of a farm item.
Definition
onDoubleClickFarm()
Return Values
booleansuccesssuccess

onSelectionChanged

Description
Handle a farm selection change.
Definition
onSelectionChanged()
Return Values
floatdailyUpkeepdaily up keep

onDeleteFarmYesNo

Description
Handle farm deletion dialog confirmation.
Definition
onDeleteFarmYesNo()
Return Values
floatsellPricesell price

InGameMenuMultiplayerUsersFrame

Description
Multiplayer user management frame for the in-game menu.
-- Displays a user list and allows modification of permissions as well as money transfers between farms. Administrators
can log in using a password and kick/ban/unban users when logged in.
--@category GUI

new

Description
Create a new InGameMenuMultiplayerUsersFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
booleanisActiveForInputis active for input

initialize

Description
Late initialization.
Definition
initialize()
Return Values
tableselfinstance of class event

onFrameOpen

Description
Called when this frame is opened by its container.
Definition
onFrameOpen()
Return Values
tableinstanceinstance of event

onFrameClose

Description
Called when this frame is closed by its container.
Definition
onFrameClose()
Return Values
tableinstanceinstance of object

setupUserListFocusContext

Description
Set up the user list to store an instance flag when navigating users or not for menu button context.
Definition
setupUserListFocusContext()
Return Values
integeridi3d rootnode

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
booleanisValidtrue if index is valid else false

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
integeridid of object
integeridid of used root node

setPlayerFarm

Description
Set the reference to the current player's farm.
Definition
setPlayerFarm()

setCurrentUserId

Description
Set the current user ID.
Definition
setCurrentUserId()
Return Values
NewBindinginstance

setBanStorage

Description
Set the ban storage reference.
Definition
setBanStorage()
Return Values
instanceinitialized with values from XML and the given parameters

setUsers

Description
Set the current users reference.
Definition
setUsers()
Return Values
intCombobit mask

getSortedUsers

Description
Get a new sorted array of known users for displaying.
Users are grouped by farms, starting with the current player's farm (unless they're a spectator). Within groups,
users are sorted alphabetically by name.
Definition
getSortedUsers()
Return Values
Trueifthere is a collision.

buildUserDisplayInfo

Description
Build a display name for a given user and their special privilege flags.
Definition
buildUserDisplayInfo()
Return Values
ClonedBindinginstance

rebuildUserList

Description
Update connected player information.
Definition
rebuildUserList(table missionUsers)
Arguments
tablemissionUsersArray of users managed by the current mission instance.
Return Values

updateMenuButtons

Description
Update menu buttons based on the current user's admin status.
Definition
updateMenuButtons()
Return Values
instanceinitialized with values from XML

updateBalance

Description
Update the current balance display.
Definition
updateBalance()
Return Values
ClonedInputActioninstance

setCurrentBalance

Description
Set the current money balance display.
Definition
setCurrentBalance(float balance, string balanceString)
Arguments
floatbalanceCurrent balance of the current player
stringbalanceStringProperly formatted money string
Return Values
tableInputBindinginstance

updateDisplay

Description
Update all display states and text.
Definition
updateDisplay()
Return Values
tableSetof required device categories, {<category> = true}

onButtonBan

Description
Handle a ban button activation.
Definition
onButtonBan()
Return Values
boolTrueif there are any configured bindings for the given device, false otherwise

onYesNoBan

Description
Handle ban confirmation dialog result.
Definition
onYesNoBan()
Return Values
GS_INPUT_HELP_MODE_KEYBOARDorGS_INPUT_HELP_MODE_GAMEPAD

onButtonKick

Description
Handle a kick button activation.
Definition
onButtonKick()
Return Values
GS_INPUT_HELP_MODE_KEYBOARDorGS_INPUT_HELP_MODE_GAMEPAD

onYesNoKick

Description
Handle kick confirmation dialog result.
Definition
onYesNoKick()
Return Values
Trueifthe parameters are valid, false otherwise.

onButtonUnBan

Description
Handle an unban button activation
Definition
onButtonUnBan()
Return Values
boolTrueif the event could be registered, false otherwise
stringeventID if successful, empty string otherwise
tableActionreference of a colliding action if there would be a collision, nil otherwise

onButtonShowProfile

Description
Handle a show user profile button activation.
Definition
onButtonShowProfile()

onButtonInviteFriends

Description
Handle an invite friends button activation
Definition
onButtonInviteFriends()

onButtonAdminLogin

Description
Handle an admin login button activation.
Definition
onButtonAdminLogin()
Return Values
boolTrueif there would be a collision, false otherwise
tableCollidingaction if there would be a collision, nil otherwise

onUserSelected

Description
Handle selection changes in the user list.
Definition
onUserSelected()

onClickPermission

Description
Handle clicking a permission check box.
Definition
onClickPermission(table checkboxElement, bool isActive)
Arguments
tablecheckboxElementToggleButtonElement which received the click
boolisActiveNew checked state
Return Values
arrayoftuples: {i={action=InputAction, event=InputEvent}}

onClickTransferButton

Description
Handle clicking the transfer button
Definition
onClickTransferButton()
Return Values
Gamepadcombomask, Mouse combo mask

transferMoney

Description
Transfer money from the current player's farm to the selected farm.
Definition
transferMoney()
Return Values
instanceor nil if ID is invalid

onClickRemoveFromFarm

Description
Handle clicking the remove player from farm button.
Definition
onClickRemoveFromFarm()
Return Values
instanceor nil if ID is invalid

onYesNoRemoveFromFarm

Description
Handle remove player from farm confirmation dialog result.
Definition
onYesNoRemoveFromFarm()
Return Values
instanceor nil if ID is invalid

onClickPromote

Description
Handle clicking the promote player to farm manager button.
Definition
onClickPromote()
Return Values
floatMousecursor X position in screen space
floatMousecursor Y position in screen space

onYesNoPromoteToFarmManager

Description
Handle promote user confirmation dialog result.
Definition
onYesNoPromoteToFarmManager()

onClickContractor

Description
Handle clicking the contractor toggle button.
Definition
onClickContractor()
Return Values
previousDevicesTableof internal ID -> InputDevice before the current initialization

onYesNoToggleContractorState

Description
Handle contractor state toggle confirmation dialog result.
Definition
onYesNoToggleContractorState()
Return Values
Listofdevice information tables, format: {deviceId=[device ID], name=[device name]}

onFarmMoneyChanged

Description
Handle a local money change event for any farm.
Definition
onFarmMoneyChanged()
Return Values
Modifierbitmask

onFarmsChanged

Description
Handle state update of any farm.
Definition
onFarmsChanged()
Return Values
Trueifthe binding's device ID could be resolved, false otherwise

onPlayerFarmChanged

Description
Handle a player changing their farm.
Definition
onPlayerFarmChanged()
Return Values
functionresultstable {checkFunctionRef=[functionResult]}

onPermissionChanged

Description
Handle a local player permission change event.
Definition
onPermissionChanged()
Return Values

onContractingStateChanged

Description
Handle a local contracting state change event.
Definition
onContractingStateChanged()
Return Values
boolTrueif the new binding could be added
tableReferenceto an Action containing a binding which collided with the added binding or nil

onAdminPassword

Description
Handle admin login password dialog response.
Definition
onAdminPassword()

onAdminLoginSuccess

Description
Handle successfully logging in as an admin.
Definition
onAdminLoginSuccess()
Return Values
Trueifa binding could be found and updated, false if there was a collision
andAction reference of a collision as {collisionBinding=Binding, collisionAction=Action} or nil

InGameMenuPricesFrame

Description
Prices overview frame of the in-game menu.
-- Displays current prices of sellable goods and produce.
--@category GUI

new

Description
Create a new InGameMenuPricesFrame instance.
Definition
new(table subclass_mt, table l10n, table fillTypeManager)
Arguments
tablesubclass_mt[optional] Meta table of subclass
tablel10nI18N reference
tablefillTypeManagerFillTypeManager reference

makeTableFocusOverrideFunction

Description
Create a focus override function for the prices table which scrolls horizontally if possible instead of exiting the
table.
Definition
makeTableFocusOverrideFunction()
Return Values
Trueifall given axes are currently active, input value of the non-modified axis (last in list)

getStationName

Description
Get the display name of a selling station.
Definition
getStationName()
Return Values
Trueifall axes are active (digital interpretation), input value of the non-modified axis (last in list)

setSellingStations

Description
Set the current list of selling stations for displaying.
Definition
setSellingStations()
Return Values
Inputvalueof the axis in the range [-1, 1] for full axes or [0, 1] for half axes.

updateVerticalSlider

Description
Update item counts and handle size of the vertical slider.
Definition
updateVerticalSlider()
Return Values

setupPriceTable

Description
Initial setup of the prices table and required data.
Definition
setupPriceTable()
Return Values
Orderedactionbindings in the form of {i={action=InputAction, bindings={Binding}}}

updatePriceTable

Description
Update prices table display data.
Definition
updatePriceTable()
Return Values

updateHeaderIcons

Description
Update table headers with fill type icons according to current horizontal slider position.
Definition
updateHeaderIcons()
Return Values
tableArrayof events

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tableFirstactive event or InputEvent.NO_EVENT

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
xmotionscale, Y motion scale

onChangedPriceSlider

Description
Handle horizontal slider changes.
Definition
onChangedPriceSlider()
Return Values
Trueifthe user settings have passed the integrity check, false otherwise.

onClickPriceHeader

Description
Handle price table header clicks.
Causes the table to be sorted by the clicked header column's numeric price values.
Definition
onClickPriceHeader()
Return Values
Trueifthe axis name represents a physical full axis, false otherwise

onClickSellingPointHeader

Description
Handle selling point table header clicks.
Causes the table to be sorted by selling point names.
Definition
onClickSellingPointHeader()
Return Values
Trueifthe input name represents an analog input

onClickPrices

Description
Handle table row clicks.
Definition
onClickPrices()
Return Values
Trueifthe axis is at zero position, false otherwise

onDoubleClickPrices

Description
Handle table row double-clicks.
Sets a map marker on the selected selling point or clears it again.
Definition
onDoubleClickPrices()
Return Values
NewInputDeviceinstance

onDataBindSellingPoint

Description
Bind an element to the selling point data.
Definition
onDataBindSellingPoint()
Return Values
DeviceIDor empty string

onDataBindPrice

Description
Bind an element to the indexed price data.
Definition
onDataBindPrice()
Return Values
Devicenameor empty string

onDataBindSiloCapacityLabel

Description
Bind an element to the silo capacity label data.
Definition
onDataBindSiloCapacityLabel()
Return Values
Prefixnumber,or -1 if none exists; raw engine-issued device ID

onDataBindSiloCapacityValue

Description
Binding an element to the indexed silo capacity value data.
Definition
onDataBindSiloCapacityValue()
Return Values
instancecontaining the symbol overlays in its "buttons" field

setSellingPointData

Description
Set data for a selling point table cell.
Definition
setSellingPointData(table dataCell, table sellingStation)
Arguments
tabledataCellTableElement.DataCell instance for a selling point cell
tablesellingStationSellingStation instance of the current data row
Return Values
arrayofhelp elements (see InputDisplayManager:makeHelpElement() for structure)

setPriceData

Description
Set data for a price table cell.
Definition
setPriceData(table dataCell, int priceIndex, table sellingStation)
Arguments
tabledataCellTableElement.DataCell instance for a price cell
intpriceIndexPrice column index
tablesellingStationSellingStation instance of the current data row
Return Values
Hashtableof currently active combo button action names, {action name=true}

buildDataRow

Description
Build a DataRow from selling point properties to add to the prices table
Definition
buildDataRow(table sellingStation)
Arguments
tablesellingStationSellingStation reference
Return Values
Axisnameor nil if not found, internal ID of binding device
dataRowinstancewith prices data for the given selling point

sortPrices

Description
Table sorting function for prices.
Definition
sortPrices(table sortCell1, table sortCell1)
Arguments
tablesortCell1TableElement.SortCell instance representing the first cell to compare
tablesortCell1TableElement.SortCell instance representing the second cell to compare
Return Values
instanceor nil if no overlay is available for the action's bindings
floatSortingvalue, see TableElement:setCustomSortFunction(...)

getStorageFillLevel

Description
Get the storage fill level for a given fill type index.
Definition
getStorageFillLevel(int index, bool farmSilo)
Arguments
intindexFill type index of the requested storage fill level
boolfarmSiloIf true, only counts storage of owned farm silos
Return Values
keytext(e.g. "F" for "KEY_f") for the keyboard action binding or nil if no resolution is possible
floatCurrentfill level >= 0 or a value < 0 if no storage exists for the requested fill type index
floatTotalcapacity for the fill type >= 0 or a value < 0 if no storage exists for the requested fill type index

InGameMenuStatisticsFrame

Description
Game statistics display frame for the in-game menu.
--@category GUI

new

Description
Create a new InGameMenuStatisticsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
controllersymbolsconfiguration key name

updateStatistics

Description
Update statistics data in tables.
Definition
updateStatistics()
Return Values
controllersymbolsconfiguration key name

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
NewInputEventinstance

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableinstanceinstance of object

buildDataRow

Description
Build a table data row for a given statistics attribute.
Definition
buildDataRow(table statAttribute)
Arguments
tablestatAttributeStatistics attribute as defined in FarmStats
Return Values
booleantrueif loading was successful else false
tableTableElement.DataRowinstance

InGameMenuTutorialFrame

Description
Exposed controls usable as fields in this frame, identified in configuration.

new

Description
Create a new InGameMenuFinancesFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
stringcutterEffectTypethe real cutterEffect name, nil if not defined

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tablecutterEffectscutter effects

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableinstanceinstance of object

InGameMenuVehiclesFrame

Description
Exposed controls usable as fields in this frame, identified in configuration.

new

Description
Create a new InGameMenuVehiclesFrame instance.
Definition
new(table subclass_mt, table messageCenter, table l10n, table storeManager, table brandManager)
Arguments
tablesubclass_mtSub-class meta table
tablemessageCenterMessageCenter reference for notifications
tablel10nI180N reference for display text resolution
tablestoreManagerStoreManager reference for vehicle store data look-ups
tablebrandManagerBrandManager reference for vehicle brand data look-ups
Return Values
booleantrueif loading was successful else false

initialize

Description
Late initialization.
Definition
initialize()
Return Values
stringmaterialTypethe real material name, nil if not defined

updateGarage

Description
Update the garage view.
Definition
updateGarage()
Return Values
integermaterialIdid of material

updateVerticalSlider

Description
Update item counts and handle size of the vertical slider.
Definition
updateVerticalSlider()
Return Values
tableinstanceinstance of object

setAccessibleVehicles

Description
Set a list of vehicles currently accessible by the player.
Definition
setAccessibleVehicles()
Return Values
booleantrueif loading was successful else false

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
stringparticleTypethe real particle name, nil if not defined

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableparticleSystemparticleSystem

makeTableHeaderFocusOverrideFunction

Description
Create a focus override function for a table header which modifies the scroll bar instead of navigation when
vertical navigation input is received.
Definition
makeTableHeaderFocusOverrideFunction()
Return Values
tableinstanceinstance of object

setNameData

Description
Set data for a vehicle name table cell.
Definition
setNameData()
Return Values
booleantrueif loading was successful else false

setAgeData

Description
Set data for a vehicle age table cell.
Definition
setAgeData()
Return Values
booleantrueif loading was successful else false

setOperatingHoursData

Description
Set data for a vehicle operating hours table cell.
Definition
setOperatingHoursData()
Return Values
tableinstanceinstance of object

setDamageData

Description
Set data for a vehicle damage table cell.
Definition
setDamageData()
Return Values
tableinstanceinstance of object

setLeasingData

Description
Set data for a vehicle leasing costs table cell.
Definition
setLeasingData()
Return Values
tableinstanceinstance of object

setValueData

Description
Set data for a vehicle selling value table cell.
Definition
setValueData()
Return Values
booleantrueif loading was successful else false

buildDataRow

Description
Build a DataRow from vehicle properties to add to the table.
Definition
buildDataRow(table vehicle)
Arguments
tablevehicleVehicle reference
Return Values
tablebaleTypebaleType object
dataRowinstancewith vehicle data for the given vehicle

sortAttributes

Description
Table sorting function for numeric values.
Definition
sortAttributes(table sortCell1, table sortCell1)
Arguments
tablesortCell1TableElement.SortCell instance representing the first cell to compare
tablesortCell1TableElement.SortCell instance representing the second cell to compare
Return Values
tablebaleTypebaleType object
floatSortingvalue, see TableElement:setCustomSortFunction(...)

onClickVehicleHeader

Description
Handle clicks on the vehicle name header.
Switches table to default string sorting.
Definition
onClickVehicleHeader()
Return Values
tablebalebale

onClickAttributeHeader

Description
Handle clicks on an attribute header.
Switches table to numerical sorting.
Definition
onClickAttributeHeader()
Return Values
stringbaleKeybale key

InputAction

Description
Logical input action.
-- Game components react to actions to alter their state. Available actions are loaded from "dataS/inputActions.xml".
Default action names are available for use as constants in the form of InputAction.ACTION_NAME (see end of file).
Additional actions (e.g. from mods) will be dynamically added as such constants at run time.
--@category Input
--@xmlConfig action#name Action name. This serves as a unique identifier in both configuration and code.

new

Description
Create a new InputAction instance
Definition
new(name Action, axisType Type, isLocked If, ignoreComboMask If, displayNamePositive [optional], displayNameNegative [optional])
Arguments
nameActionname, unique
axisTypeTypeof action axis (HALF or FULL)
isLockedIftrue, bindings for this action cannot be changed in the game
ignoreComboMaskIftrue, non-combo bindings will trigger this action even if a combo button is currently active
displayNamePositive[optional]Display name of the action in positive direction for the current localization
setting. This is the default display name.
displayNameNegative[optional]Display name of the action in negative direction for the current localization
setting. Only used for full axes.
Return Values
InputAction

createFromXML

Description
Create a new InputAction instance from an XML element.
Definition
createFromXML(xmlFile XML, elementTag Tag)
Arguments
xmlFileXMLfile handle
elementTagTagof the element to parse as an InputAction
Return Values
integernumPixelsnumber of pixels
InputActioninstanceinitialized with values from XML

addBinding

Description
Add a Binding to this action.
Definition
addBinding()
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area pixels

removeBinding

Description
Remove a binding from this action.
Definition
removeBinding()

getBindings

Description
Get the bindings for this action.
Definition
getBindings()
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area pixels

clearBindings

Description
Clear this action's bindings.
Definition
clearBindings()

setPrimaryKeyboardBinding

Description
Let this action know which binding is its primary keyboard binding.
Stores the input axes as a concatenated string for comparisons.
Definition
setPrimaryKeyboardBinding(Binding Binding)
Arguments
BindingBindinginstance which is the primary keyboard binding for this action
Return Values
integernumChangedPixelsnumber of changed pixels

isFullAxis

Description
Determine if this action represents a logical full axis.
Definition
isFullAxis()
Return Values
tablecolortire track color

getIgnoreComboMask

Description
Determine if bindings of this action should trigger any associated events if the bindings are not combos but a combo
button is currently pressed.
Definition
getIgnoreComboMask()
Return Values
stringencodedStringthe encoded string

clone

Description
Create a new InputAction instance with the same state as this instance.
Definition
clone()
Return Values
stringdecodedStringthe decoded string
ClonedInputActioninstance

toString

Description
Get a string representation for this InputAction.
Definition
toString()
Return Values
tablecopythe copied table

InputBinding

Description
Input binding manager.
-- Loads and saves action input bindings and provides action trigger information.
-- Methods of note (see the documentation of the actual methods for more detailed descriptions):
registerActionEvent() Register an event callback for an action (for action values, see InputAction.lua)
removeActionEvent() Removes a previously registered event. Also see removeActionEventsByTarget().
setActionEvent...() Group of methods to adjust event states, e.g. activity or input display hint parameters.
-- Input event usage scenarios:
1. Long lifetime components / much interaction: Register event at creation of a component, modify event in component
update method depending on its state, remove event at component destruction
2. Short lifetime components / little interaction: Register event when necessary (e.g. when in range of an object),
remove again when no interaction is possible anymore
-- Player input settings are loaded from the file "inputBindings.xml" in their profile directory. If the file is not
present or corrupted whenever input is loaded, it will be restored from a suitable template. If a binding of a locked
action is changed directly on the file system, it will be overwritten with its template counterpart on the next
loading call to ensure that critical inputs are always available (e.g. menu navigation).
--@category Input

new

Description
Create the InputBinding instance.
Definition
new(table logManager, table modManager, table messageCenter, bool isConsoleVersion)
Arguments
tablelogManagerLogManager reference
tablemodManagerModManager reference
tablemessageCenterMessageCenter reference
boolisConsoleVersionIf true, the game is running on console
Return Values
tablecopythe copied table
tableInputBindinginstance

load

Description
Load the input binding configuration.
Definition
load(bool isInitializing, bool forceDefaultBindings)
Arguments
boolisInitializing[optional, default=false] If true, loads the input bindings in initialization mode and
saves at the end of loading to store any resolved device IDs to the user settings.
boolforceDefaultBindings[optional, default=false] If true, will forcibly load default bindings and override
any user input settings.
Return Values
booleanisElementOfListtrue if element is part of the list, else false

loadDefaultBindings

Description
Load default input bindings.
Will apply defaults for newly connected devices or override all bindings with template defaults if requested.
Definition
loadDefaultBindings(bool forceReplace)
Arguments
boolforceReplace[optional, default=false] If true, will overwrite all user bindings with the default templates.
Return Values
integerindexindex of first occurrence

loadModActions

Description
Load actions defined by mods.
Definition
loadModActions()
Return Values
booleanareEqualtrue if lists are equal, else false

loadModBindingDefaults

Description
Load default mod input binding data.
Definition
loadModBindingDefaults()
Return Values
anyvaluevalue of the random element

assignPlatformBindingPaths

Description
Assign bindings configuration file paths depending on platform and devices.
Definition
assignPlatformBindingPaths()
Return Values
tablesetthe converted set

overwriteSettingsWithDefault

Description
Overwrites user input settings with the default template.
Definition
overwriteSettingsWithDefault(forceOverwrite If)
Arguments
forceOverwriteIftrue, will overwrite an existing settings file. If false, will only perform the operation if no user settings are present.
Return Values
tablelistthe converted list

restoreInputContexts

Description
Restore input contexts after reloading the input settings, e.g. when devices change.
Definition
restoreInputContexts()
Return Values
tablehashthe converted hash

setShowMouseCursor

Description
Set the visibility state of the mouse cursor.
Definition
setShowMouseCursor(bool doShow, bool saveCursorPosition)
Arguments
booldoShowIf true, the cursor will be shown. Otherwise, it will be hidden.
boolsaveCursorPosition[optional] If true, saves the current cursor position to restore when showing it again
Return Values
booleanareEqualtrue if sets are equal, else false

getShowMouseCursor

Description
Determine if the mouse cursor is currently being shown.
Definition
getShowMouseCursor()
Return Values
booleanisSubsettrue if set1 is a subset of set2

getInputHelpMode

Description
Get the current input help mode for the input hint display.
If the input help mode has been set to automatic, the last button or key input will determine which device scheme
is used.
Definition
getInputHelpMode()
Return Values
booleanisSubsettrue if set1 is a real subset of set2
GS_INPUT_HELP_MODE_KEYBOARDorGS_INPUT_HELP_MODE_GAMEPAD

getLastInputMode

Description
Get the current input mode, independent of input help mode settings.
Definition
getLastInputMode()
Return Values
booleanhasIntersectiontrue if set1 and set2 have an intersection
GS_INPUT_HELP_MODE_KEYBOARDorGS_INPUT_HELP_MODE_GAMEPAD

validateActionEventParameters

Description
Validate parameters for registerActionEvent().
Prints warnings if there are problems and returns the validation status.
Definition
validateActionEventParameters()
Return Values
tableintersectionthe intersection of both sets
Trueifthe parameters are valid, false otherwise.

registerActionEvent

Description
Register an event callback for an input action.
Use InputAction constants for action names. At least one of the trigger parameters must be set to true to receive
events. This methods also checks if there would be any input binding collision when an event is added for the given
action. If there are any collisions, the registration will fail.
-- Note the interaction of the "down" and "always" triggers: If "down" is set and not "always", only an input down-flank
will raise an event. If both "down" and "always" are set, an event is raised as long as the input is pressed beyond a
threshold. If only "always" and not "down" is set, an event will be raised on each frame with the current input value
even if no input is active.
-- @param string actionName Name of action, see InputAction
Definition
registerActionEvent(table targetObject, function eventCallback, bool triggerUp, bool triggerDown, bool triggerAlways, bool startActive, table callbackState)
Arguments
tabletargetObjectEvent target, first argument to event callback
functioneventCallbackEvent callback, called when the action has input. Signature: callback(targetObject, actionName, inputValue, callbackState)
booltriggerUpIf true, the event fires once when an input signal of the given action goes to "up" state, e.g. a released key.
booltriggerDownIf true, the event fires once when an input signal of the given action goes to "down" state, e.g. a pressed key.
booltriggerAlwaysIf true, the event fires on any signal input change, potentially every frame. This is mostly useful for required continuous axis input, e.g. steering actions.
boolstartActive[optional] If true, the event is active right after registration and will be checked for input collisions. Otherwise, set its activation state using InputBinding:setActionEventActive() and handle collisions yourself.
tablecallbackState[optional] An arbitrary value or reference which serves as a closure state within callbacks, useful e.g. when checking input state between events without requiring additional class fields.
Return Values
tablesubstractionthe substraction of both set
boolTrueif the event could be registered, false otherwise
stringeventID if successful, empty string otherwise
tableActionreference of a colliding action if there would be a collision, nil otherwise

checkEventCollision

Description
Check if adding an event for a given action name would cause colliding input bindings to be active.
Definition
checkEventCollision(string actionName)
Arguments
stringactionNameName of an InputAction
Return Values
tableunionthe union of both sets
boolTrueif there would be a collision, false otherwise
tableCollidingaction if there would be a collision, nil otherwise

beginActionEventsModification

Description
Start registering action events in a given context.
This method must be accompanied by a finalizing call to InputBinding:endActionEventsModification() when registration is
complete. While a registration context is set, all calls to InputBinding:registerActionEvent() will add events to
that context. Also, derived event collections (i.e. data structures for display and fast iteration) will only be
updated when InputBinding:endActionEventsModification() is called instead of each time an event is added.
If no context with the given name exists, a new empty one will be created and added to the known contexts.
Definition
beginActionEventsModification(string inContext, bool createNew)
Arguments
stringinContextName of the input context which receives any registered events until endActionEventsModification is called.
boolcreateNew[optional, default=false] If true, will create a new context of the given name, potentially overwriting any existing one.
Return Values
tablefilteredlist (non-deep copy)

endActionEventsModification

Description
End registering action events in a context.
Resets the registration context set in InputBinding:beginActionEventsModification() for any later registrations.
Definition
endActionEventsModification()
Return Values
tablefilteredlist (non-deep copy)

refreshEventCollections

Description
Refresh derived event collections for retrieval purposes.
Definition
refreshEventCollections()
Return Values
integersignthe sign of the value

storeDisplayActionEvents

Description
Store an array of action-event tuples for all action events which need an input hint display.
Definition
storeDisplayActionEvents()
Return Values
booleantrueif value is nan else false

storeEventBindings

Description
Store all bindings associated with registered and active events in collections for iteration.
Definition
storeEventBindings()
Return Values
numberrountedvalue

iterateEvents

Description
Iterates the action event collection, calling a given function on each event.
If the processing function returns a "truthy" value, the iteration is stopped.
Definition
iterateEvents(processingFunction function(event,)
Arguments
processingFunctionfunction(event,actionName, actionEventList, actionEventListIndex)
Return Values
floatvalueradian angle

removeEventInternal

Description
Internal function for event removal.
Definition
removeEventInternal()
Return Values
floatvalueinterpolated value

removeActionEvent

Description
Remove a previously registered action event by ID.
Definition
removeActionEvent(eventId Event)
Arguments
eventIdEventID as returned by registerActionEvent().
Return Values
floatvalueinterpolated value

removeActionEventsByActionName

Description
Remove all previously registered action events which are triggered by an action identified by name.
Definition
removeActionEventsByActionName(actionName If)
Arguments
actionNameIfan event is triggered by the action of that name, it is removed.
Return Values
floatalphaalpha

removeActionEventsByTarget

Description
Remove all previously registered action events which have a given target.
Definition
removeActionEventsByTarget(targetObject If)
Arguments
targetObjectIfan event has this object as a target, it is removed.
Return Values
floatvaluevalue

getDisplayActionEvents

Description
Get action-event tuples for registered events which require an input hint.
Note that the data is live and should be treated as read-only.
Definition
getDisplayActionEvents()
Return Values
floatisOutOfBoundsis out of bounds
arrayoftuples: {i={action=InputAction, event=InputEvent}}

setActionEventText

Description
Set a specific action text to display as an input hint for a given event.
Use this to adjust display texts depending on context, e.g. "Attach" / "Detach" for the vehicle attach action.
Additionally, it serves as a way to display neutral full axis action names, e.g. "Move player" instead of any
specific label depending on the input direction.
Definition
setActionEventText(eventId ID, actionText Localized)
Arguments
eventIdIDof a registered event
actionTextLocalizeddisplay text for the event's action
Return Values
floatvaluethe floored percent value

setActionEventIcon

Description
Set the name of an icon to display as an input hint instead of text for a given event.
If an icon has been specified for an event with this function, any text setting will have no effect.
Definition
setActionEventIcon(eventId ID, iconName Input)
Arguments
eventIdIDof a registered event
iconNameInputhint icon name as defined in axisIcons.xml or InputHelpElement.AXIS_ICON
Return Values
floatvaluethe floored clamped value

setActionEventTextVisibility

Description
Set the visibility of an action event input hint display.
The most basic controls, such as player movement, do not need any input hints and can be hidden this way. If more
than one event is registered on an action, make sure to only set one of them to visible. The system will
automatically set all events after the first per action to invisible to ensure a valid ground state.
Definition
setActionEventTextVisibility(eventId ID, isVisible If)
Arguments
eventIdIDof a registered event
isVisibleIffalse, hides the input hint for this event. Default is visible.
Return Values
floatanglethe resized angle in the range -pi to pi

setActionEventTextPriority

Description
Set the priority of an action event input hint display.
Use any of the following script constants: GS_PRIO_VERY_HIGH, GS_PRIO_HIGH, GS_PRIO_NORMAL, GS_PRIO_LOW,
GS_PRIO_VERY_LOW. Higher priority will be shown first in the input hint display box.
Definition
setActionEventTextPriority(eventId ID, priority Priority)
Arguments
eventIdIDof a registered event
priorityPrioritynumber value, lower is more important. Use GS_PRIO_[...] constants.
Return Values
floatanglethe radian difference in range -pi to pi

setActionEventActive

Description
Set the active state of an action event.
Only active events can be triggered by input and be displayed as input hints.
Definition
setActionEventActive(eventId ID, isActive New)
Arguments
eventIdIDof a registered event
isActiveNewactive state
Return Values
floatlengthlength

setActionEventsActiveByTarget

Description
Set the active state of all action events targeting a given object.
Only active events can be triggered by input and be displayed as input hints.
Definition
setActionEventsActiveByTarget(targetObject Action, isActive New)
Arguments
targetObjectActionevent target object
isActiveNewactive state
Return Values
floatlengthsquare length

getComboCommandPressedMask

Description
Get the combo input masks for any currently active gamepad and mouse combo inputs.
The returned masks are bit-wise combined masks made from the InputBinding.COMBO_MASK_[...] constants.
Definition
getComboCommandPressedMask()
Return Values
floatxnormalized x
floatynormalized y
Gamepadcombomask, Mouse combo mask

getComboActionNameForAxisSet

Description
Get the combo action name for a given set of modifier axes.
Definition
getComboActionNameForAxisSet()

getInternalIdByDeviceId

Description
Resolve a device ID sting to the engine-internal integer ID.
Definition
getInternalIdByDeviceId()
Return Values
floatlengthlength

getDeviceByInternalId

Description
Retrieve an InputDevice by its internal device ID.
Definition
getDeviceByInternalId(internalDeviceId Internally)
Arguments
internalDeviceIdInternallyassigned device ID (= device index assigned by engine, zero based)
Return Values
floatlengthsquare length
InputDeviceinstanceor nil if ID is invalid

assignLastInputHelpMode

Description
Assign an input help mode as the last used mode.
This triggers a message center notification to all subscribed components if the input help mode has changed.
Definition
assignLastInputHelpMode()
Return Values
floatxnormalized x
floatynormalized y
floatznormalized z

startBindingChanges

Description
Prepare for incoming binding changes.
Must be called before InputBinding:startInputCapture() to guarantee a valid state.
Definition
startBindingChanges()

commitBindingChanges

Description
Commit all binding changes since the last call to InputBinding:startBindingChanges().
Accepts the current, modified binding state and notifies any change listeners.
Definition
commitBindingChanges()

rollbackBindingChanges

Description
Rolls back all binding changes since the last calls to InputBinding:startBindingChanges().
Definition
rollbackBindingChanges()
Return Values
floatxscaled x
floatyscaled y
floatzscaled z

startInputCapture

Description
Capture all input and run a callback if input has been received on a device.
Overrides the global input event functions.
Definition
startInputCapture(isKeyboard True, isMouse True, callbackTarget If, callbackState Free, inputCallback Called, abortCallback Called, deleteCallback Called)
Arguments
isKeyboardTrueif target device is keyboard input
isMouseTrueif target device is mouse input
callbackTargetIfspecified, will be supplied as the first argument to the callback function (usually caller self)
callbackStateFreeparameter which is returned with callbacks to the callback target
inputCallbackCalledwhen the target device receives input. function(deviceId, inputAxisName, isModifier, inputValue, callbackState)
abortCallbackCalledwhen an abort input is received on any device. function()
deleteCallbackCalledwhen a delete input is received on any device. function(callbackState)

captureKeyboardInput

Description
Capture keyboard input.
Fires an input callback as soon as a key is pressed. Modifier keys (e.g. shift, alt) only trigger callbacks when
they are pressed alongside a regular key. Modifier callbacks always arrive before non-modifier key callbacks.
Definition
captureKeyboardInput(abortCallback function(), deleteCallback function(), inputCallback function(deviceId,)
Arguments
abortCallbackfunction()to be called when the abort key is pressed
deleteCallbackfunction()to be called when the delete key is pressed
inputCallbackfunction(deviceId,axisName, isModifier, inputValue), see startInputCapture()

captureMouseInput

Description
Capture mouse input.
Axis input continuously fires callbacks while the player is moving the mouse. Button callbacks are triggered once
when a mouse button is held down and again when it is released.
Definition
captureMouseInput(callback function(deviceId,)
Arguments
callbackfunction(deviceId,axisName, isModifier, inputValue), see startInputCapture()
Return Values
floatxclamped x
floatyclamped y
floatzclamped z

captureGamepadInput

Description
Capture gamepad / controller input.
Continously fires callbacks for all known gamepad buttons and axes for each frame.
Definition
captureGamepadInput(callback function(deviceId,)
Arguments
callbackfunction(deviceId,axisName, isModifier, inputValue), see startInputCapture()

stopInputGathering

Description
Stop the current input gathering run.
Restores global input event functions.
Definition
stopInputGathering()

restoreDefaultBindings

Description
Restore default bindings
Definition
restoreDefaultBindings()
Return Values
floatxinterpolated x
floatyinterpolated y
floatzinterpolated z

clearState

Description
Clear relevant state for loading and resetting.
Definition
clearState()

loadActions

Description
Load input actions which are later bound to input axes.
Definition
loadActions(xmlFile Action, modName [optional])
Arguments
xmlFileActiondefinition XML file handle
modName[optional]Name of the mod which defines actions. If not set, actions are assumed to be default game actions.

resetDeviceInformation

Description
Reset stored device information.
Clears all device information and returns the previous device list for comparisons. Call this for
initialization and before enumerating system devices.
Definition
resetDeviceInformation()
Return Values
floatxinterpolated x
floatyinterpolated y
floatzinterpolated z
previousDevicesTableof internal ID -> InputDevice before the current initialization

createDefaultDevices

Description
(Re-)Creates the internal keyboard and mouse virtual device.
Definition
createDefaultDevices()

enumerateGamepadDevices

Description
Find gamepad devices in the system and store their information.
Definition
enumerateGamepadDevices(previousDevices Table)
Arguments
previousDevicesTableof internal ID -> InputDevice before the current initialization

getGamepadDevices

Description
Get a list of recognized gamepad (and other controller) input devices.
Definition
getGamepadDevices()
Return Values
floatxtransformed x
floatytransformed y
floatztransformed z
Listofdevice information tables, format: {deviceId=[device ID], name=[device name]}

loadDeviceSettingsFromXML

Description
Load device input settings (other than bindings) from an input binding XML file.
Definition
loadDeviceSettingsFromXML(xmlFile XML)
Arguments
xmlFileXMLfile handle

applyGamepadDeadzones

Description
Apply deadzone settings to all gamepad device axes.
If no deadzone value had been configured for a valid axis, the global default deadzone value is applied.
Definition
applyGamepadDeadzones()

initializeGamepadMapping

Description
Initialize gamepad settings from XML.
Definition
initializeGamepadMapping()
Return Values
dotthedot product

validateAndRepairComboActionBindings

Description
Check if combo action bindings are valid and restore proper bindings if necessary.
Definition
validateAndRepairComboActionBindings()
Return Values
floatxx
floatyy
floatzz

loadActionBindingsFromXML

Description
Load bindings of actions to input axes from a configuration XML file.
Definition
loadActionBindingsFromXML(xmlFile Configuration, silentIgnoreDuplicates [optional], modName [optional], doNotReplace [optional])
Arguments
xmlFileConfigurationXML file handle
silentIgnoreDuplicates[optional]If true, will not give a warning on duplicate bindings and just ignore them
modName[optional]Name of the mod for which action bindings are loaded. If not set, will load bindings for the default game.
doNotReplace[optional]If true, will not replace existing bindings with a loaded ones

loadBindingsFromXML

Description
Load all bindings within an XML actionBindings definition element.
Definition
loadBindingsFromXML()

storeComboInputMappings

Description
Store input axis names of combo command actions for combo mask checking.
Definition
storeComboInputMappings()
Return Values
floatyrotation

getBindingComboMask

Description
Get a combo modifier mask for a binding.
Because input axis names are different, this is safe to use for any binding as long as the calling context sticks
to either gamepad or mouse input bindings to check.
Definition
getBindingComboMask(Binding Binding)
Arguments
BindingBindinginstance
Return Values
floatxx direction
floatzz direction
Modifierbitmask

assignComboMasks

Description
Assign combination input bitmasks on actions based on their bindings.
This will update all actions and should be run whenever any binding changes. Axis inputs will have two valid bindings
for modifiers (component + and -). Ensure that players cannot set differently modified inputs on a single axis
action.
Definition
assignComboMasks()

storeLinkedBindings

Description
Store binding links based on connections set in InputAction.LINKED_ACTIONS.
Definition
storeLinkedBindings()
Return Values
floatxlimited x direction
floatzlimited z direction

assignActionPrimaryBindings

Description
Assign primary keyboard bindings to actions if applicable.
Definition
assignActionPrimaryBindings()

adjustBindingSlotIndex

Description
Adjust a binding's slot index.
Definition
adjustBindingSlotIndex(Binding Binding, usedSlots Set)
Arguments
BindingBindingto adjust
usedSlotsSetof used slot indices for the binding's context (action, device, axis)
Return Values
floatxx position
floatxz position

resolveBindingDevice

Description
Resolve a binding's device ID to an engine-issued internal device ID.
Replaces default device IDs in bindings with the ID of the first device of the corresponding category. This
effectively binds default or template bindings to first devices. Also updates the binding's internal device ID field.
If a binding's device is missing, the method tries resolving a suitable replacement device. First, device IDs are
checked to see if the missing device simply changed order (and therefore its prefix). Then, the device names are
compared. If no identifiers match, the binding is assigned to the first device of the category of the missing device.
If all else fails, the binding is assigned to the first controller, possibly losing some bindings due to collisions.
Definition
resolveBindingDevice(Binding Binding)
Arguments
BindingBindingwhose device ID is checked and replaced, if necessary
Return Values
Trueifthe binding's device ID could be resolved, false otherwise

resolveFirstDeviceOfCategoryToBinding

Description
Resolve and assign the first device of a given category to a binding.
Definition
resolveFirstDeviceOfCategoryToBinding()
Return Values
floatdotproduct

resolveSameIdDeviceWithPrefixToBinding

Description
Resolve and assign the last device with a given base ID (without prefix) to a binding.
Definition
resolveSameIdDeviceWithPrefixToBinding()
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

resolveMissingDeviceByNameToBinding

Description
Resolve and assign the last device with a given name to a binding.
Definition
resolveMissingDeviceByNameToBinding()

resolveDefaultDeviceToBinding

Description
Resolve and assign the first known device to a binding.
Definition
resolveDefaultDeviceToBinding()

checkBindings

Description
Run a a list of functions on all known bindings in the context of a given action if provided.
The functions' return values are written to a results table which is returned at the end. Callers can retrieve
function results by indexing the results table with the corresponding function reference.
Definition
checkBindings(action Action, checkFunctions List)
Arguments
actionActionreference for the current context, e.g. check bindings for an action
checkFunctionsListof functions with the signature function(Binding), return [bool hasResult], result
Return Values
functionresultstable {checkFunctionRef=[functionResult]}

validateBinding

Description
Validate a new binding before it's added to the system.
Returns boolean flags for constraints and a colliding binding if there was one.
Definition
validateBinding(Binding New)
Arguments
BindingNewbinding instance
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

addBinding

Description
Add a new input binding.
Checks for duplicates and collisions and stores the binding only if everything's okay.
Definition
addBinding(table binding, bool silentIgnoreDuplicates, bool doNotReplace)
Arguments
tablebindingNew binding
boolsilentIgnoreDuplicatesIf true, will not print warnings on duplicate bindings
booldoNotReplaceIf true, will not replace existing bindings
Return Values
boolTrueif the new binding could be added
tableReferenceto an Action containing a binding which collided with the added binding or nil

updateBinding

Description
Update an existing binding with new device ID, input axes and input component data.
Definition
updateBinding(findDeviceId Binding, findActionName Name, findBindingIndex Binding, findAxisComponent Logical, deviceId New, axisNames List, inputComponent Physical)
Arguments
findDeviceIdBindingdevice ID
findActionNameNameof binding action
findBindingIndexBindingindex, 1 primary, 2 secondary, etc.
findAxisComponentLogicalbinding axis direction component to assign, always positive for buttons/keys/half-axes
deviceIdNewdevice ID
axisNamesListof new input axis names
inputComponentPhysicalinput axis direction component to bind (direction of last axis in axisNames)
Return Values
Trueifa binding could be found and updated, false if there was a collision
BindingandAction reference of a collision as {collisionBinding=Binding, collisionAction=Action} or nil

deleteBinding

Description
Delete a binding.
Definition
deleteBinding(findDeviceId Binding, findActionName Name, findBindingIndex Binding, findAxisComponent Logical)
Arguments
findDeviceIdBindingdevice ID
findActionNameNameof binding action
findBindingIndexBindingindex, 1 primary, 2 secondary, etc.
findAxisComponentLogicalbinding axis direction component to assign, always positive for buttons/keys/half-axes

getKeyboardMouseInputActiveAndValue

Description
Check if a keyboard or mouse input is active.
Definition
getKeyboardMouseInputActiveAndValue(axes List, axisDirection 1, inputDirection 1)
Arguments
axesListof input axis names which are all required to be pressed for the input to be active
axisDirection1or -1, determining the direction of the bound logical axis.
inputDirection1or -1, determining the direction of the requested physical axis component.
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion
Trueifall given axes are currently active, input value of the non-modified axis (last in list)

getGamepadInputActiveAndValue

Description
Scan gamepad / controller binding input.
Both buttons and controller physical axes are checked for a given device and list of logical axes.
Definition
getGamepadInputActiveAndValue(internalDeviceId Engine-internal, axes List, axisDirection 1, inputDirection 1)
Arguments
internalDeviceIdEngine-internaldevice ID of device to scan
axesListof axis names to scan
axisDirection1or -1, determining the direction of the bound logical axis component.
inputDirection1or -1, determining the direction of the requested physical axis component.
Return Values
Trueifall axes are active (digital interpretation), input value of the non-modified axis (last in list)

getGamepadAxisValue

Description
Scan a controller axis on a device for input.
Definition
getGamepadAxisValue()
Return Values
Inputvalueof the axis in the range [-1, 1] for full axes or [0, 1] for half axes.

update

Description
Update input for the current frame.
Definition
update(dt Delta)
Arguments
dtDeltatime in milliseconds

checkGamepadActive

Description
Check if any gamepad button or axis is pressed and set the input help mode if necessary.
Definition
checkGamepadActive()
Return Values
floatrotationthe final rotation

updateMouseInput

Description
Update mouse input state.
Definition
updateMouseInput()
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

finalizeMouseInput

Description
Finalize mouse input processing for the current frame.
Wraps the mouse position around if required and resets movement accumulators.
Definition
finalizeMouseInput()

clearActiveBindingBuffer

Description
Clear an active binding buffer for re-use to avoid table allocation each frame.
Automatically adds device entries if new devices are added.
Definition
clearActiveBindingBuffer()

updateEventBindings

Description
Update input bindings associated with all registered and active events.
Definition
updateEventBindings()

hasBindingForPressedMouseComboMask

Description
Check if there is currently any binding matching the pressed mouse combo mask.
This is used to override the combo mask ignore flag for mouse look in special cases. E.g. when rotating a tool axis
with a mouse dragging movement, mouse look should be disabled for the other axis as well, even if it has no active
binding with the same combo button (which would have been handled by input shadowing).
Definition
hasBindingForPressedMouseComboMask()
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

shadowLinkedBindings

Description
Apply binding input shadow flag to bindings of linked actions for currently active input.
Definition
shadowLinkedBindings()

updateComboBindings

Description
Update binding input for combo action bindings.
Definition
updateComboBindings()

updateInput

Description
Update input bindings with the current input state and trigger events.
Definition
updateInput()

updateBindingInput

Description
Update the input state of a single action-to-input binding.
Definition
updateBindingInput()
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

resetContinuousEventBindings

Description
Reset binding input state for bindings used in continuous trigger events.
Definition
resetContinuousEventBindings(bool checkComboMasks, int gamepadComboMask, int gamepadMouseMask)
Arguments
boolcheckComboMasks[optional, default=false] If true, checks binding combo masks against provided parameters
intgamepadComboMask[optional] Gamepad combo input bit mask
intgamepadMouseMask[optional] Mouse combo input bit mask

neutralizeEventBindingInput

Description
Set an event's binding's input to a neutral value and notify the event's listeners of that neutral position.
Definition
neutralizeEventBindingInput()

updateDebugDisplay

Description
Update and debug information display.
Definition
updateDebugDisplay()

saveToXMLFile

Description
Save action bindings to player custom settings.
Definition
saveToXMLFile()
Return Values
floatdistancedistance to rectangle

saveDeviceSettings

Description
Save all device settings.
Updates and adds settings for active devices.
Definition
saveDeviceSettings(xmlFile Input)
Arguments
xmlFileInputsettings XML file handle
Return Values
floatdistancedistance to line segment

getActionList

Description
Get a deep copy of the action definitions list.
Definition
getActionList()
Return Values
booleanhasIntersectiontrue if both lines intersect
floatt1x position
floatt2z position

getActionByName

Description
Get a loaded InputAction by name.
Only use the returned action to assign references and do not change its state.
Definition
getActionByName(actionName Name)
Arguments
actionNameNameof the action to be returned
Return Values
InputAction

disableAlternateBindingsForAction

Description
Disable alternate bindings for a given action.
This setting is only valid in the current input context and will be overwritten the next time any input event is
changed.
Definition
disableAlternateBindingsForAction(string actionName)
Arguments
stringactionNameInputAction name

setContext

Description
Set the current input context.
If no context of the given name exists, it will be created.
Definition
setContext(string name, bool createNew, bool deletePrevious)
Arguments
stringnameInput context name
boolcreateNew[optional, default=false] If true, will create a clear context with the given name, overriding any other with the same name.
booldeletePrevious[optional, default=false] If true, will delete the previous context after setting the new context.
Return Values
booleanhasIntersectiontrue if the line segment is completly in the rectangle OR if it intersects with one of the four rectangle sides

revertContext

Description
Revert the input context to the previously set input context.
Use this method only if you can guarantee a valid state, e.g. when calling setContext in a modal interaction context.
Definition
revertContext(bool deleteCurrent)
Arguments
booldeleteCurrent[optional, default=false] If true, will delete the current input context before reverting to the previous context.
Return Values
floatpos1Xx pos of intersection 1, else nil
floatpos1Yy pos of intersection 1, else nil
floatpos2Xx pos of intersection 2, else nil
floatpos2Zz pos of intersection 2, else nil

setPreviousContext

Description
Set the previous context for another context.
This modifies the previous context value which is used to revert input contexts.
Definition
setPreviousContext(string forContextName, string previousContextName)
Arguments
stringforContextNameName of the input context whose previous context will be set
stringpreviousContextNameNew previous context name

clearAllContexts

Description
Clear all contexts except the root.
The current context will also be set to root.
Definition
clearAllContexts()

getContextName

Description
Get the name of the current input context.
Definition
getContextName()

getActionBindingsCopy

Description
Get an ordered copy of the action bindings table for manipulation.
Definition
getActionBindingsCopy(onlyAssignable If)
Arguments
onlyAssignableIftrue, will only copy assignable action bindings
Return Values
booleanhasIntersectiontrue if spheres have an intersection else false
Orderedactionbindings in the form of {i={action=InputAction, bindings={Binding}}}

getActionBindings

Description
Get the current action bindings table.
The returned table is the current live state and can thus contain unconfirmed modifications. Treat the table as
read-only so as not to interfere with the correct workings of this class. Only use this getter for initializations
and otherwise rely on setBindingChangeCallback() to receive a confirmed working state.
Definition
getActionBindings()
Return Values
floatareaarea in hectars

getEventsForActionName

Description
Get an array of registered events in the current input context for a given action name.
Definition
getEventsForActionName(string actionName)
Arguments
stringactionNameAction name as valid in InputAction
Return Values
floatbrightnessbrightness
tableArrayof events

getFirstActiveEventForActionName

Description
Get the first active event in the current input context for a given action name.
Definition
getFirstActiveEventForActionName(string actionName)
Arguments
stringactionNameAction name as valid in InputAction
Return Values
floataverageSpeedaverage speed
tableFirstactive event or InputEvent.NO_EVENT

setMouseMotionScale

Description
Set the mouse motion scale.
The given scale factor is multiplied with the default mouse motion scale of 0.75 on the X and Y axes.
Definition
setMouseMotionScale(scale Mouse)
Arguments
scaleMousemotion scale factor
Return Values
floatspeedspeed

getMouseMotionScale

Description
Get the current mouse motion scale.
Definition
getMouseMotionScale()
Return Values
floatspeedRandomspeed random
xmotionscale, Y motion scale

setBindingChangeCallback

Description
Set a callback for binding changes.
The callback function must accept the action bindings table as a single argument.
Definition
setBindingChangeCallback(callback Callback)
Arguments
callbackCallbackfunction which takes a single table parameter in the form of {InputAction: {i=Binding}}
Return Values
floatnormalSpeednormal speed

setEventChangeCallback

Description
Set a callback for event changes.
The callback function must accept the action-event tuples in an array as a single argument.
Definition
setEventChangeCallback(callback Callback)
Arguments
callbackCallbackfunction which takes a single table parameter in the form of {i={action=InputAction, event=InputEvent}}
Return Values
floattangentSpeedtangent speed

notifyBindingChanges

Description
Notify a listener of binding changes.
The notification callback is set via setBindingChangeCallback().
Definition
notifyBindingChanges()
Return Values
floatspriteScaleXX sprite scale

notifyEventChanges

Description
Notify a listener of event changes.
The notification callback is set via setEventChangeCallback().
Definition
notifyEventChanges()
Return Values
floatspriteScaleYY sprite scale

notifyInputModeChange

Description
Notify components of an input mode change via the message center.
Definition
notifyInputModeChange()
Return Values
floatspriteScaleXGainX sprite scale gain

checkSettingsIntegrity

Description
Check if user input bindings are corrupted and compare input configuration XML file versions.
Definition
checkSettingsIntegrity()
Return Values
floatspriteScaleYGainY sprite scale gain
Trueifthe user settings have passed the integrity check, false otherwise.

checkDefaultInputExclusiveActionBindings

Description
Checks loaded default input bindings according to exclusive locked action groups defined in InputAction.
This is a developer check to verify critical input plausibility.
Definition
checkDefaultInputExclusiveActionBindings()
Return Values
Trueifthere is a collision, false otherwise

getIsPhysicalFullAxis

Description
Determine if an axis name represents a physical full axis on any device.
Definition
getIsPhysicalFullAxis(inputAxisName Axis)
Arguments
inputAxisNameAxisname
Return Values
objectinstance or nil if no object could be created
Trueifno placeable object could be created at the requested position because there was no valid space, false otherwise
Trueifthe axis name represents a physical full axis, false otherwise

getIsHalfAxis

Description
Determine if an axis name represents a physical half-axis on any device.
Definition
getIsHalfAxis(inputAxisName Axis, True if)
Arguments
inputAxisNameAxisname
Trueifthe axis name represents a physical half-axis, false otherwise

getIsAnalogInput

Description
Determine if an input name represents an analog (i.e. continuous) physical input.
Definition
getIsAnalogInput(inputName Input)
Arguments
inputNameInputname (potentially a key, button or axis identifier)
Return Values
objectinstance or nil if no object could be created
Trueifno placeable object could be created at the requested position because there was no valid space, false otherwise
Trueifthe input name represents an analog input

getIsKeyboardInput

Description
Determine if an input name list represents keyboard input.
Definition
getIsKeyboardInput()

getIsMouseInput

Description
Determine if an input name list represents mouse input.
Definition
getIsMouseInput()
Return Values
floatRayorigin X position in world space
floatRayorigin Y position in world space
floatRayorigin Z position in world space
floatRaydirection X component
floatRaydirection Y component
floatRaydirection Z component

getIsMouseWheelInput

Description
Determine if an input name list represents a single mouse wheel step input.
Definition
getIsMouseWheelInput()

getIsGamepadInput

Description
Determine if an input name list represents gamepad / controller input.
Definition
getIsGamepadInput()

getIsDPadInput

Description
Check if an input name list represents a single D-Pad input.
Definition
getIsDPadInput()

isAxisZero

Description
Check if the input value of an axis can be considered zero.
Definition
isAxisZero(value Axis)
Arguments
valueAxisinput value
Return Values
Trueifthe axis is at zero position, false otherwise

getMaximumBindingCountForDeviceId

Description
Get the maximum number of bindings per action for a given device ID.
Definition
getMaximumBindingCountForDeviceId()

getDeviceCategory

Description
Get the device category for a device identified by its engine-internal ID
Definition
getDeviceCategory()
Return Values
any_typeunpackedValuesreturns unpacked values found in string

InputDevice

Description
Game input device.
-- The class stores name and IDs of a device as well as physical to logical key / button / axis mappings.
--@category Input
--@xmlConfig device#id Device ID, must match a value returned by engine function getGamepadId() or one of the constants
of InputDevice.DEFAULT_DEVICE_NAMES.

new

Description
Create a new InputDevice instance.
Definition
new(internalId Internal, deviceId Device, deviceName Device, category Device)
Arguments
internalIdInternaldevice ID as issued by the engine (~ device index)
deviceIdDeviceID as received by the operating system
deviceNameDevicename as assembled by the engine
categoryDevicecategory, use one of the values of InputDevice.CATEGORY
Return Values
tablevaluesvalues
NewInputDeviceinstance

loadSettingsFromXML

Description
Load device settings from an XML file.
This will load settings other than input bindings, e.g. sensitivity for gamepad axes.
Definition
loadSettingsFromXML(xmlFile XML, deviceElement XML)
Arguments
xmlFileXMLfile handle
deviceElementXMLdata element for this device
Return Values
tablevaluesradian values

saveSettingsToXML

Description
Save device settings to an XML file.
Definition
saveSettingsToXML(xmlFile XML, deviceElement XML)
Arguments
xmlFileXMLfile handle
deviceElementXMLdata element for this device
Return Values
tableresulttext elements

isController

Description
Determine if this device is a controller/gamepad.
Definition
isController()
Return Values
booleanstartsWidthtrue if given string starts with pattern else false

loadIdFromXML

Description
Load a device's ID from an XML file.
Definition
loadIdFromXML(xmlFile XML, deviceElement XML)
Arguments
xmlFileXMLfile handle
deviceElementXMLdata element for this device
Return Values
booleanstartsWidthtrue if given string ends with pattern else false
DeviceIDor empty string

loadNameFromXML

Description
Load a device's name from an XML file.
Definition
loadNameFromXML(xmlFile XML, deviceElement XML)
Arguments
xmlFileXMLfile handle
deviceElementXMLdata element for this device
Return Values
stringtrimedStringtrimed text
Devicenameor empty string

loadCategoryFromXML

Description
Load a device's category from an XML file.
Definition
loadCategoryFromXML(xmlFile XML, deviceElement XML, Device category)
Arguments
xmlFileXMLfile handle
deviceElementXMLdata element for this device
Devicecategory
Return Values
any_typevaluenot nil value

getDeviceIdPrefix

Description
Get a device ID prefix' numeric value, if it exists.
Definition
getDeviceIdPrefix()
Return Values
floatlxx direction
floatlzz direction
Prefixnumber,or -1 if none exists; raw engine-issued device ID

getPrefixedDeviceId

Description
Get a device ID prefixed with a given number.
Definition
getPrefixedDeviceId()

toString

Description
Get a string representation for this device.
Definition
toString()
Return Values
floatlxaverage x direction
floatlzaverage z direction

InputDisplayManager

Description
Bridge-component between input handling and UI.
-- Serves data and display elements for input controls. Accesses InputBinding data and is being accessed by UI
components.
--@category Input

load

Description
Load the required base data for this manager.
Loads controller symbols / UI overlays.
Definition
load()

setDevGamepadLabelMapping

Description
Set up development-only gamepad label function if necessary.
Definition
setDevGamepadLabelMapping()
Return Values
booleanisAttachedis attached

loadControllerSymbolsAndOverlays

Description
Load controller symbols and create UI overlays.
Reads a UV values from an XML configuration to create UI overlays from a texture atlas.
Definition
loadControllerSymbolsAndOverlays()
Return Values
booleandoesBlockimplement does block

createButtonOverlay

Description
Create a single button overlay.
Definition
createButtonOverlay()
Return Values
integeraiToolReverserDirectionNodereverser direction node of ai tool

loadAxisIcons

Description
Load vehicle axis input hint icons.
The icons are kept in memory as overlays until the game is closed.
Definition
loadAxisIcons(xmlFile XML, modPath [optional])
Arguments
xmlFileXMLfile handle
modPath[optional]Path to loaded mod, will load defaults if set to nil
Return Values
floatmaxTurnRadiusmax turn radius

loadModAxisIcons

Description
Load axis icons defined by mods.
Definition
loadModAxisIcons()
Return Values
floatleftAreaPercentageleft area percentage
floatrightAreaPercentageright area percentage

addContextBindings

Description
Add bindings of an action to a list if they fit the required context (gamepad or keyboard and mouse),
Definition
addContextBindings(contextBindings Bindings, action InputAction, isContextGamepad If)
Arguments
contextBindingsBindingslist for the required context
actionInputActionreference
isContextGamepadIftrue, we require gamepad bindings. Otherwise, keyboard and mouse is needed.

getActionBindingsForContext

Description
Get bindings from one or two actions for the current input context (either gamepad or keyboard and mouse).
Definition
getActionBindingsForContext()
Return Values
floatareaarea found
floattotalAreatotal area checked

getKeyboardBindings

Description
Get bindings for one or two actions for keyboard input, exclusively.
Definition
getKeyboardBindings()

resolveModifierSymbols

Description
Resolve modifier symbols and add them to an overlays collection.
Definition
resolveModifierSymbols(table overlays, table separators, table firstContextBinding)
Arguments
tableoverlaysOverlays collection which receives resolved modifier symbols
tableseparatorsArray of separator types inbetween symbols
tablefirstContextBindingBinding reference
Return Values
floatareaarea found
floattotalAreatotal area checked

resolveAccumulatedSymbolPermutations

Description
Recursively permutate symbol names to resolve dynamically ordered names to fixed definitions.
Definition
resolveAccumulatedSymbolPermutations()

resolveUnmodifiedSymbols

Description
Resolve unmodified binding axis names to symbol overlays and add those to the given overlays collection.
Definition
resolveUnmodifiedSymbols(table overlays, table contextBindings, bool isContextGamepad)
Arguments
tableoverlaysOverlays collection which receives resolved symbols
tablecontextBindingsArray of Binding instances
boolisContextGamepadIf true, resolve gamepad symbols. Otherwise, resolve mouse symbols.
Return Values
floatareaarea found
floattotalAreatotal area checked

addRegularSymbols

Description
Add regular input display symbols to an overlays array.
Definition
addRegularSymbols()

addComboSymbols

Description
Add combo input display symbols to an overlays array.
Definition
addComboSymbols()
Return Values
tableinstanceinstance of object

getControllerSymbolOverlays

Description
Get input symbol overlays for one or two actions.
Use the second action parameter to display complementary actions, e.g. action1 is moving forward/backward, action 2
is moving left/right.
Definition
getControllerSymbolOverlays(actionName1 First, actionName2 [optional])
Arguments
actionName1Firstaction name as defined and/or loaded in InputAction
actionName2[optional]Second action name as defined and/or loaded in InputAction
Return Values
integernumOfConfigurationTypesnumber of configuration types
InputHelpElementinstancecontaining the symbol overlays in its "buttons" field

requireSymbolAccumulation

Description
Determine if an action and bindings combinations requires their input symbols to be accumulated to get a combined
symbol for better display.
Definition
requireSymbolAccumulation()
Return Values
integernumOfConfigurationTypesnumber of configuration types

makeHelpElement

Description
Make a help element to display in the HUD.
Definition
makeHelpElement()
Return Values
stringnamename of config

onActionEventsChanged

Description
Called when action events in the input system have changed.
Definition
onActionEventsChanged(displayActionEvents Array)
Arguments
displayActionEventsArrayof action-event tuples which require an input hint display, {i={action=InputAction, event=InputEvent}}
Return Values
integerindexindex of config

sortEventHelpElements

Description
Table sorting function for event help elements.
Priority > primaryKeyboardInput > text
Definition
sortEventHelpElements()
Return Values
tableconfigurationconfiguration

sortEventHelpElementsGamepad

Description
Sorting function for gamepad mode
Definition
sortEventHelpElementsGamepad()
Return Values
any_typevaluevalue of attribute

storeEventHelpElements

Description
Store display help elements for currently active action events.
Definition
storeEventHelpElements()
Return Values
booleanconfigurationHasBeenBoughtconfiguration has been bought

storeComboHelpElements

Description
Store combo button help elements for any modifier buttons required by currently active action events.
Definition
storeComboHelpElements()
Return Values
tablecolorcolor (r, g, b)

getEventHelpElementForAction

Description
Get the input help element for a given action.
Definition
getEventHelpElementForAction(inputActionName Name)
Arguments
inputActionNameNameof the requested input action.
Return Values
integermaterialmaterial

getEventHelpElements

Description
Get input help elements for the current input context.
Definition
getEventHelpElements(pressedComboMask Bit, isContextGamepad If)
Arguments
pressedComboMaskBitmask of the currently pressed combo button input
isContextGamepadIftrue, the player should be shown input hints for gamepad input. Otherwise, keyboard / mouse input help is required.
Return Values
any_typevaluevalue of config
arrayofhelp elements (see InputDisplayManager:makeHelpElement() for structure)

getComboHelpElements

Description
Get input help elements for currently available combo buttons.
Definition
getComboHelpElements(isContextGamepad If)
Arguments
isContextGamepadIftrue, the player should be shown input hints for gamepad input. Otherwise, keyboard / mouse input help is required.
Return Values
stringconfigKeykey of configuration
integerconfigIndexindex of configuration
Hashtableof currently active combo button action names, {action name=true}

getPrefix

Description
Get the controller symbol prefix for a device identified by its internal ID.
Definition
getPrefix()

getPlusOverlay

Description
Get the "plus" sign overlay.
This overlay is (re-)used in several places. Take care not to invalidate its state between uses.
Definition
getPlusOverlay()
Return Values
tablecolorcolor (r, g, b)

getOrOverlay

Description
Get the "or" sign overlay.
This overlay is (re-)used in several places. Take care not to invalidate its state between uses.
Definition
getOrOverlay()
Return Values
tableinstanceinstance of object

getKeyboardKeyOverlay

Description
Get the keyboard key glyph overlay (ButtonOverlay instance).
This overlay is (re-)used in several places. Take care not to invalidate its state between uses.
Definition
getKeyboardKeyOverlay()
Return Values
booleantrueif loading was successful else false

getFirstBindingAxisAndDeviceForActionName

Description
Get the first input axis name of the first binding of an input action identified by name.
Definition
getFirstBindingAxisAndDeviceForActionName(inputActionName Name, axisComponent [optional,, isGamepad [optional,)
Arguments
inputActionNameNameof an action as defined in InputAction
axisComponent[optional,default=POSITIVE] Binding.AXIS_COMPONENT value
isGamepad[optional,default=false] If true, return the first gamepad binding. Otherwise, keyboard is requested.
Return Values
booleansuccesstrue if added else false
Axisnameor nil if not found, internal ID of binding device

getGamepadInputActionOverlay

Description
Get an input action glyph overlay for the first gamepad button of the first binding of a given input action.
The method is simplified by design to mainly provide menu button glyphs. It will only return an overlay for the
first input axis, i.e. a simple button binding without modifiers. The returned overlay is a new instance and callers
need to delete it after use via GuiOverlay.deleteOverlay().
Definition
getGamepadInputActionOverlay(inputActionName Name, axisComponent [optional,)
Arguments
inputActionNameNameof an action as defined in InputAction
axisComponent[optional,default=POSITIVE] Binding.AXIS_COMPONENT value
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Overlayinstanceor nil if no overlay is available for the action's bindings

getKeyboardInputActionKey

Description
Get an input action key text for the key of the first binding of a given input action.
Definition
getKeyboardInputActionKey(inputActionName Name, axisComponent [optional,)
Arguments
inputActionNameNameof an action as defined in InputAction
axisComponent[optional,default=POSITIVE] Binding.AXIS_COMPONENT value
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
keytext(e.g. "F" for "KEY_f") for the keyboard action binding or nil if no resolution is possible

getGamepadInputSymbolName

Description
Get the controller symbol key name for a single gamepad / controller binding.
For full axes, call this for each axis component binding and concatenate the symbol keys with a space inbetween.
Definition
getGamepadInputSymbolName(internalDeviceId Internal, axisName Input, isAxisInput If)
Arguments
internalDeviceIdInternalgamepad device ID
axisNameInputaxis name
isAxisInputIftrue, the bound input axis is an analog physical axis
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
controllersymbolsconfiguration key name

getMouseInputSymbolName

Description
Get the controller symbol key name for a single mouse binding.
For full axes, call this for each axis component binding and concatenate the symbol keys with a space inbetween.
Definition
getMouseInputSymbolName(axisNames Mouse)
Arguments
axisNamesMousebinding axis names
Return Values
booleancanStartcan start ai
controllersymbolsconfiguration key name

onActionBindingsChanged

Description
Called when action bindings have changed.
Definition
onActionBindingsChanged(actionBindings Action)
Arguments
actionBindingsActionbindings table, {InputAction: {Binding}}
Return Values
booleancanContiuecan contiue ai

InputEvent

Description
Input event.
-- Holds information about an input event for an action, target, event callback and event trigger conditions. Also
stores input hint display information, because only actions with associated events need hints. When an action has
several events, callers need to make sure only one of the events' visibility is active.
--@category Input

new

Description
Create a new instance of InputEvent.
This constructor also assigns an ID to the instance, which should be used as a handle in most cases instead of the
actual instance reference.
Definition
new(actionName Name, targetObject Event, eventCallback Event, triggerUp If, triggerDown If, triggerAlways If, startActive [optional,, callbackState [optional])
Arguments
actionNameNameof action, see InputAction
targetObjectEventtarget, first argument to event callback
eventCallbackEventcallback, called when the action has input. Signature: callback(targetObject, actionName, inputValue, callbackState, isAnalog)
triggerUpIftrue, the event fires once when an input signal of the given action goes to "up" state, e.g. a released key.
triggerDownIftrue, the event fires once when an input signal of the given action goes to "down" state, e.g. a pressed key.
triggerAlwaysIftrue, the event fires on any signal input change, potentially every frame. This is mostly useful for required continuous axis input, e.g. steering actions.
startActive[optional,default=false] If true, the event is active right after registration.
callbackState[optional]An arbitrary value or reference which serves as a closure state within callbacks, useful e.g. when checking input state between events without requiring class fields.
Return Values
floatdirectionshape angle
NewInputEventinstance

setIgnoreComboMask

Description
Set the ignore flag for input binding combo masks.
If true, bindings which can trigger this event can be activated even if the do not match the currently pressed combo
mask. This is required for special cases, mostly player camera input, which should still be active when a combo
button is pressed.
Definition
setIgnoreComboMask()
Return Values
booleanisNeededcollision box is needed

getIgnoreComboMask

Description
Get the ignore flag for input binding combo masks.
Definition
getIgnoreComboMask()
Return Values
stringattributesstats attributes

notifyInput

Description
Notify this event of the input status of an associated action.
-- Note the interaction of the "down" and "always" triggers: If "down" is set and not "always", only an input down-flank
will raise an event. If both "down" and "always" are set, an event is raised as long as the input is pressed beyond a
threshold. If only "always" and not "down" is set, an event will be raised on each frame with the current input value
even if no input is active.
-- @param isUp If true, the action input had an "up" flank, i.e. the input was in "pressed" state and has returned to zero position
Definition
notifyInput(isDown If, isPressed If, inputValue Action, isAnalog True)
Arguments
isDownIftrue, the action input had a "down" flank, i.e. the input has crossed the "down" threshold
isPressedIftrue, the action input is in "pressed" state, i.e. the magnitude of the input is above the "down" threshold
inputValueActioninput value. This is not guaranteed to be in the range [-1, 1], because of sensitivity settings. Event handlers may clamp input values at their own discretion.
isAnalogTrueif the binding which provides the input value is analog.
Return Values
booleandeactivateOnLeavedeactivate on leaving

frameReset

Description
Reset this event after a frame.
Definition
frameReset()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

makeId

Description
Make this InputEvent instance's ID.
Definition
makeId()
Return Values
booleanexistsanimation axists

getTriggerCode

Description
Return trigger code
Definition
getTriggerCode()
Return Values
booleanisPlayinganimation is playing

initializeDisplayText

Description
Initialize this event's input hint display text with information from its associated action.
Defaults to the action's positive display name. For most half-axis actions, this will be correct. If a more specific
text is required depending on the current player context, apply a different text through the input system using
InputBinding:setActionEventText().
Definition
initializeDisplayText(InputAction InputAction)
Arguments
InputActionInputActionwhich this event references.
Return Values
floatanimTimereal animation time in ms

InputGlyphElement

Description
Input glyph display element.
-- Displays a key or button glyph for an input.
--@category GUI

new

Description
Create a new instance of InputGlyphElement.
Definition
new(table inputDisplayManager, float baseWidth, float baseHeight)
Arguments
tableinputDisplayManagerInputDisplayManager reference
floatbaseWidthDefault width of this element in screen space
floatbaseHeightDefault height of this element in screen space
Return Values
tablenpcthe npc object

delete

Description
Delete this element and release its resources.
Definition
delete()
Return Values
tableinstanceinstance of object

deleteOverlayCopies

Description
Delete any overlay copies.
Definition
deleteOverlayCopies()
Return Values
booleantrueif loading was successful else false

setScale

Description
Set the scale of this element.
Definition
setScale(float widthScale, float heightScale)
Arguments
floatwidthScaleWidth scale factor
floatheightScaleHeight scale factor
Return Values
booltrueif successful

setUpperCase

Description
Set the glyph text to be displayed in all upper case or not.
This resets the lower case setting if upper case is enabled.
Definition
setUpperCase()
Return Values
booltrueif successful

setLowerCase

Description
Set the glyph text to be displayed in all lower case or not.
This resets the upper case setting if lower case is enabled.
Definition
setLowerCase()
Return Values
booltrueif normalized

setBold

Description
Set the glyph text to be displayed in bold print or not.
Definition
setBold()
Return Values
booltrueif normalized

setKeyboardGlyphColor

Description
Set the button frame color for the keyboard glyphs.
Definition
setKeyboardGlyphColor(table color)
Arguments
tablecolorColor as an RGBA array
Return Values
tablereturnsa food group or nil if nothing is found

setButtonGlyphColor

Description
Set the color for button glyphs.
Definition
setButtonGlyphColor(table color)
Arguments
tablecolorColor as an RGBA array
Return Values
tablereturnsa food group or nil if nothing is found

setAction

Description
Set the action whose input glyphs need to be displayed by this element.
Definition
setAction(string actionName, string actionText, float actionTextSize, bool noModifiers, bool copyOverlays)
Arguments
stringactionNameInputAction name
stringactionText[optional] Additional action text to display after the glyph
floatactionTextSize[optional] Additional action text size in screen space
boolnoModifiers[optional] If true, will only show the input glyph of the last unmodified input binding axis
boolcopyOverlays[optional] If true, will create and handle a separate copy of an input glyph. Do not use
this when updating the action each frame!
Return Values
tablereturnsa food mixture or nil if nothing is found

setActions

Description
Set multiple actions whose input glyphs need to be displayed by this element.
If exactly two actions are passed in, they will be interpreted as belonging to the same axis and the system tries
to resolved the actions to a combined glyph. Otherwise, the glyphs will just be displayed in order of the actions.
Definition
setActions(table actionNames, string actionText, float actionTextSize, bool noModifiers, bool copyOverlays)
Arguments
tableactionNamesInputAction names array
stringactionText[optional] Additional action text to display after the glyph
floatactionTextSize[optional] Additional action text size in screen space
boolnoModifiers[optional] If true, will only show the input glyph of the last unmodified input binding axis
boolcopyOverlays[optional] If true, will create and handle a separate copy of an input glyph. Do not use
this when updating the action each frame!
Return Values
intFoodconsumption type, one of [AnimalFoodManager.FOOD_CONSUME_TYPE_SERIAL | AnimalFoodManager.FOOD_CONSUME_TYPE_PARALLEL]

updateDisplayText

Description
Update the display text from the set action text according to current casing settings.
Definition
updateDisplayText()
Return Values
tablereturnsa food group or nil if not found

getGlyphWidth

Description
Get the screen space width required by the glyphs used to display input in the current input context.
Definition
getGlyphWidth()
Return Values
floatreturnsa production weight between 0 and 1

draw

Description
Draw the input glyph(s).
Definition
draw()
Return Values
tableinstanceInstance of object

drawControllerButtons

Description
Draw controller button glyphs.
Definition
drawControllerButtons(table Array, float posX, float posY)
Arguments
tableArrayof controller button glyph overlays
floatposXInitial drawing X position in screen space
floatposYInitial drawing Y position in screen space
Return Values
boolreturnstrue if loading is fine
floatXposition in screen space after the last glyph

drawKeyboardKeys

Description
Draw keyboard key glyphs.
Definition
drawKeyboardKeys(table Array, float posX, float posY)
Arguments
tableArrayof keyboard key names
floatposXInitial drawing X position in screen space
floatposYInitial drawing Y position in screen space
Return Values
boolreturnstrue if module init after placement is fine
floatXposition in screen space after the last glyph

drawActionText

Description
Draw the action text after the input glyphs.
Definition
drawActionText(float posX, float posY)
Arguments
floatposXDrawing X position in screen space
floatposYDrawing Y position in screen space
Return Values

InputHelpDisplay

Description
HUD input help display.
-- Displays controls and further information for the current input context.
--@category GUI

new

Description
Create a new instance of InputHelpDisplay.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
Return Values

addHelpText

Description
Add a help text line for this frame.
Will be cleared after the current frame.
Definition
addHelpText()
Return Values
boolreturnstrue if initialization is fine

setVehicle

Description
Set the currently controlled vehicle.
Definition
setVehicle(table vehicle)
Arguments
tablevehicleVehicle reference or nil if no vehicle is controlled.
Return Values
stringfilllevel

getHidingTranslation

Description
Override of HUDDisplayElement.
Moves out to the left to hide.
Definition
getHidingTranslation()
Return Values
integertotalanimals. Default is zero

addCustomEntry

Description
Add a custom input help entry which is displayed in the current input context until removed.
Custom entries will be displayed in order of addition after any automatically detected input help entries and before
vehicle extensions.
Definition
addCustomEntry()
Return Values
stringreturnanimal type. nil if not available

clearCustomEntries

Description
Clear all custom input help entries in the current context.
Definition
clearCustomEntries()
Return Values
tableofcosumed food (result[fillTypeIndex]=amount)

update

Description
Update the input help's state.
Definition
update()
Return Values
tableProductionfill type information as {i={j={fillType=fillType, fillLevel=fillLevel, capacity=capacity}}}

updateSizeAndPositions

Description
Update sizes and positions of this elements and its children.
Definition
updateSizeAndPositions()
Return Values

refreshHUDExtensions

Description
Create any required HUD extensions when the current vehicle configuration changes.
Definition
refreshHUDExtensions()
Return Values
booltrueif registration went well

updateHUDExtensions

Description
Update HUD extensions if controlled vehicles have changed.
Definition
updateHUDExtensions()
Return Values
booltrueif registration went well

collectVehicleSpecializations

Description
Recursively get vehicle specializations for a vehicle configuration.
Definition
collectVehicleSpecializations()
Return Values
floatdirtyfactor [0-1]

getAvailableHeight

Description
Get the available screen space height for displaying input help.
Definition
getAvailableHeight()
Return Values
tableinstanceinstance of object

updateInputContext

Description
Update display elements with the current input context.
Definition
updateInputContext()
Return Values
booleantrueif loading was successful else false

updateEntries

Description
Update entry glyphs and visibility with the current input help elements.
Definition
updateEntries(table helpElements)
Arguments
tablehelpElementsArray of InputHelpElement for the current input context
Return Values
booltrueif successful

updateComboHeaders

Description
Update combo header state.
Definition
updateComboHeaders(bool useGamepadButtons, int pressedComboMaskMouse, int pressedComboMaskGamepad)
Arguments
booluseGamepadButtonsIf true, check gamepad input. Otherwise, check keyboard / mouse.
intpressedComboMaskMouseBit mask of pressed mouse combo actions
intpressedComboMaskGamepadBit mask of pressed gamepad combo actions
Return Values
booltrueif animal is in the husbandry
floatScreenspace height used by the combo header (0 if invisible)

updateComboInputGlyphs

Description
Update visibility and color of combo input glyphs.
Definition
updateComboInputGlyphs(table comboActionStatus, int pressedComboMaskMouse, int pressedComboMaskGamepad)
Arguments
tablecomboActionStatusHashtable of combo action names which are currently available
intpressedComboMaskMouseBit mask of pressed mouse combo actions
intpressedComboMaskGamepadBit mask of pressed gamepad combo actions
Return Values
table

getInputHelpElements

Description
Get input help elements based on the current input context.
Definition
getInputHelpElements(float availableHeight, int pressedComboMaskGamepad, int pressedComboMaskMouse, bool useGamepadButtons)
Arguments
floatavailableHeightMaximum available height to use for input help elements
intpressedComboMaskGamepadBit mask of pressed gamepad combo buttons
intpressedComboMaskMouseBit mask of pressed mouse combo buttons
booluseGamepadButtonsIf true, we should draw gamepad / controller combo button glyphs
Return Values
tableinstanceinstance of object
tableInputhelp elements
floatScreenspace height used by the returned help elements

setAnimationAvailableHeight

Description
Set the current animation value for available height.
Definition
setAnimationAvailableHeight()
Return Values
booleantrueif loading was successful else false

setAnimationOffset

Description
Set the current animation position offset.
Definition
setAnimationOffset()
Return Values
booltrueif successful

animateHide

Description
Animate this element on hiding.
Definition
animateHide()
Return Values
booltrueif successful

animateShow

Description
Animate this element on showing.
Definition
animateShow()
Return Values
floatamounteffectively changed

onAnimateVisibilityFinished

Description
Called when a hiding or showing animation has finished.
Definition
onAnimateVisibilityFinished()
Return Values
floatdeltaof amount changed

onInputDevicesChanged

Description
Called when the connected input devices have changed.
Definition
onInputDevicesChanged()
Return Values
floatreturnsthe fillLevel of a fillType

draw

Description
Draw the input help.
Only draws if the element is visible and there are any help elements.
Definition
draw()
Return Values
floatreturnsthe fillLevel of all fillType

drawControlsLabel

Description
Draw the "controls" label on top of the display frame.
Definition
drawControlsLabel()
Return Values
floatreturnsthe capacity of a fillType

drawHelpInfos

Description
Draw icons and text in help entries.
Definition
drawHelpInfos()
Return Values
floatreturnsa progress of the fillType between 0 and 1. Default is 0.

drawVehicleHUDExtensions

Description
Draw vehicle HUD extensions.
Definition
drawVehicleHUDExtensions()
Return Values
floatactualdelta filled

setScale

Description
Set this element's UI scale.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor
Return Values

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Return Values
tablemoduleinstance or nil of no module has been registered

getBackgroundPosition

Description
Get this element's base background position in screen space.
Definition
getBackgroundPosition()
Return Values
tableinstanceinstance of object

getTopLeftPosition

Description
Get the current top left position of the input help, including animation.
Definition
getTopLeftPosition()
Return Values
booleantrueif loading was successful else false

getMaxEntryCount

Description
Get the maximum number of help entries which may be shown at any time.
Definition
getMaxEntryCount()
Return Values
floatreturnsthe capacity of a fillType
intMaximumnumber of entries to show

getIsHelpElementAllowed

Description
Returns if it is still allowed to add more help elements
Definition
getIsHelpElementAllowed(table helpElements, table helpElement)
Arguments
tablehelpElementsexisting table of help elements
tablehelpElementhelp element to add
Return Values
floatamounteffectively changed
booleanisAllowedisAllowed

setDimension

Description
Set this element's dimensions.
Override from HUDElement which adjusts frame with offset.
Definition
setDimension()
Return Values
booleantrueif loading was successful else false

createBackground

Description
Create the background overlay for positioning.
Definition
createBackground()
Return Values
floatfooddropped

createComponents

Description
Create required display components.
Definition
createComponents()
Return Values
floatspillagetotal

createFrame

Description
Create the frame around input help elements.
Definition
createFrame()
Return Values
tableinstanceinstance of object

createVerticalSeparator

Description
Create a vertical separator element.
Definition
createVerticalSeparator()
Return Values
booleantrueif loading was successful else false

createHorizontalSeparator

Description
Create a horizontal separator element.
Definition
createHorizontalSeparator()
Return Values
tableinstanceinstance of object

createComboInputGlyph

Description
Create an input glyph for displaying combo input buttons.
Definition
createComboInputGlyph(float posX, float posY, float width, float height, string actionName)
Arguments
floatposXScreen space X position
floatposYScreen space Y position
floatwidthScreen space width
floatheightScreen space height
stringactionNameInputAction name of the combo action whose input glyphs need to be displayed
Return Values
booleantrueif loading was successful else false
tableComboInputGlyphElement instance

createComboHeader

Description
Create a combo input glyph header.
Definition
createComboHeader(hudAtlasPath Path, frameX Screen, frameY Screen, table combos, table boxSize, table separatorPositions)
Arguments
hudAtlasPathPathto HUD texture atlas
frameXScreenspace X position of the display frame
frameYScreenspace Y position of the display frame
tablecombosArray of input combination descriptions as defined in InputBinding
tableboxSize2D vector which holds the pixel size of one combo input box within the header
tableseparatorPositionsArray of 2D vectors of separator pixel positions
Return Values
floatmanuredropped
tableComboheader HUDElement

createMouseComboHeader

Description
Create the mouse combo header.
Definition
createMouseComboHeader()
Return Values
floatmanurefill level

createControllerComboHeader

Description
Create the gamepad / controller combo header.
Definition
createControllerComboHeader()
Return Values
floatmanureused

createEntry

Description
Create an input help entry box.
Definition
createEntry()
Return Values
tableinstanceinstance of object

createEntries

Description
Create all required input help entry boxes.
The boxes are modified as required to reflect the current input context.
Definition
createEntries()
Return Values
booleantrueif loading was successful else false

InputHelpElement

Description
Input help element.
-- Holds help and hint information about the current input context for display in the HUD.
--@category Input

getActionNames

Description
Get an array of action names which were validly set in the constructor.
Definition
getActionNames()
Return Values
floatanimTimeanimation time [0..1]

InputHelper

Description
Maps key IDs to localization glyph symbols.

MouseHelper.getInputDisplayText

Description
Get a display string for a list of mouse input axis names
Definition
MouseHelper.getInputDisplayText()
Return Values
floatdurationduration in ms

KeyboardHelper.getDisplayKeyName

Description
Get a display name for a given key ID.
Encapsulates engine getKeyName() function.
Definition
KeyboardHelper.getDisplayKeyName()
Return Values
booleanrightOrderreturns true if parts are in right order

KeyboardHelper.getInputDisplayText

Description
Get a display string for a list of keyboard input keys.
Definition
KeyboardHelper.getInputDisplayText()
Return Values
booleanrightOrderreturns true if parts are in reverse right order

GamepadHelper.getInputDisplayText

Description
Get a display string for a list of gamepad/controller input button/axis names and an associated device.
Definition
GamepadHelper.getInputDisplayText(inputList List, internalDeviceId ID)
Arguments
inputListListof input button / axis names
internalDeviceIdIDof device as issued by the engine
Return Values
floatretlimited value

JoinGameScreen

Description
Join Multiplayer Game Screen.
-- @field mainBox Layout box for most of the screen, used to quickly show / hide everything.

onClickHeader

Description
Handle clicks on table header elements
Triggers sorting and a view update.
Definition
onClickHeader()
Return Values
tableinstanceinstance of object

onServerNameChanged

Description
Handle changes in the server name filter field
Definition
onServerNameChanged(element TextInputElement, text New)
Arguments
elementTextInputElementinstance
textNewtext
Return Values
tablebaleTypebaleType object

saveFilterSettings

Description
Save the current filter settings.
Definition
saveFilterSettings()
Return Values
tablebrandColorbrandColor object

getSelectedServer

Description
Get the server info of the currently selected server
Definition
getSelectedServer()
Return Values
tableinstanceinstance of object

setStartButtonState

Description
Assign the "Start Game" button state.
Enables the button if the currently selected server is valid for playing. Disables it otherwise.
Definition
setStartButtonState()
Return Values
booleantrueif loading was successful else false

filterServer

Description
Filter a server with the current filter settings.
Definition
filterServer(server Server)
Arguments
serverServerinformation (see onServerInfo()) for data structure
Return Values
booleantrueif loading was successful else false
Trueifthe server matches the current filter settings, false otherwise

setTableFiltersAndSorting

Description
Apply server filters to server list.
Definition
setTableFiltersAndSorting()
Return Values
booleansuccesssuccess

rebuildServerList

Description
Update the server table.
This causes a full rebuild of the table data.
Definition
rebuildServerList()
Return Values
tableinstanceinstance of object

buildServerDataRow

Description
Build a DataRow from server properties to add to the server list GuiElement.
Definition
buildServerDataRow()
Return Values
tableinstanceinstance of object
dataRowinstancewith server data

ListItemElement

Description
List item element to be used and laid out by ListElement and TableElement.
-- Used layers: "image" for a background image.
--@category GUI
--@xmlConfig GuiElement#allowSelected bool [optional] If false, this element cannot be selected, only focused or activated.

getFocusTarget

Description
Get the actual focus target, in case a child or parent element needs to be targeted instead.
Override from BitmapElement: Only focuses children if #autoSelectChildren is true
Definition
getFocusTarget(incomingDirection (Optional), moveDirection (Optional))
Arguments
incomingDirection(Optional)If specified, may return different targets for different incoming directions.
moveDirection(Optional)Actual movement direction per input. This is the opposing direction of incomingDirection.
Return Values
GuiElementActualelement to focus.

MainScreen

Description
Main Menu Screen.
-- @field backgroundImage Main background image

setupNotifications

Description
Set up notifications display and animation.
Definition
setupNotifications()
Return Values
floatnearCoCRadiusNear circle of confusion radius (nearCoCRadius = 0 means no near blur (pinhole camera))
floatnearBlurEndDistance from the camera center where near blur ends
floatfarCoCRadiusFar circle of confusion radius (farCoCRadius = 0 means no far blur (pinhole camera))
floatfarBlurStartDistance from the camera center where far blur starts
floatfarBlurEndDistance from the camera center where far blur ends

setNotificationButtonsDisabled

Description
Set notification buttons disabled state.
If fewer than 2 notifications are available to show, the cycle buttons will always be disabled.
Definition
setNotificationButtonsDisabled()

resetNotifications

Description
Reset notification data and display.
Definition
resetNotifications()

cycleNotification

Description
Cycle through available notifications.
Definition
cycleNotification(int signedDelta)
Arguments
intsignedDelta1 or -1 for next or previous

onNotificationBoxClick

Description
Handle an activation of the notification open button or input action.
Definition
onNotificationBoxClick()

updateNotifications

Description
Update notifications.
Definition
updateNotifications()
Return Values
floatnearCoCRadiusNear circle of confusion radius (nearCoCRadius = 0 means no near blur (pinhole camera))
floatnearBlurEndDistance from the camera center where near blur ends
floatfarCoCRadiusFar circle of confusion radius (farCoCRadius = 0 means no far blur (pinhole camera))
floatfarBlurStartDistance from the camera center where far blur starts
floatfarBlurEndDistance from the camera center where far blur ends

updateFading

Description
Update screen fading values.
Definition
updateFading()

MapDataGrid

Description
Creating data grid

new

Description
@param table customMt custom metatable
Definition
new()
Return Values
tableinstanceinstance of object
Code
19function MapDataGrid:new(mapSize, blocksPerRowColumn, customMt)
20 local self = DataGrid:new(blocksPerRowColumn, blocksPerRowColumn, customMt or MapDataGrid_mt)
21
22 self.blocksPerRowColumn = blocksPerRowColumn
23 self.mapSize = mapSize
24 self.blockSize = self.mapSize/self.blocksPerRowColumn
25
26 return self
27end

getValueAtWorldPos

Description
@param float worldZ world position z
Definition
getValueAtWorldPos()
Return Values
tablevaluevalue at the given position
Code
34function MapDataGrid:getValueAtWorldPos(worldX, worldZ)
35 local rowIndex, colIndex = self:getRowColumnFromWorldPos(worldX, worldZ)
36 return self:getValue(rowIndex, colIndex), rowIndex, colIndex
37end

setValueAtWorldPos

Description
@param float worldZ world position z
Definition
setValueAtWorldPos(table value)
Arguments
tablevaluevalue at the given position
Code
44function MapDataGrid:setValueAtWorldPos(worldX, worldZ, value)
45 local rowIndex, colIndex = self:getRowColumnFromWorldPos(worldX, worldZ)
46 self:setValue(rowIndex, colIndex, value)
47end

getRowColumnFromWorldPos

Description
@param float worldZ world position z
Definition
getRowColumnFromWorldPos()
Return Values
integerrowrow
integercolumncolumn
Code
55function MapDataGrid:getRowColumnFromWorldPos(worldX, worldZ)
56 local mapSize = self.mapSize
57 local blocksPerRowColumn = self.blocksPerRowColumn
58
59 local x = (worldX + mapSize*0.5) / mapSize
60 local z = (worldZ + mapSize*0.5) / mapSize
61
62 local row = MathUtil.clamp(math.ceil(blocksPerRowColumn*z), 1, blocksPerRowColumn)
63 local column = MathUtil.clamp(math.ceil(blocksPerRowColumn*x), 1, blocksPerRowColumn)
64
65-- log(worldX, worldZ, " -> ", (worldX + self.mapSize*0.5), (worldZ + self.mapSize*0.5), z, x, row, column)
66
67 return row, column
68end

MapHotspot

Description
UV coordinates in the map hotspot atlas.

setRawTextOffset

Description
Set the text offset using a raw value string in the form of "<X>px <Y>px".
Definition
setRawTextOffset()
Return Values
booleantrueif loading was successful else false

setOwnerFarmId

Description
Set the farm this hotspot should be shown for. Use AccessHandler.EVERYONE for showing it to everybody (default)
Definition
setOwnerFarmId()
Return Values
boolistrue if available Pallet has been assigned with a vehicle object

MapOverlayGenerator

Description
Map overlay generator.
-- Provides density map based data overlays on top of an in-game map.

new

Description
Create a MapOverlayGenerator instance.
Definition
new(table l10n, table fruitTypeManager, table fillTypeManager, table farmlandManager, table farmManager)
Arguments
tablel10nI18N reference for text localization
tablefruitTypeManagerFruitTypeManager reference for fruit type resolution
tablefillTypeManagerFillTypeManager reference for fruit fill type resolution
tablefarmlandManagerFarmlandManager reference for farm land data access
tablefarmManagerFarmManager reference for farm land ownership data access

delete

Description
Delete this instance and any used overlays.
Definition
delete()

setMissionFruitTypes

Description
Set the valid fruit types of the current mission.
Definition
setMissionFruitTypes()

setColorBlindMode

Description
Set the color blind mode for overlay creation.
Definition
setColorBlindMode()

buildFruitTypeMapOverlay

Description
Build the map overlay for fruit types.
Definition
buildFruitTypeMapOverlay()

buildGrowthStateMapOverlay

Description
Build the map overlay for growth states.
Definition
buildGrowthStateMapOverlay()

buildSoilStateMapOverlay

Description
Build the map overlay for soil states.
Definition
buildSoilStateMapOverlay()

buildFarmlandsMapOverlay

Description
Build the map overlay for farm lands.
Definition
buildFarmlandsMapOverlay()

generateOverlay

Description
Generate a map overlay of a given type.
This is an internal generic interfacing method and should not be called externally. Consumers should use one of the
specific public methods instead, e.g. MapOverlayGenerator:generateFruitTypeOverlay().
Definition
generateOverlay(int mapOverlayType, function finishedCallback, table overlayState)
Arguments
intmapOverlayTypeOverlay type as one of MapOverlayGenerator.OVERLAY_TYPE.[CROPS|GROWTH|SOIL|FARMLANDS]
functionfinishedCallbackFunction which is called with the overlay ID as its argument when processing is
finished, signature: function(overlayId)
tableoverlayStateOverlay state data which defines parameters (e.g. colors) of the map overlays.
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

generateFruitTypeOverlay

Description
Generate a fruit type overlay.
Definition
generateFruitTypeOverlay(function finishedCallback, table fruitTypeFilter)
Arguments
functionfinishedCallbackCalled when generation is finished, signature: function(overlayId)
tablefruitTypeFilterMap of fruit type indices to booleans. If the value is true, the fruit type will be displayed.
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

generateGrowthStateOverlay

Description
Generate a growth state overlay.
Definition
generateGrowthStateOverlay(function finishedCallback, table fruitTypeFilter)
Arguments
functionfinishedCallbackCalled when generation is finished, signature: function(overlayId)
tablefruitTypeFilterMap of growth state indices (MapOverlayGenerator.GROWTH_STATE_INDEX members) to
booleans. If the value is true, the growth state will be displayed.
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

generateSoilStateOverlay

Description
Generate a soil state overlay.
Definition
generateSoilStateOverlay(function finishedCallback, table fruitTypeFilter)
Arguments
functionfinishedCallbackCalled when generation is finished, signature: function(overlayId)
tablefruitTypeFilterMap of soil state indices (MapOverlayGenerator.SOIL_STATE_INDEX members) to
booleans. If the value is true, the soil state will be displayed.
Return Values
boolTrueif overlay generation has started, false if generation is already in progress or an invalid overlay
type has been provided

generateFarmlandOverlay

Description
Generate a farm land overlay.
Definition
generateFarmlandOverlay(function finishedCallback, table mapPosition)
Arguments
functionfinishedCallbackCalled when generation is finished, signature: function(overlayId)
tablemapPositionMap position vector of a selection position. If the position is within a farm land, it will
be highlighted.

checkOverlayFinished

Description
Check if any overlay is currently being generated and triggers a callback when it's finished.
Definition
checkOverlayFinished()

reset

Description
Reset overlay generation state.
Definition
reset()

update

Description
Update the state each frame.
Checks the overlay generation state.
Definition
update()

getDisplayCropTypes

Description
Get display information for crop types.
Override to add new crop types or change information.
Definition
getDisplayCropTypes()
Return Values
arrayofdisplay information, {i={colors={true=[{r,g,b,a} colorblind], false=[{r,g,b,a} default], iconFilename=path,
iconUVs={u1, v1, u2, v2, u3, v3, u4, v4}, description=text, fruitTypeIndex=index}}
Code
373function MapOverlayGenerator:getDisplayCropTypes()
374 local cropTypes = {}
375 -- load crop type icon definitions in order of map configuration
376 for i, fruitType in ipairs(self.missionFruitTypes) do
377 if fruitType.shownOnMap and fruitType.fruitTypeIndex ~= FruitType.WEED then -- weed is known as a fruit type, but is handled as a soil state
378 local fillableIndex = self.fruitTypeManager:getFillTypeIndexByFruitTypeIndex(fruitType.fruitTypeIndex)
379 local fillable = self.fillTypeManager:getFillTypeByIndex(fillableIndex)
380
381 local iconFilename = fillable.hudOverlayFilenameSmall
382 local iconUVs = Overlay.DEFAULT_UVS -- default crop type icons are separate files, use full texture
383 local description = fillable.title
384
385 table.insert(cropTypes, {
386 colors = {[false] = fruitType.defaultColor, [true] = fruitType.colorBlindColor},
387 iconFilename = iconFilename,
388 iconUVs = iconUVs,
389 description = description,
390 fruitTypeIndex = fruitType.fruitTypeIndex,
391 foliageId = fruitType.foliageId
392 })
393 end
394 end
395
396 return cropTypes
397end

getDisplayGrowthStates

Description
Get display information for growth states.
Growth states can be represented in multiple colors per state, so colors are defined in arrays per color blind mode.
Override to add new growth states or change information.
Definition
getDisplayGrowthStates()
Return Values
arrayofdisplay information, {i={colors={true={i={r,g,b,a}}, false={i={r,g,b,a}}}, description=text}}
Code
404function MapOverlayGenerator:getDisplayGrowthStates()
405 return {
406 -- indices are contiguous, so this definition is a valid array:
407 [MapOverlayGenerator.GROWTH_STATE_INDEX.CULTIVATED] = {
408 colors = {
409 [true] = {MapOverlayGenerator.FRUIT_COLOR_CULTIVATED[true]},
410 [false] = {MapOverlayGenerator.FRUIT_COLOR_CULTIVATED[false]}
411 },
412 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_CULTIVATED)
413 },
414 [MapOverlayGenerator.GROWTH_STATE_INDEX.GROWING] = {
415 colors = MapOverlayGenerator.FRUIT_COLORS_GROWING,
416 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_GROWING)
417 },
418 [MapOverlayGenerator.GROWTH_STATE_INDEX.HARVEST] = {
419 colors = MapOverlayGenerator.FRUIT_COLORS_HARVEST,
420 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_HARVEST)
421 },
422 [MapOverlayGenerator.GROWTH_STATE_INDEX.HARVESTED] = {
423 colors = {
424 [true] = {MapOverlayGenerator.FRUIT_COLOR_CUT},
425 [false] = {MapOverlayGenerator.FRUIT_COLOR_CUT}
426 },
427 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_HARVESTED)
428 },
429 [MapOverlayGenerator.GROWTH_STATE_INDEX.PLOWED] = {
430 colors = {
431 [true] = {MapOverlayGenerator.FRUIT_COLOR_PLOWED[true]},
432 [false] = {MapOverlayGenerator.FRUIT_COLOR_PLOWED[false]}
433 },
434 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_PLOWED)
435 },
436 [MapOverlayGenerator.GROWTH_STATE_INDEX.TOPPING] = {
437 colors = {
438 [true] = {MapOverlayGenerator.FRUIT_COLOR_REMOVE_TOPS[true]},
439 [false] = {MapOverlayGenerator.FRUIT_COLOR_REMOVE_TOPS[false]}
440 },
441 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_TOPPING)
442 },
443 [MapOverlayGenerator.GROWTH_STATE_INDEX.WITHERED] = {
444 colors = {
445 [true] = {MapOverlayGenerator.FRUIT_COLOR_WITHERED[true]},
446 [false] = {MapOverlayGenerator.FRUIT_COLOR_WITHERED[false]}
447 },
448 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.GROWTH_MAP_WITHERED)
449 }
450 }
451end

getDisplaySoilStates

Description
Get display information for soil states.
Soil states can be represented in multiple colors per state, so colors are defined in arrays per color blind mode.
Override to add new soil states or change information.
Definition
getDisplaySoilStates()
Return Values
arrayofdisplay information, {i={colors={true={i={r,g,b,a}}, false={i={r,g,b,a}}}, description=text}}
Code
458function MapOverlayGenerator:getDisplaySoilStates()
459 local weedType = self.fruitTypeManager:getWeedFruitType()
460 local fillableIndex = self.fruitTypeManager:getFillTypeIndexByFruitTypeIndex(FruitType.WEED)
461 local weedFillable = self.fillTypeManager:getFillTypeByIndex(fillableIndex)
462
463 return {
464 [MapOverlayGenerator.SOIL_STATE_INDEX.WEEDS] = {
465 colors = {
466 [true] = {weedType.colorBlindMapColor},
467 [false] = {weedType.defaultMapColor}
468 },
469 description = weedFillable.title
470 },
471 [MapOverlayGenerator.SOIL_STATE_INDEX.FERTILIZED] = {
472 colors = MapOverlayGenerator.FRUIT_COLORS_FERTILIZED,
473 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.SOIL_MAP_FERTILIZED)
474 },
475 [MapOverlayGenerator.SOIL_STATE_INDEX.NEEDS_PLOWING] = {
476 colors = {
477 [true] = {MapOverlayGenerator.FRUIT_COLOR_NEEDS_PLOWING[true]},
478 [false] = {MapOverlayGenerator.FRUIT_COLOR_NEEDS_PLOWING[false]}
479 },
480 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.SOIL_MAP_NEED_PLOWING)
481 },
482 [MapOverlayGenerator.SOIL_STATE_INDEX.NEEDS_LIME] = {
483 colors = {
484 [true] = {MapOverlayGenerator.FRUIT_COLOR_NEEDS_LIME[true]},
485 [false] = {MapOverlayGenerator.FRUIT_COLOR_NEEDS_LIME[false]}
486 },
487 description = self.l10n:getText(MapOverlayGenerator.L10N_SYMBOL.SOIL_MAP_NEED_LIME)
488 }
489 }
490end

MapSelectionScreen

Description
Map Selection Screen.
-- Used when starting a new game.
-- @field mapSelector Map selection option at top of view

onCreateMapImage

Description
Creation event for map preview BitmapElement instances.
This gets called during onOpen when map data is iterated and added, so we can set the image state according to the
currently processed map.
Definition
onCreateMapImage(element BitmapElement)
Arguments
elementBitmapElementinstance which shows a map preview image

MessageCenter

Description
Message center message types.
Use these identifiers to subscribe to and publish messages.

subscribe

Description
Subscribe the target to given message type.
Definition
subscribe(integer messageType, function callback, table callbackTarget, any argument)
Arguments
integermessageTypeType of message
functioncallbackCallback function
tablecallbackTargetOptional target
anyargumentOptional argument, will be last in callback argument list
Return Values
tableimplementimplement

unsubscribe

Description
Unsubscribe the observer from message
This is relatively slow, do not use in :update or :draw
Definition
unsubscribe(integer messageType, table callbackTarget)
Arguments
integermessageTypeType of message
tablecallbackTargetObserver object
Return Values
booleansuccesssuccess

unsubscribeAll

Description
Unsubscribe the observer from all messages
Definition
unsubscribeAll(table callbackTarget)
Arguments
tablecallbackTargetObserver object
Return Values
booleansupportsHardAttachattacher joint supports hard attach

publish

Description
Publish a message with given type and possible arguments
Definition
publish(integer messageType, table arguments)
Arguments
integermessageTypeType of the message, used with the subscriptions
tableargumentsOptional arguments passed to function
Return Values
booleansuccesssuccess

publishDelayed

Description
Publish a message with given type and possible arguments. This message is handled in the next frame.
Useful for within networking code
Definition
publishDelayed(integer messageType, table arguments)
Arguments
integermessageTypeType of the message, used with the subscriptions
tableargumentsOptional arguments passed to function
Return Values
floattotalMasstotal mass

MissionCollaborators

Description
Mission class collaborator collection for initialization.
-- Serves as an explicitly defined value-object for Mission class constructors to pass in required collaborator
references without needing to change the constructor signature for each new collaborator class.

new

Description
Create a new MissionCollaborators instance.
The constructor declares fields for reference which are used by the Mission class constructors. Stick to only
assigning to these fields when using this class or add a suitable declaration below when more references are needed.
Definition
new()
Return Values
floattotalamount of consumed pto torque in kNm

MissionManager

Description
Dismiss a (finished or cancelled) mission. Deletes it completely. Calls dismiss on the mission to handle money exchange to farm.

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
31function MissionManager:new(customMt)
32 local self = AbstractManager:new(customMt or MissionManager_mt)
33
34 self.missionTypes = {}
35 self.missionTypeIdToType = {}
36
37 self.defaultMissionMapWidth = 512
38 self.defaultMissionMapHeight = 512
39 self.missionMapNumChannels = 4
40
41 -- Only on new game start. Reset is done when quitting a game.
42 -- This value is changed very early in the loading process
43 self.numTransportTriggers = 0
44 self.transportTriggers = {}
45
46 return self
47end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
74function MissionManager:loadMapData(xmlFile)
75 MissionManager:superClass().loadMapData(self)
76
77 self:createMissionMap()
78
79 if g_currentMission:getIsServer() then
80 g_currentMission:addUpdateable(self)
81
82 self.missionNextGenerationTime = g_currentMission.time + MissionManager.MISSION_GENERATION_INTERVAL
83
84 self.fieldDataDmod = DensityMapModifier:new(g_currentMission.terrainDetailId, g_currentMission.sprayFirstChannel, g_currentMission.sprayNumChannels)
85 self.fieldDataFilter = DensityMapFilter:new(g_currentMission.terrainDetailId, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
86 self.fieldDataFilter:setValueCompareParams("greater", 0)
87 end
88
89 local p = getXMLString(xmlFile, "map.transportMissions#filename")
90 if p ~= nil then
91 local path = Utils.getFilename(p, g_currentMission.baseDirectory)
92 if path ~= nil and path ~= "" then
93 self:loadTransportMissions(path)
94 end
95 end
96
97 local p = getXMLString(xmlFile, "map.missionVehicles#filename")
98 if p ~= nil then
99 local path = Utils.getFilename(p, g_currentMission.baseDirectory)
100 if path ~= nil then
101 self:loadMissionVehicles(path)
102 end
103 end
104
105 if g_currentMission:getIsServer() then
106 -- Generate a weighted list of transport missions
107 for _, missionType in ipairs(self.missionTypes) do
108 if missionType.category == MissionManager.CATEGORY_TRANSPORT then
109 for i = 1, missionType.priority do
110 table.insert(self.possibleTransportMissionsWeighted, missionType)
111 end
112 end
113 end
114 end
115
116 g_messageCenter:subscribe(MessageType.MISSION_DELETED, self.onMissionDeleted, self)
117
118 if g_addTestCommands then
119 addConsoleCommand("gsGenerateFieldMission", "Force generating a new mission for given field", "consoleGenerateFieldMission", self)
120 addConsoleCommand("gsMissionLoadAllVehicles", "Loading and unloading all field mission vehicles", "consoleLoadAllFieldMissionVehicles", self)
121
122 addConsoleCommand("gsMissionHarvestField", "Harvest a field and print the liters", "consoleHarvestField", self)
123 end
124end

loadTransportMissions

Description
Load map-configured transport missions
Definition
loadTransportMissions()

loadMissionVehicles

Description
Load vehicles for use with field missions
Definition
loadMissionVehicles()

unloadMapData

Description
Unload data on mission delete
Definition
unloadMapData()
Code
349function MissionManager:unloadMapData()
350 g_messageCenter:unsubscribeAll()
351 g_currentMission:removeUpdateable(self)
352
353 self.numTransportTriggers = 0
354 self.transportTriggers = {}
355
356 self.fieldDataDmod = nil
357 self.fieldDataFilter = nil
358
359 self:destroyMissionMap()
360
361 if g_addTestCommands then
362 removeConsoleCommand("gsGenerateFieldMission")
363 removeConsoleCommand("gsMissionLoadAllVehicles")
364 removeConsoleCommand("gsMissionHarvestField")
365 end
366
367 MissionManager:superClass().unloadMapData(self)
368end

saveToXMLFile

Description
Write field mission data to savegame file
Definition
saveToXMLFile(string xmlFilename)
Arguments
stringxmlFilenamefile path
Return Values
booleantrueif loading was successful else false
Code
374function MissionManager:saveToXMLFile(xmlFilename)
375 local xmlFile = createXMLFile("missionXML", xmlFilename, "missions")
376
377 if xmlFile ~= nil then
378 for k, mission in ipairs(self.missions) do
379 local missionKey = string.format("missions.mission(%d)", k - 1)
380
381 setXMLString(xmlFile, missionKey.."#type", mission.type.name)
382 if mission.activeMissionId ~= nil then
383 setXMLInt(xmlFile, missionKey.."#activeId", mission.activeMissionId)
384 end
385
386 mission:saveToXMLFile(xmlFile, missionKey)
387 end
388
389 saveXMLFile(xmlFile)
390 delete(xmlFile)
391 end
392
393 return false
394end

loadFromXMLFile

Description
Load fieldjob data from xml savegame file
Definition
loadFromXMLFile(string filename)
Arguments
stringfilenamexml filename
Code
399function MissionManager:loadFromXMLFile(xmlFilename)
400 if xmlFilename == nil then
401 return false
402 end
403
404 local xmlFile = loadXMLFile("missionsXML", xmlFilename)
405 if not xmlFile then
406 return false
407 end
408
409 -- Active missions
410 local i = 0
411 while true do
412 local key = string.format("missions.mission(%d)", i)
413 if not hasXMLProperty(xmlFile, key) then
414 break
415 end
416
417 local missionTypeName = getXMLString(xmlFile, key.."#type")
418 local missionType = self:getMissionType(missionTypeName)
419
420 if missionType ~= nil then
421 local mission = missionType.class:new(true, g_client ~= nil)
422 mission.type = missionType
423 mission.activeMissionId = getXMLInt(xmlFile, key .. "#activeId") -- can be nil
424 self:assignGenerationTime(mission)
425
426 if not mission:loadFromXMLFile(xmlFile, key) then
427 mission:delete()
428 else
429 if mission.field ~= nil then
430 self.fieldToMission[mission.field.fieldId] = mission
431 end
432
433 if mission.type.category == MissionManager.CATEGORY_TRANSPORT then
434 self.numTransportMissions = self.numTransportMissions + 1
435 end
436
437 mission:register()
438 table.insert(self.missions, mission)
439 end
440 else
441 print("Warning: Mission type '" .. tostring(missionType) .. "' not found!")
442 end
443
444 i = i + 1
445 end
446
447 -- If there are any active missions, find any associated vehicles
448 if table.getn(self.missions) > 0 then
449 for _, vehicle in pairs(g_currentMission.vehicles) do
450 if vehicle.activeMissionId ~= nil then
451 local mission = self:getMissionForActiveMissionId(vehicle.activeMissionId)
452 if mission ~= nil and mission.vehicles ~= nil then
453 table.insert(mission.vehicles, vehicle)
454 end
455 end
456 end
457 end
458
459 delete(xmlFile)
460
461 return true
462end

delete

Description
Deletes field mission manager
Definition
delete()
Code
466function MissionManager:delete()
467end

update

Description
Updates field mission ownage data from xml savegame file
Definition
update(string filename)
Arguments
stringfilenamexml filename
Code
472function MissionManager:update(dt)
473 if g_currentMission:getIsServer() then
474 self.generationTimer = self.generationTimer - g_currentMission.missionInfo.timeScale * dt
475
476 self:updateMissions(dt)
477
478 if table.getn(self.missions) < MissionManager.MAX_MISSIONS and self.generationTimer < g_time then
479 self:generateMissions(dt)
480
481 -- Limit generation
482 self.generationTimer = MissionManager.MISSION_GENERATION_INTERVAL
483 end
484 end
485end

getTransportMissionConfig

Description
Get mission configuration given the name
Definition
getTransportMissionConfig()

getTransportMissionConfigById

Description
Get a mission config given an ID. Used by TransportMission:readStream
Definition
getTransportMissionConfigById()

hasFarmActiveMission

Description
Get whether given farm has an active mission
Definition
hasFarmActiveMission()

startMission

Description
Start given mission for a farm.
Definition
startMission()

cancelMission

Description
Cancel mission: sets it to finished without success
Definition
cancelMission()

deleteMission

Description
Delete a mission
Definition
deleteMission()

dismissMission

Description
On a client it sends an event instead
Definition
dismissMission()

getActiveMissions

Description
Get a list of active missions
Definition
getActiveMissions()

getIsAnyMissionActive

Description
Get whether any mission is currently running
Definition
getIsAnyMissionActive()

canMissionStillRun

Description
Test whether the given mission is still able to run
Definition
canMissionStillRun()

addTransportMissionTrigger

Description
Add a new transport trigger. Requires triggerId and index properties.
Definition
addTransportMissionTrigger()

removeTransportMissionTrigger

Description
Remove a transport trigger.
Definition
removeTransportMissionTrigger()

generateNewFieldMission

Description
Generate a mission for given field. Returns nil if field already has an active mission
Definition
generateNewFieldMission()

assignGenerationTime

Description
Generation time is used for reliably sorting
Definition
assignGenerationTime()

getRandomVehicleGroup

Description
Get a randomly chosen group of vehicles fitting for given mission type and field size
Definition
getRandomVehicleGroup(missionType type, fieldSize size)
Arguments
missionTypetypeof mission (string)
fieldSizesizeof field: 'SMALL', 'MEDIUM', 'LARGE'
Return Values
Listofvehicles. Each element is a table with filanema and configuration properties.
Reward

getVehicleGroupFromIdentifier

Description
Used on the client. Make sure it never crashes on nil (patches)
Definition
getVehicleGroupFromIdentifier()

getFreeActiveMissionId

Description
Get a free activeMissionId, used for active missions only.
Definition
getFreeActiveMissionId()

validateMissionOnField

Description
Validate missions on given field, after something happened to the field (event)
Definition
validateMissionOnField()

getMissionMapValue

Description
Get a value at given world coordinates
Definition
getMissionMapValue()

getMissionForActiveMissionId

Description
Get the mission associated with the activeMissionId
Definition
getMissionForActiveMissionId()

MixerWagonHUDExtension

Description
Custom HUD drawing extension for MixerWagon.
-- Displays the fill levels of the mixer wagon.
--@category GUI

new

Description
Create a new instance of MixerWagonHUDExtension.
Definition
new(table vehicle, float uiScale, table uiTextColor, float uiTextSize)
Arguments
tablevehicleVehicle which has the specialization required by a sub-class
floatuiScaleCurrent UI scale
tableuiTextColorHUD text drawing color as an RGBA array
floatuiTextSizeHUD text size
Return Values
tableinstanceinstance of object

canDraw

Description
Determine if the HUD extension should be drawn.
Definition
canDraw()
Return Values
booleantrueif loading was successful else false

getDisplayHeight

Description
Get this HUD extension's display height.
Definition
getDisplayHeight()
Return Values
tableinstanceinstance of object
floatDisplayheight in screen space

draw

Description
Draw mixing ratio information for a mixing wagon when it is active.
Definition
draw(float leftPosX, float rightPosX, float posY)
Arguments
floatleftPosXLeft input help panel column start position
floatrightPosXRight input help panel column start position
floatposYCurrent input help panel drawing vertical offset
Return Values
booleantrueif loading was successful else false
floatModifiedinput help panel drawing vertical offset

ModHubCategoriesFrame

Description
ModHub categories frame
-- Displays categories.
--@category GUI

new

Description
Create a new ModHubCategoriesFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass

initialize

Description
Initialize with categories to be displayed.
Categories must be provided as an array of tables like {id=<id>, iconFilename=<path>, label=<text>}. This will add
a category element per entry to the display list.
Definition
initialize(table categories, function categoryClickedCallback, table headerIconUVs, string headerText)
Arguments
tablecategoriesCategory definitions array
functioncategoryClickedCallbackNotification callback for category activation(click/enter), signature: function(selectedId, baseCategoryIconUVs, baseCategoryLabel, clickedCategoryLabel)
tableheaderIconUVsUV coordinates of the header icon to display
stringheaderTextHeader text to display

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
floatnearCoCRadiusNear circle of confusion radius (nearCoCRadius = 0 means no near blur (pinhole camera))
floatnearBlurEndDistance from the camera center where near blur ends
floatfarCoCRadiusFar circle of confusion radius (farCoCRadius = 0 means no far blur (pinhole camera))
floatfarBlurStartDistance from the camera center where far blur starts
floatfarBlurEndDistance from the camera center where far blur ends

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()

updateScrollButtons

Description
Update scroll button visibility based on the currently visible list items.
Definition
updateScrollButtons()

onClickCategory

Description
Handle a click / button activation on a category.
Definition
onClickCategory()

onDoubleClickCategory

Description
Handle a double click on a category.
Definition
onDoubleClickCategory()

onCategorySelected

Description
Handle navigation selection of a category element.
Definition
onCategorySelected()
Return Values
booleanisAllowedstate change is allowed

onClickLeft

Description
Handle click on left navigation button.
Definition
onClickLeft()
Return Values
tableinstanceinstance of object

onClickRight

Description
Handle click on right navigation button.
Definition
onClickRight()
Return Values
booleantrueif loading was successful else false

onScroll

Description
Handle a list scrolling event.
Definition
onScroll()
Return Values
booleansuccesssuccess

ModHubDetailsFrame

Description
Shop items frame for the in-game menu shop.
-- Displays purchasable items of a common category in a horizontal list layout.
--@category GUI

new

Description
Create a new ModHubDetailsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
integerfillTypeIndexthe fillType index

setCategory

Description
Set the category to display.
Definition
setCategory()
Return Values
tablefillTypethe fillType object

setModInfo

Description
Set an ordered array of ShopDisplayItem instances to display in this frame.
Definition
setModInfo()
Return Values
tablefillTypeslist of fillTypes

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tablefillTypeCategoryfillType category object

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tablesuccesstrue if added else false

ModHubItemsFrame

Description
Shop items frame for the in-game menu shop.
-- Displays purchasable items of a common category in a horizontal list layout.
--@category GUI

new

Description
Create a new ModHubItemsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
tablefillTypeslist of fillTypes

setItemClickCallback

Description
Set the callback to use when an item is activated (for buying or selling).
Definition
setItemClickCallback()
Return Values
tablefillTypesfill types

setItemSelectCallback

Description
Set the callback to use when an item is selected in the view.
Definition
setItemSelectCallback()
Return Values
integerconverterIndexindex of converterIndex

setCategory

Description
Set the category to display.
Definition
setCategory()
Return Values
tableconverterDataconverter data

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tablesamplesample

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableinstanceinstance of object

updateScrollButtons

Description
Update scroll button visibility based on the currently visible list items.
Definition
updateScrollButtons()
Return Values
booleantrueif loading was successful else false

onClickItem

Description
Handle a click / button activation on an item.
Definition
onClickItem()
Return Values
booleansuccesssuccess

onDoubleClickItem

Description
Handle a double-click on an item.
Definition
onDoubleClickItem()
Return Values
tablefruitTypefruitType type object

onClickLeft

Description
Handle click on left navigation button.
Definition
onClickLeft()
Return Values
tablefruitthe fruit object

onClickRight

Description
Handle click on right navigation button.
Definition
onClickRight()
Return Values
tablefruitthe fruit object

onItemSelected

Description
Handle selection of an item.
Definition
onItemSelected()
Return Values
tablefruitTypesa list of fruitTypes

ModHubScreen

Description
Mode

new

Description
Create a new instance of ModHubScreen.
Definition
new(table target, table custom_mt, table messageCenter, table l10n, table inputManager, table modHubController, bool isConsoleVersion)
Arguments
tabletargetCallback target
tablecustom_mtSub-class meta table
tablemessageCenterMessageCenter reference
tablel10nI18N reference for text localization
tableinputManagerInputBinding reference
tablemodHubControllermodHubController reference
boolisConsoleVersionIf true, the game is running on a console
Return Values
tablefruitTypeCategoryfruitType category object

reset

Description
Reset menu state (and all pages).
Definition
reset()
Return Values
tablesuccesstrue if added else false

clickBackCallback

Description
Button function for backing out of the menu.
Definition
clickBackCallback()
Return Values
tablefruitTypeslist of fruitTypes

clearMenuButtonActions

Description
Clear menu button actions, events and callbacks.
Definition
clearMenuButtonActions()
Return Values
tablefruitTypesfruit types

assignMenuButtonInfo

Description
Assign menu button information to the in-game menu buttons.
Definition
assignMenuButtonInfo()
Return Values
tablefillTypesfill types

onMenuActionClick

Description
Handle a menu action click by calling one of the menu button callbacks.
Definition
onMenuActionClick()
Return Values
tablefillTypesfill types
boolTrueif no callback was present and no action was taken, false otherwise

onClickOk

Description
Handle menu confirmation input event.
Definition
onClickOk()
Return Values
floatliterPerSqmliter per sqm

onClickBack

Description
Handle menu back input event.
Definition
onClickBack()
Return Values
integerconverterIndexindex of converterIndex

onClickCancel

Description
Handle menu cancel input event.
Bound to quite the game to the main menu.
Definition
onClickCancel()
Return Values
tableconverterDataconverter data

onClickActivate

Description
Handle menu active input event.
Bound to save the game.
Definition
onClickActivate()
Return Values
tableinstanceinstance of object

updateButtonsPanel

Description
Update the buttons panel when a given page is visible.
Definition
updateButtonsPanel()
Return Values
booleantrueif loading was successful else false

makeSelfCallback

Description
Make a callback which encloses the self reference and handles arbitrary arguments afterwards.
Definition
makeSelfCallback()
Return Values
tablegameplayHintGroupa random gameplay hint group

MultiTextOptionElement

Description
Multiple choice text element.
-- This element requires a specific configuration setup to be properly used: In the configuration, it must contain the
following child elements in this order: 1. ButtonElement, 2. ButtonElement, 3. TextElement, 4. TextElement. The first
three elements are mandatory, as they are the buttons to change this element's value and the label which displays the
value. The fourth (text) element is optional and used as a header label for this element if defined.
--@category GUI
--@xmlConfig GuiElement#wrap bool [optional] If false, values will not cycle when the end or start of the value list is reached.

disableButtonSounds

Description
Disable automatic playing of sound samples in child buttons.
Definition
disableButtonSounds()

inputLeft

Description
Trigger a "left" input.
Definition
inputLeft(isShoulderButton If)
Arguments
isShoulderButtonIftrue, assume a shoulder button input (PC or console)

inputRight

Description
Trigger a "right" input.
Definition
inputRight(isShoulderButton If)
Arguments
isShoulderButtonIftrue, assume a shoulder button input (PC or console)

MultiValueTween

Description
Tween class which handles multiple values at the same time.
-- Start and end values must be passed in as arrays. The setter function must be able to handle as many arguments as
there were entries in the start and end values arrays: setter called as function(unpack(values)).
--@category GUI

new

Description
Create a new Tween.
Definition
new(table subClass, function setterFunction, table startValues, table endValues, float duration)
Arguments
tablesubClassSubclass metatable for inheritance
functionsetterFunctionValues setter function. Signature: callback(v1, ..., vn) or callback(target, v1, ..., vn).
tablestartValuesOriginal values
tableendValuesTarget values
floatdurationDuration of tween in milliseconds

setTarget

Description
Set a callback target for this tween.
If a target has been set, the setter function must support receiving the target as its first argument.
Definition
setTarget()

tweenValue

Description
Get the current tween value.
Definition
tweenValue()

applyValue

Description
Apply a value via the setter function.
Definition
applyValue()

Overlay

Description
Image display overlay.
-- This class is used to display textures or usually parts thereof as rectangular panels in the UI or on the HUD.
Example usages include button icons, showing images in the main menu or drawing the in-game map.
--@category GUI

new

Description
Create a new Overlay.
Definition
new(overlayFilename File, x Screen, y Screen, width Display, height Display)
Arguments
overlayFilenameFilepath of the source texture
xScreenposition x
yScreenposition y
widthDisplaywidth
heightDisplayheight

delete

Description
Delete this overlay.
Releases the texture file handle.
Definition
delete()

setColor

Description
Set this overlay's color.
The color is multiplied with the texture color. For no modification of the texture color, use full opaque white,
i.e. {1, 1, 1, 1}.
Definition
setColor(r Red, g Green, b Blue, a Alpha)
Arguments
rRedchannel
gGreenchannel
bBluechannel
aAlphachannel

setUVs

Description
Set this overlay's UVs which define the area to be displayed within the target texture.
Definition
setUVs(uvs UV)
Arguments
uvsUVcoordinates in the form of {u1, v1, u2, v2, u3, v3, u4, v4}

setPosition

Description
Set this overlay's position.
Definition
setPosition()

getPosition

Description
Get this overlay's position.
Definition
getPosition()
Return Values
floatXposition in screen space
floatYposition in screen space

setDimension

Description
Set this overlay's width and height.
Either value can be omitted (== nil) for no change.
Definition
setDimension()

resetDimensions

Description
Reset width, height and scale to initial values set in the constructor.
Definition
resetDimensions()

setInvertX

Description
Set horizontal flipping state.
Definition
setInvertX(invertX If)
Arguments
invertXIftrue, will set the overlay to display its image flipped horizontally

setRotation

Description
Set this overlay's rotation.
Definition
setRotation(rotation Rotation, centerX Rotation, centerY Rotation)
Arguments
rotationRotationin radians
centerXRotationpivot X position offset from overlay position in screen space
centerYRotationpivot Y position offset from overlay position in screen space

setScale

Description
Set this overlay's scale.
Multiplies the scale values with the initial dimensions and sets those as the current dimensions.
Definition
setScale(float scaleWidth, float scaleHeight)
Arguments
floatscaleWidthWidth scale factor
floatscaleHeightHeight scale factor

getScale

Description
Get this overlay's scale values.
Definition
getScale()
Return Values
floatWidthscale factor
floatHeightscale factor

render

Description
Render this overlay.
Definition
render()

setAlignment

Description
Set this overlay's alignment.
Definition
setAlignment(vertical Vertical, horizontal Horizontal)
Arguments
verticalVerticalalignment value, one of Overlay.ALIGN_VERTICAL_[...]
horizontalHorizontalalignment value, one of Overlay.ALIGN_HORIZONTAL_[...]

setIsVisible

Description
Set this overlay's visibility.
Definition
setIsVisible()

setImage

Description
Set a different image for this overlay.
The previously targeted image's handle will be released.
Definition
setImage(overlayFilename File)
Arguments
overlayFilenameFilepath to new target image

PagingElement

Description
Paging control element.
-- Organizes grouped elements into pages to be displayed one at a time. To set it up, one defines several
same-sized container elements (e.g. bare GuiElement) as children of the PagingElement to hold the pages' contents.
The pages should be given #name properties which are resolved to a localization text with a prepended "ui_" prefix.
On loading, any named child element of this PagingElement will be added as a page.
--@category GUI
--@xmlConfig GuiElement#onPageChange callback [optional] onPageChangeCallback(pageIndex, pageMappingIndex, element) Called when the page changes. Receives the current index in all pages, the current index in all enabled pages and this element.

setPage

Description
Set the current page index.
Indices are based on mapped pages, which are all available and visible pages added to this element.
Definition
setPage(pageMappingIndex Index)
Arguments
pageMappingIndexIndexof page in page mappings
Return Values
boolTrueif the page changed

getNextID

Description
Get a new page ID based on an internal counter.
Definition
getNextID()

addPage

Description
Add a new page.
Definition
addPage(id Page, element Page, title Page, index [optional])
Arguments
idPageID
elementPagecontainer GuiElement
titlePagetitle for displaying
index[optional]Insertion index for page. If undefined or outside of valid range, will add the page at the end.

getVisiblePagesCount

Description
Get the number of currently visible pages.
Definition
getVisiblePagesCount()

getPageIdByElement

Description
Get a page ID by the page container element reference.
Definition
getPageIdByElement(element Page)
Arguments
elementPagecontainer GuiElement instance
Return Values
Page

getPageElementByIndex

Description
Get a page container element by page index.
Definition
getPageElementByIndex(pageIndex Index)
Arguments
pageIndexIndexof page in all (incl. disabled and invisible) pages
Return Values
PagecontainerGuiElement instance

getPageIndexByElement

Description
Get the page index in this element's page array for a given element reference.
Definition
getPageIndexByElement(table element)
Arguments
tableelementGuiElement instance
Return Values
intPageindex

getPageMappingIndexByElement

Description
Get the page index in this elements page mapping array (visible pages) for a given element reference.
Definition
getPageMappingIndexByElement(table element)
Arguments
tableelementGuiElement instance
Return Values
intPagemapping index

removePageByElement

Description
Remove a page, identified by its page container element, from this element.
The method only removes the page from the display collection. Callers must take care of the page element's clean-up,
e.g. removing it from the element hierarchy.
Definition
removePageByElement(pageElement Page)
Arguments
pageElementPagecontainer element

getCurrentPageId

Description
Get the page ID of the currently displayed page.
Definition
getCurrentPageId()

getPageMappingIndex

Description
Get the index of a page in the page mappings (only visible pages) by page ID.
Definition
getPageMappingIndex()

getIsPageDisabled

Description
Determine if a page, identified by page ID, is disabled.
Definition
getIsPageDisabled()

getPageById

Description
Get a page by ID.
Definition
getPageById()

setPageIdDisabled

Description
Set a page's disabled state.
Definition
setPageIdDisabled(pageId Page, disabled True)
Arguments
pageIdPageID
disabledTruefor disabled, false for enabled

getPageTitles

Description
Get page titles of all pages which were visible at the latest call to updatePageMapping()
Definition
getPageTitles()

Placeable

Description
Base Class for placeables
-- Note about terrain modification on placement:
If terrain modification is enabled using the placeable.leveling#requireLeveling attribute, the configuration needs
at least one leveling area to be defined (ramps are optional). These areas represent parallelograms which are passed
to terrain modification functions. They are defined by start, width and height nodes which in this case should be
set up to form rectangular shapes. For the best results, create a new transform group for each area at the starting
positions and add separate nodes for the three defining points in the placeable object I3D file.
--@category Placeables
--@xmlConfig placeable.filename string File name of associated I3D file

onCreateGlowMaterial

Description
On create glow material
Definition
onCreateGlowMaterial(empty empty, integer id)
Arguments
emptyemptyempty
integeridid of node
Code
90function Placeable.onCreateGlowMaterial(_, id)
91 if getHasShaderParameter(id, "colorScale") then
92 Placeable.GLOW_MATERIAL = getMaterial(id, 0)
93 end
94end

new

Description
Creating placeable
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
106function Placeable:new(isServer, isClient, customMt)
107 local self = Object:new(isServer, isClient, customMt or Placeable_mt)
108 self.nodeId = 0
109
110 self.useRandomYRotation = false
111 self.useManualYRotation = false
112 self.placementSizeX = 1
113 self.placementSizeZ = 1
114 self.placementTestSizeX = 1
115 self.placementTestSizeZ = 1
116 self.requireLeveling = false
117 self.maxSmoothDistance = 3
118 self.maxSlope = MathUtil.degToRad(45)
119 self.maxEdgeAngle = MathUtil.degToRad(45)
120 self.smoothingGroundType = nil
121
122 self.triggerMarkers = {}
123 self.clearAreas = {}
124 self.levelAreas = {}
125 self.rampAreas = {}
126 self.foliageAreas = {}
127 self.samples = {}
128 self.pickObjects = {}
129 self.animatedObjects = {}
130 self.triggerMarkers = {}
131 self.mapHotspots = {}
132 self.isolated = false
133 self.isDeleted = false
134 self.useMultiRootNode = false
135 self.price = 0
136 self.age = 0
137 self.isInPreviewMode = nil
138 self.placementPositionSnapSize = 0
139 self.placementRotationSnapAngle = 0
140
141 -- defines that a placeable is placed on a map directly, and with a unique ID
142 self.mapBoundId = nil
143
144 registerObjectClassName(self, "Placeable")
145 return self
146end

delete

Description
Deleting placeable
Definition
delete()
Code
150function Placeable:delete()
151 self.isDeleted = true
152 if self.i3dFilename ~= nil then
153 g_i3DManager:releaseSharedI3DFile(self.i3dFilename, nil, true)
154 end
155
156 for _, node in ipairs(self.triggerMarkers) do
157 g_currentMission:removeTriggerMarker(node)
158 end
159
160 if #self.rampAreas > 0 then
161 for _, area in pairs(self.rampAreas) do
162 if area.previewShape then
163 g_i3DManager:releaseSharedI3DFile(Placeable.RAMP_PREVIEW_PATH, nil, true)
164 end
165 end
166 end
167
168 for _, animatedObject in ipairs(self.animatedObjects) do
169 animatedObject:delete()
170 end
171
172 for _, hotspot in ipairs(self.mapHotspots) do
173 g_currentMission.hud:removeMapHotspot(hotspot)
174 hotspot:delete()
175 end
176
177 if g_currentMission ~= nil and g_currentMission.environment ~= nil then
178 g_currentMission.environment:removeDayChangeListener(self)
179 g_currentMission.environment:removeWeatherChangeListener(self)
180 g_currentMission.environment:removeHourChangeListener(self)
181 end
182
183 unregisterObjectClassName(self)
184 g_currentMission:removeItemToSave(self)
185 g_currentMission:removePlaceable(self)
186 for _, node in pairs(self.pickObjects) do
187 g_currentMission:removeNodeObject(node)
188 end
189
190 if self.nodeId ~= 0 and entityExists(self.nodeId) then
191 self:setCollisionMask(self.nodeId, 0)
192 setVisibility(self.nodeId, false)
193 else
194 self.nodeId = 0
195 end
196
197 if self.isClient then
198 g_soundManager:deleteSamples(self.samples)
199 end
200
201 g_currentMission:removeOwnedItem(self)
202
203 g_currentMission:addPlaceableToDelete(self, 300)
204 Placeable:superClass().delete(self)
205end

deleteFinal

Description
Deleting placeable final
Definition
deleteFinal()
Code
209function Placeable:deleteFinal()
210 if self.nodeId ~= 0 then
211 delete(self.nodeId)
212 self.nodeId = 0
213 end
214end

setCollisionMask

Description
Set collision mask of node and its children
Definition
setCollisionMask(integer nodeId, integer mask)
Arguments
integernodeIdid of node
integermaskcollision mask
Code
220function Placeable:setCollisionMask(nodeId, mask)
221 setCollisionMask(nodeId, mask)
222 local numChildren = getNumOfChildren(nodeId)
223 for i=0,numChildren-1 do
224 local childId = getChildAt(nodeId, i)
225 self:setCollisionMask(childId, mask)
226 end
227end

getIsPlayerInRange

Description
Returns true if player is in range
Definition
getIsPlayerInRange(float distance, table player)
Arguments
floatdistancedistance
tableplayerplayer
Return Values
booleanisInRangeis in range
Code
234function Placeable:getIsPlayerInRange(distance, player)
235 if self.nodeId ~= 0 then
236 distance = Utils.getNoNil(distance, 10)
237 if player == nil then
238 for _, player in pairs(g_currentMission.players) do
239 if self:isInActionDistance(player, self.nodeId, distance) then
240 return true, player
241 end
242 end
243 else
244 return self:isInActionDistance(player, self.nodeId, distance), player
245 end
246 end
247 return false, nil
248end

isInActionDistance

Description
Returns true if player is in range
Definition
isInActionDistance(table player, integer refNode, float distance)
Arguments
tableplayerplayer
integerrefNodeid of reference node
floatdistancedistance
Return Values
booleanisInRangeis in range
Code
256function Placeable:isInActionDistance(player, refNode, distance)
257 local x,_,z = getWorldTranslation(refNode)
258 local px,_,pz = getWorldTranslation(player.rootNode)
259 local dx,dz = px-x, pz-z
260 if dx*dx + dz*dz < distance*distance then
261 return true
262 end
263
264 return false
265end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
271function Placeable:readStream(streamId, connection)
272 Placeable:superClass().readStream(self, streamId, connection)
273 if connection:getIsServer() then
274 local configFileName = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId))
275 local x=streamReadFloat32(streamId)
276 local y=streamReadFloat32(streamId)
277 local z=streamReadFloat32(streamId)
278 local rx=NetworkUtil.readCompressedAngle(streamId)
279 local ry=NetworkUtil.readCompressedAngle(streamId)
280 local rz=NetworkUtil.readCompressedAngle(streamId)
281 local isNew = self.configFileName == nil
282 if isNew then
283 self:load(configFileName, x,y,z, rx,ry,rz, false, false)
284 end
285 self.age = streamReadUInt16(streamId)
286 self.price = streamReadInt32(streamId)
287
288 if isNew then
289 self:finalizePlacement()
290 end
291
292 for _, animatedObject in ipairs(self.animatedObjects) do
293 local animatedObjectId = NetworkUtil.readNodeObjectId(streamId)
294 animatedObject:readStream(streamId, connection)
295 g_client:finishRegisterObject(animatedObject, animatedObjectId)
296 end
297 end
298end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
304function Placeable:writeStream(streamId, connection)
305 Placeable:superClass().writeStream(self, streamId, connection)
306 if not connection:getIsServer() then
307 streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.configFileName))
308 local x,y,z = getTranslation(self.nodeId)
309 local x_rot,y_rot,z_rot = getRotation(self.nodeId)
310 streamWriteFloat32(streamId, x)
311 streamWriteFloat32(streamId, y)
312 streamWriteFloat32(streamId, z)
313 NetworkUtil.writeCompressedAngle(streamId, x_rot)
314 NetworkUtil.writeCompressedAngle(streamId, y_rot)
315 NetworkUtil.writeCompressedAngle(streamId, z_rot)
316 streamWriteUInt16(streamId, self.age)
317 streamWriteInt32(streamId, self.price)
318
319 for _, animatedObject in ipairs(self.animatedObjects) do
320 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(animatedObject))
321 animatedObject:writeStream(streamId, connection)
322 g_server:registerObjectInStream(connection, animatedObject)
323 end
324 end
325end

createNode

Description
Create node
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleansuccesssuccess
Code
362function Placeable:createNode(i3dFilename)
363 self.i3dFilename = i3dFilename
364 local nodeRoot = g_i3DManager:loadSharedI3DFile(i3dFilename, nil, false, false)
365 if nodeRoot == 0 then
366 return false
367 end
368
369 if self.useMultiRootNode then
370 link(getRootNode(), nodeRoot)
371 self.nodeId = nodeRoot
372 else
373 local nodeId = getChildAt(nodeRoot, 0)
374 if nodeId == 0 then
375 delete(nodeRoot)
376 return false
377 end
378 link(getRootNode(), nodeId)
379 delete(nodeRoot)
380 self.nodeId = nodeId
381 end
382
383 return true
384end

setPreviewMaterials

Description
Sets the preview material to all nodes in the placeable
Definition
setPreviewMaterials(integer node, table nodeTable)
Arguments
integernodeid of node
tablenodeTabletable to save the nodes
Code
390function Placeable:setPreviewMaterials(node, nodeTable)
391 if getHasClassId(node, ClassIds.SHAPE) then
392 nodeTable[node] = node
393 setMaterial(node, Placeable.GLOW_MATERIAL, 0)
394 end
395
396 local numChildren = getNumOfChildren(node)
397 for i=0, numChildren-1 do
398 self:setPreviewMaterials(getChildAt(node, i), nodeTable)
399 end
400end

setPlaceablePreviewState

Description
Set placable preview state
Definition
setPlaceablePreviewState(int state)
Arguments
intstatePlacement state [Placeable.PREVIEW_STATE.CHECKING | Placeable.PREVIEW_STATE.VALID | Placeable.PREVIEW_STATE.INVALID]
Code
405function Placeable:setPlaceablePreviewState(state)
406 if not self.isInPreviewMode then
407 self.isInPreviewMode = true
408
409 self.previewGlowingNodes = {}
410 if Placeable.GLOW_MATERIAL ~= nil then
411 -- replace materials with glowing material
412 self:setPreviewMaterials(self.nodeId, self.previewGlowingNodes)
413
414 -- load preview shapes for ramps
415 for _, area in pairs(self.rampAreas) do
416 local rampNode = g_i3DManager:loadSharedI3DFile(Placeable.RAMP_PREVIEW_PATH)
417 if rampNode ~= 0 then
418 link(area.root, rampNode) -- link the ramp root to the area -> can rotate the entire area hierarchy for preview
419 area.previewNode = rampNode
420
421 local rampRootTransform = getChildAt(rampNode, 0)
422 local rampShape = getChildAt(rampRootTransform, 0)
423 area.previewShape = rampShape
424
425 setMaterial(rampShape, Placeable.GLOW_MATERIAL, 0)
426
427 -- scale the ramp preview to the area dimensions, this assumes a rectangular area
428 local scaleX, _, scaleZ = getScale(rampShape)
429 local startX, startY, startZ = getWorldTranslation(area.start)
430 local widthX, widthY, widthZ = getWorldTranslation(area.width)
431 local heightX, heightY, heightZ = getWorldTranslation(area.height)
432
433 local width = MathUtil.vector3Length(widthX - startX, widthY - startY, widthZ - startZ)
434 local height = MathUtil.vector3Length(heightX - startX, heightY - startY, heightZ - startZ)
435
436 setScale(rampShape, width, Placeable.RAMP_PREVIEW_THICKNESS, height)
437 end
438 end
439 end
440 end
441 if Placeable.GLOW_MATERIAL ~= nil then
442 local color = Placeable.PREVIEW_COLOR[state]
443 for node in pairs(self.previewGlowingNodes) do
444 setShaderParameter(node, "colorScale", color[1], color[2], color[3], color[4], false)
445 end
446
447 local rampColor = Placeable.PREVIEW_RAMP_COLOR[state]
448 for _, area in pairs(self.rampAreas) do
449 if area.previewShape ~= nil then
450 setShaderParameter(area.previewShape, "colorScale", rampColor[1], rampColor[2], rampColor[3], rampColor[4], false)
451 end
452 end
453 end
454end

load

Description
Load placeable
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
467function Placeable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
468 self.configFileName = xmlFilename
469 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename)
470
471 local xmlFile = loadXMLFile("TempXML", xmlFilename)
472 if xmlFile == 0 then
473 return false
474 end
475 local i3dFilename = getXMLString(xmlFile, "placeable.filename")
476 self.placementSizeX = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.placement#sizeX"), self.placementSizeX)
477 self.placementSizeZ = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.placement#sizeZ"), self.placementSizeZ)
478 self.placementTestSizeX = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.placement#testSizeX"), self.placementSizeX)
479 self.placementTestSizeZ = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.placement#testSizeZ"), self.placementSizeZ)
480 self.useRandomYRotation = Utils.getNoNil(getXMLBool(xmlFile, "placeable.placement#useRandomYRotation"), self.useRandomYRotation)
481 self.useManualYRotation = Utils.getNoNil(getXMLBool(xmlFile, "placeable.placement#useManualYRotation"), self.useManualYRotation)
482 self.alignToWorldY = Utils.getNoNil(getXMLBool(xmlFile, "placeable.placement#alignToWorldY"), true)
483 self.placementPositionSnapSize = math.abs(Utils.getNoNil(getXMLFloat(xmlFile, "placeable.placement#placementPositionSnapSize"), 0.0))
484 self.placementRotationSnapAngle = math.rad(math.abs(Utils.getNoNil(getXMLFloat(xmlFile, "placeable.placement#placementRotationSnapAngle"), 0.0)))
485
486 self.incomePerHour = getXMLFloat(xmlFile, "placeable.incomePerHour" .. g_currentMission.missionInfo.difficulty)
487 -- fallback for old single value format
488 if self.incomePerHour == nil then
489 self.incomePerHour = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.incomePerHour"), 0)
490 if g_currentMission.missionInfo.difficulty == 1 then
491 self.incomePerHour = self.incomePerHour * 1.5
492 elseif g_currentMission.missionInfo.difficulty == 3 then
493 self.incomePerHour = self.incomePerHour / 1.5
494 end
495 end
496
497 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
498 if storeItem ~= nil then
499 if self.price == 0 or self.price == nil then
500 self.price = StoreItemUtil.getDefaultPrice(storeItem)
501 end
502
503 if g_currentMission ~= nil and storeItem.canBeSold then
504 g_currentMission.environment:addDayChangeListener(self)
505 end
506 end
507
508 if i3dFilename == nil then
509 delete(xmlFile)
510 return false
511 end
512 self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory)
513
514 if not self:createNode(self.i3dFilename) then
515 delete(xmlFile)
516 return false
517 end
518 self:initPose(x,y,z, rx,ry,rz, initRandom)
519
520 if hasXMLProperty(xmlFile, "placeable.dayNightObjects") then
521 local i = 0
522 while true do
523 local key = string.format("placeable.dayNightObjects.dayNightObject(%d)", i)
524 if not hasXMLProperty(xmlFile, key) then
525 break
526 end
527
528 local node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key.."#node"))
529 if node ~= nil then
530 if self.dayNightObjects == nil then
531 self.dayNightObjects = {}
532 g_currentMission.environment:addWeatherChangeListener(self)
533 end
534
535 local visibleDay = getXMLBool(xmlFile, key.."#visibleDay")
536 local visibleNight = getXMLBool(xmlFile, key.."#visibleNight")
537 local intensityDay = getXMLFloat(xmlFile, key.."#intensityDay")
538 local intensityNight = getXMLFloat(xmlFile, key.."#intensityNight")
539
540 table.insert(self.dayNightObjects, {node=node, visibleDay=visibleDay, visibleNight=visibleNight, intensityDay=intensityDay, intensityNight=intensityNight})
541 end
542 i = i + 1
543 end
544 end
545
546 -- load leveling properties
547 self.requireLeveling = Utils.getNoNil(getXMLBool(xmlFile, "placeable.leveling#requireLeveling"), self.requireLeveling)
548 if self.requireLeveling then
549 self.maxSmoothDistance = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.leveling#maxSmoothDistance"), 3)
550 self.maxSlope = MathUtil.degToRad(Utils.getNoNil(getXMLFloat(xmlFile, "placeable.leveling#maxSlope"), 45))
551 self.maxEdgeAngle = MathUtil.degToRad(Utils.getNoNil(getXMLFloat(xmlFile, "placeable.leveling#maxEdgeAngle"), 45))
552 self.smoothingGroundType = getXMLString(xmlFile, "placeable.leveling#smoothingGroundType")
553 end
554
555 self:loadAreasFromXML(self.clearAreas, xmlFile, "placeable.clearAreas.clearArea(%d)", false, false)
556 self:loadAreasFromXML(self.levelAreas, xmlFile, "placeable.leveling.levelAreas.levelArea(%d)", false, true) -- load leveling info
557 self:loadAreasFromXML(self.rampAreas, xmlFile, "placeable.leveling.rampAreas.rampArea(%d)", true, true) -- load ramps and leveling info
558 self:loadAreasFromXML(self.foliageAreas, xmlFile, "placeable.foliageAreas.foliageArea(%d)", false, false, true) -- load ramps and leveling info
559
560 if hasXMLProperty(xmlFile, "placeable.tipOcclusionUpdateArea") then
561 local sizeX = getXMLFloat(xmlFile, "placeable.tipOcclusionUpdateArea#sizeX")
562 local sizeZ = getXMLFloat(xmlFile, "placeable.tipOcclusionUpdateArea#sizeZ")
563
564 if sizeX ~= nil and sizeZ ~= nil then
565 local centerX = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.tipOcclusionUpdateArea#centerX"), 0)
566 local centerZ = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.tipOcclusionUpdateArea#centerZ"), 0)
567 self.tipOcclusionUpdateArea = {centerX, centerZ, sizeX, sizeZ}
568 end
569 end
570
571 if not self.alignToWorldY then
572 self.pos1Node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.placement#pos1Node"))
573 self.pos2Node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.placement#pos2Node"))
574 self.pos3Node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.placement#pos3Node"))
575 if self.pos1Node == nil or self.pos2Node == nil or self.pos3Node == nil then
576 self.alignToWorldY = true
577 print("Warning: Pos1Node, Pos2Node and Pos3Node has to be set when alignToWorldY is false!")
578 end
579 end
580
581 if hasXMLProperty(xmlFile, "placeable.animatedObjects") then
582 local i = 0
583 while true do
584 local animationKey = string.format("placeable.animatedObjects.animatedObject(%d)", i)
585 if not hasXMLProperty(xmlFile, animationKey) then
586 break
587 end
588
589 local animatedObject = AnimatedObject:new(self.isServer, self.isClient)
590 if not animatedObject:load(self.nodeId, xmlFile, animationKey) then
591 print("Error: Failed to load animated object " .. tostring(i))
592 else
593 if self.isServer then
594 animatedObject:register(true)
595 end
596
597 table.insert(self.animatedObjects, animatedObject)
598 end
599
600 i = i + 1
601 end
602 end
603
604 local i = 0
605 while true do
606 local triggerMarkerKey = string.format("placeable.triggerMarkers.triggerMarker(%d)", i)
607 if not hasXMLProperty(xmlFile, triggerMarkerKey) then
608 break
609 end
610
611 local node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, triggerMarkerKey.."#node"))
612 if node ~= nil then
613 table.insert(self.triggerMarkers, node)
614 g_currentMission:addTriggerMarker(node)
615 end
616
617 i = i + 1
618 end
619
620 if hasXMLProperty(xmlFile, "placeable.hotspots") then
621 local i = 0
622 while true do
623 local hotspotKey = string.format("placeable.hotspots.hotspot(%d)", i)
624 if not hasXMLProperty(xmlFile, hotspotKey) then
625 break
626 end
627
628 local hotspot = self:loadHotspotFromXML(xmlFile, hotspotKey)
629 if hotspot ~= nil then
630 g_currentMission:addMapHotspot(hotspot)
631 table.insert(self.mapHotspots, hotspot)
632 end
633
634 i = i + 1
635 end
636 end
637
638 if self.isClient then
639 self.samples.idle = g_soundManager:loadSampleFromXML(xmlFile, "placeable.sounds", "idle", self.baseDirectory, self.nodeId, 1, AudioGroup.ENVIRONMENT, nil, nil)
640 end
641
642 delete(xmlFile)
643
644 return true
645end

loadAreasFromXML

Description
Load area definitions from XML into an area array.
Definition
loadAreasFromXML(table areaArray, string xmlFile, string xmlPathTemplate, bool isRamp)
Arguments
tableareaArrayArray instance which receives loaded area definitions.
stringxmlFileLoaded XML file handle
stringxmlPathTemplateXML element path template for an area type
boolisRampIf true, the targeted areas are ramps

loadAreaFromXML

Description
Load a single area definition from XML.
Areas are defined by three nodes: start, width and height. The start node denotes the origin of the area, while width
and height provide the dimensions of the spanned parallelogram. Usage of areas include clear areas (foliage is
cleared) and leveling areas (terrain is leveled) around placeable objects.
Definition
loadAreaFromXML(table area, integer xmlFile, string key, bool isRamp)
Arguments
tableareaEmpty area definition table which receives the loaded node IDs.
integerxmlFileID of the XML file
stringkeyString Key to the XML element
boolisRampIf true, the targeted areas are ramps
Return Values
booleansuccesssuccess
Code
685function Placeable:loadAreaFromXML(area, xmlFile, key, isRamp, isLeveling)
686 local start = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key .. "#startNode"))
687 local width = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key .. "#widthNode"))
688 local height = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key .. "#heightNode"))
689
690 if start ~= nil and width ~= nil and height ~= nil then
691 area.root = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key .. "#rootNode"))
692 area.start = start
693 area.width = width
694 area.height = height
695 area.texture = getXMLString(xmlFile, key .. "#texture")
696
697 if isRamp then
698 local rx, ry, rz = getRotation(area.root)
699 area.baseRotation = {rx, ry, rz} -- store base rotation for resetting during preview
700 local rampSlope = getXMLFloat(xmlFile, key .. "#maxSlope")
701 area.maxSlope = rampSlope and MathUtil.degToRad(rampSlope) or self.maxSlope
702 end
703
704 if isLeveling then
705 area.groundType = getXMLString(xmlFile, key .. "#groundType")
706 end
707
708 return true
709 end
710
711 return false
712end

loadFoliageAreaFromXML

Description
Load foliage definitons from XML.
Definition
loadFoliageAreaFromXML()
Code
716function Placeable:loadFoliageAreaFromXML(area, xmlFile, key)
717 local rootNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key .. "#rootNode"))
718 local fruitType = getXMLString(xmlFile, key .. "#fruitType")
719 local fruitTypeDesc = g_fruitTypeManager:getFruitTypeByName(fruitType)
720 local state = getXMLInt(xmlFile, key .. "#state")
721
722 if rootNode ~= nil and fruitTypeDesc ~= nil then
723 area.fruitType = fruitTypeDesc.index
724 area.fieldDimensions = rootNode
725 area.fruitState = Utils.getNoNil(state, fruitTypeDesc.maxHarvestingGrowthState - 1)
726
727 return true
728 end
729
730 return false
731end

loadHotspotFromXML

Description
Load hotspot from XML definitons
Definition
loadHotspotFromXML()
Code
735function Placeable:loadHotspotFromXML(xmlFile, key)
736 local name = Utils.getNoNil(getXMLString(xmlFile, key.."#name"), "")
737
738 local category = Utils.getNoNil(getXMLString(xmlFile, key.."#category"), "CATEGORY_TRIGGER")
739 if MapHotspot[category] ~= nil then
740 category = MapHotspot[category]
741 else
742 category = MapHotspot.CATEGORY_DEFAULT
743 end
744
745 local hotspot = MapHotspot:new(name, category)
746
747 local text = g_i18n:convertText(Utils.getNoNil(getXMLString(xmlFile, key.."#fullName"), ""))
748 if text ~= "" then
749 local showName = Utils.getNoNil(getXMLBool(xmlFile, key.."#showName"), false)
750
751 hotspot:setText(text, not showName)
752 end
753
754 local imageFilename = getXMLString(xmlFile, key.."#imageFilename")
755 if imageFilename ~= nil then
756 imageFilename = Utils.getFilename(imageFilename, self.baseDirectory)
757 end
758
759 local imageUVs = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#imageUVs"), 4)
760 local imageName = getXMLString(xmlFile, key.."#imageName")
761 if imageName ~= nil and MapHotspot.UV[imageName] ~= nil then
762 imageUVs = MapHotspot.UV[imageName]
763 end
764 if imageUVs ~= nil then
765 imageUVs = getNormalizedUVs(imageUVs)
766 end
767 if imageUVs ~= nil then
768 local baseColor = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#baseColor"), 4)
769 hotspot:setBorderedImage(imageFilename, imageUVs, baseColor)
770 end
771
772 local linkNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key .. "#linkNode"))
773 if linkNode == nil then
774 linkNode = self.nodeId
775 end
776 hotspot:setLinkedNode(linkNode)
777
778 local width = getXMLFloat(xmlFile, key.."#width")
779 local height = getXMLFloat(xmlFile, key.."#height")
780 if width ~= nil and heigth ~= nil then
781 hotspot:setSize(width, height)
782 end
783
784 hotspot:setBlinking(Utils.getNoNil(getXMLBool(xmlFile, key.."#blinking"), false))
785 hotspot:setPersistent(Utils.getNoNil(getXMLBool(xmlFile, key.."#persistent"), false))
786 hotspot:setRenderLast(Utils.getNoNil(getXMLBool(xmlFile, key.."#renderLast"), false))
787
788 local textSize = getXMLInt(xmlFile, key.."#textSize")
789 if textSize ~= nil then
790 _, textSize = getNormalizedScreenValues(0, textSize)
791 hotspot:setTextOptions(textSize)
792 end
793
794 local hotspotTextOffset = Utils.getNoNil(getXMLString(xmlFile, key .. "#hotspotTextOffset"), "0px 0px")
795 hotspot:setRawTextOffset(hotspotTextOffset)
796
797 local textColor = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#textColor"), 4)
798 hotspot:setTextOptions(nil, nil, nil, textColor)
799
800 return hotspot
801end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
805function Placeable:finalizePlacement()
806 if self.isInPreviewMode then
807 print("Error: Can't finalize placement of preview placeables")
808 end
809 if not self.isolated then
810
811 self:alignToTerrain()
812
813 addToPhysics(self.nodeId)
814 g_currentMission:addPlaceable(self)
815 g_currentMission:addItemToSave(self)
816 g_currentMission:addOwnedItem(self)
817 self:collectPickObjects(self.nodeId)
818
819 for _, node in pairs(self.pickObjects) do
820 g_currentMission:addNodeObject(node, self)
821 end
822
823 local missionInfo = g_currentMission.missionInfo
824 if self.isServer then
825 if not self.isLoadedFromSavegame or
826 (missionInfo.isValid and not (missionInfo:getIsTipCollisionValid(g_currentMission) and missionInfo:getIsPlacementCollisionValid(g_currentMission))) then
827 self:setTipOcclusionAreaDirty()
828 end
829 end
830 end
831
832 if self.isClient then
833 g_soundManager:playSample(self.samples.idle)
834 end
835
836 -- initially update dayNightObjects
837 self:weatherChanged()
838 g_currentMission.environment:addHourChangeListener(self)
839
840 local x,_,z = getWorldTranslation(self.nodeId)
841 self.farmlandId = g_farmlandManager:getFarmlandIdAtWorldPosition(x, z)
842
843 for _, hotspot in ipairs(self.mapHotspots) do
844 hotspot:setOwnerFarmId(self:getOwnerFarmId())
845 end
846
847 g_messageCenter:publish(MessageType.FARM_PROPERTY_CHANGED, {self:getOwnerFarmId()})
848end

setTipOcclusionAreaDirty

Description
Set tip occlusion area dirty
Definition
setTipOcclusionAreaDirty()
Code
852function Placeable:setTipOcclusionAreaDirty()
853 if self.tipOcclusionUpdateArea ~= nil and self.nodeId ~= 0 then
854 local x, z, sizeX, sizeZ = unpack(self.tipOcclusionUpdateArea)
855 local x1,_,z1 = localToWorld(self.nodeId, x+sizeX*0.5, 0, z+sizeZ*0.5)
856 local x2,_,z2 = localToWorld(self.nodeId, x-sizeX*0.5, 0, z+sizeZ*0.5)
857 local x3,_,z3 = localToWorld(self.nodeId, x+sizeX*0.5, 0, z-sizeZ*0.5)
858 local x4,_,z4 = localToWorld(self.nodeId, x-sizeX*0.5, 0, z-sizeZ*0.5)
859 local minX = math.min(math.min(x1, x2), math.min(x3, x4))
860 local maxX = math.max(math.max(x1, x2), math.max(x3, x4))
861 local minZ = math.min(math.min(z1, z2), math.min(z3, z4))
862 local maxZ = math.max(math.max(z1, z2), math.max(z3, z4))
863 g_densityMapHeightManager:setCollisionMapAreaDirty(minX, minZ, maxX, maxZ)
864 end
865end

alignToTerrain

Description
Align placeable to terrain
Definition
alignToTerrain()
Code
869function Placeable:alignToTerrain()
870 if not self.alignToWorldY then
871 local x1,y1,z1 = getWorldTranslation(self.nodeId)
872 y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,y1,z1)
873 setTranslation(self.nodeId, x1,y1,z1)
874 local x2,y2,z2 = getWorldTranslation(self.pos1Node)
875 y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,y2,z2)
876 local x3,y3,z3 = getWorldTranslation(self.pos2Node)
877 y3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,y3,z3)
878 local x4,y4,z4 = getWorldTranslation(self.pos3Node)
879 y4 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x4,y4,z4)
880 local dirX = x2 - x1
881 local dirY = y2 - y1
882 local dirZ = z2 - z1
883 local dir2X = x3 - x4
884 local dir2Y = y3 - y4
885 local dir2Z = z3 - z4
886 local upX,upY,upZ = MathUtil.crossProduct(dir2X, dir2Y, dir2Z, dirX, dirY, dirZ)
887 setDirection(self.nodeId, dirX, dirY, dirZ, upX,upY,upZ)
888 end
889end

clearFoliageAndTipAreas

Description
Clear foliage and tipAny from clearAreas
Definition
clearFoliageAndTipAreas()
Code
893function Placeable:clearFoliageAndTipAreas()
894 if self.isServer then
895 for _, areas in pairs{self.clearAreas, self.levelAreas, self.rampAreas} do
896 for _, area in pairs(areas) do
897 local x,_,z = getWorldTranslation(area.start)
898 local x1,_,z1 = getWorldTranslation(area.width)
899 local x2,_,z2 = getWorldTranslation(area.height)
900 -- clear foliage
901 FSDensityMapUtil.removeFieldArea(x, z, x1, z1, x2, z2)
902 FSDensityMapUtil.removeWeedArea(x, z, x1, z1, x2, z2)
903 FSDensityMapUtil.eraseTireTrack(x, z, x1, z1, x2, z2)
904 -- clear tipAny
905 DensityMapHeightUtil.clearArea(x, z, x1, z1, x2, z2)
906 end
907 end
908
909 -- Add foliage again
910 for _, area in pairs(self.foliageAreas) do
911 FieldUtil.setAreaFruit(area.fieldDimensions, area.fruitType, area.fruitState)
912 end
913 end
914end

initPose

Description
Initialize pose
Definition
initPose(float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
floatxx world position
floatyy world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Code
925function Placeable:initPose(x,y,z, rx,ry,rz, initRandom)
926 setTranslation(self.nodeId, x, y, z)
927 setRotation(self.nodeId, rx, ry, rz)
928end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
933function Placeable:collectPickObjects(node)
934 if getRigidBodyType(node) ~= "NoRigidBody" then
935 table.insert(self.pickObjects, node)
936 end
937 local numChildren = getNumOfChildren(node)
938 for i=1, numChildren do
939 self:collectPickObjects(getChildAt(node, i-1))
940 end
941end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
949function Placeable:loadFromXMLFile(xmlFile, key, resetVehicles)
950 local x,y,z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#position"))
951 local xRot,yRot,zRot = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotation"))
952 if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then
953 return false
954 end
955
956 xRot = math.rad(xRot)
957 yRot = math.rad(yRot)
958 zRot = math.rad(zRot)
959
960 local xmlFilename = getXMLString(xmlFile, key.."#filename")
961 if xmlFilename == nil then
962 return false
963 end
964 xmlFilename = NetworkUtil.convertFromNetworkFilename(xmlFilename)
965
966 if self:load(xmlFilename, x,y,z, xRot, yRot, zRot, false, false) then
967 self.age = Utils.getNoNil(getXMLFloat(xmlFile, key.."#age"), 0)
968 self.price = Utils.getNoNil(getXMLInt(xmlFile, key.."#price"), self.price)
969
970 -- Use a call so any sub-objects of the placeable can be updated
971 self:setOwnerFarmId(Utils.getNoNil(getXMLInt(xmlFile, key .. "#farmId"), AccessHandler.EVERYONE), true)
972
973 self.mapBoundId = Utils.getNoNil(getXMLString(xmlFile, key .. "#mapBoundId"), self.mapBoundId)
974 self.isLoadedFromSavegame = true
975 self:finalizePlacement()
976
977 for i, animatedObject in ipairs(self.animatedObjects) do
978 animatedObject:loadFromXMLFile(xmlFile, string.format("%s.animatedObjects.animatedObject(%d)", key, i - 1))
979 end
980
981 return true
982 else
983 return false
984 end
985end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
992function Placeable:saveToXMLFile(xmlFile, key, usedModNames)
993 local x,y,z = getTranslation(self.nodeId)
994 local xRot,yRot,zRot = getRotation(self.nodeId)
995
996 setXMLString(xmlFile, key.."#filename", HTMLUtil.encodeToHTML(NetworkUtil.convertToNetworkFilename(self.configFileName)))
997 setXMLString(xmlFile, key.."#position", string.format("%.4f %.4f %.4f", x, y, z))
998 setXMLString(xmlFile, key.."#rotation", string.format("%.4f %.4f %.4f", math.deg(xRot), math.deg(yRot), math.deg(zRot)))
999 setXMLInt(xmlFile, key.."#age", self.age)
1000 setXMLFloat(xmlFile, key.."#price", self.price)
1001 setXMLInt(xmlFile, key.."#farmId", self:getOwnerFarmId())
1002
1003 if self.mapBoundId ~= nil then
1004 setXMLString(xmlFile, key.."#mapBoundId", self.mapBoundId)
1005 end
1006
1007 for i, animatedObject in ipairs(self.animatedObjects) do
1008 animatedObject:saveToXMLFile(xmlFile, string.format("%s.animatedObjects.animatedObject(%d)", key, i - 1), usedModNames)
1009 end
1010end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
1020function Placeable:update(dt)
1021end

getPrice

Description
Returns price
Definition
getPrice()
Return Values
integerpriceprice
Code
1029function Placeable:getPrice()
1030 return self.price
1031end

canBuy

Description
Returns true if we can place a building
checking item count
Definition
canBuy()
Return Values
Code
1037function Placeable:canBuy()
1038 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
1039 local enoughItems = storeItem.maxItemCount == nil or (storeItem.maxItemCount ~= nil and g_currentMission:getNumOfItems(storeItem, g_currentMission:getFarmId()) < storeItem.maxItemCount)
1040 return enoughItems
1041end

onBuy

Description
Called on buy
Definition
onBuy()
Code
1053function Placeable:onBuy()
1054end

onSell

Description
Called on sell
Definition
onSell()
Code
1058function Placeable:onSell()
1059 if self.isServer then
1060 self:setTipOcclusionAreaDirty()
1061 end
1062
1063 g_messageCenter:publish(MessageType.FARM_PROPERTY_CHANGED, {self:getOwnerFarmId()})
1064end

getDailyUpkeep

Description
Returns daily up keep
Definition
getDailyUpkeep()
Return Values
integerdailyUpkeepdaily up keep
Code
1069function Placeable:getDailyUpkeep()
1070 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
1071 local multiplier = 1
1072 if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then
1073 local ageMultiplier = math.min(self.age/storeItem.lifetime, 1)
1074 multiplier = 1 + EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * ageMultiplier
1075 end
1076 return StoreItemUtil.getDailyUpkeep(storeItem, nil) * multiplier
1077end

getSellPrice

Description
Returns sell price
Definition
getSellPrice()
Return Values
integersellPricesell price
Code
1082function Placeable:getSellPrice()
1083 local priceMultiplier = 0.5
1084 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
1085 local maxVehicleAge = storeItem.lifetime
1086
1087 if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then
1088 priceMultiplier = priceMultiplier * math.exp(-3.5 * math.min(self.age/maxVehicleAge, 1))
1089 end
1090
1091 return math.floor(self.price * math.max(priceMultiplier, 0.05))
1092end

isMapBound

Description
Get wether the placeable is bound to the map and should be matched with the original map definition.
Does not currently influence anything. Once it doe: the position and rotation of the placeable will be updated
By the map info. It will also be removed if it was from the map.
Definition
isMapBound()

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
1103function Placeable:hourChanged()
1104 if self.isServer then
1105 if self.incomePerHour ~= 0 then
1106 g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), "propertyIncome")
1107 g_currentMission:addMoneyChange(self.incomePerHour, self:getOwnerFarmId(), EconomyManager.MONEY_TYPE_PROPERTY_INCOME)
1108 end
1109 end
1110end

dayChanged

Description
Called if day changed
Definition
dayChanged()
Code
1114function Placeable:dayChanged()
1115 self.age = self.age + 1
1116end

weatherChanged

Description
Called if weather changed
Definition
weatherChanged()
Code
1120function Placeable:weatherChanged()
1121 if g_currentMission ~= nil and g_currentMission.environment ~= nil and self.dayNightObjects ~= nil then
1122 for _, dayNightObject in pairs(self.dayNightObjects) do
1123 if dayNightObject.visibleDay ~= nil and dayNightObject.visibleNight ~= nil then
1124 setVisibility(dayNightObject.node, (g_currentMission.environment.isSunOn and dayNightObject.visibleDay) or (dayNightObject.visibleNight and (not g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining())))
1125
1126 elseif dayNightObject.intensityDay ~= nil and dayNightObject.intensityNight ~= nil then
1127 local intensity = dayNightObject.intensityNight
1128 if g_currentMission.environment.isSunOn then
1129 intensity = dayNightObject.intensityDay
1130 end
1131
1132 local _,y,z,w = getShaderParameter(dayNightObject.node, "lightControl")
1133 setShaderParameter(dayNightObject.node, "lightControl", intensity, y, z, w, false)
1134 end
1135 end
1136 end
1137end

getTerrainModificationBlockingAreas

Description
Get an array of areas which this placeable is going to modify on placement.
These areas are used to modify the placement blocking bit vector map to avoid interfering with terrain modifications
of other placeables.
Definition
getTerrainModificationBlockingAreas()
Return Values
{i={x, y, z, side1x, side1y, side1z, side2x, side2y, side2z}}, all numbers in world space coordinates

loadSpecValueIncomePerHour

Description
Loads capacity spec value
Definition
loadSpecValueIncomePerHour(integer xmlFile, string customEnvironment)
Arguments
integerxmlFileid of xml object
stringcustomEnvironmentcustom environment
Return Values
tablecapacityAndUnitcapacity and unit
Code
1167function Placeable.loadSpecValueIncomePerHour(xmlFile, customEnvironment)
1168 if not hasXMLProperty(xmlFile, "placeable.incomePerHour1") then
1169 return nil
1170 end
1171
1172 local incomePerHour = {}
1173 incomePerHour[1] = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.incomePerHour1"), 0)
1174 incomePerHour[2] = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.incomePerHour2"), 0)
1175 incomePerHour[3] = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.incomePerHour3"), 0)
1176 return incomePerHour
1177end

getSpecValueIncomePerHour

Description
Returns value of income per hour
Definition
getSpecValueIncomePerHour(table storeItem, table realItem)
Arguments
tablestoreItemstore item
tablerealItemreal item
Return Values
integerincomePerHourincome per hour
Code
1184function Placeable.getSpecValueIncomePerHour(storeItem, realItem)
1185 if storeItem.specs.incomePerHour == nil then
1186 return nil
1187 end
1188 return string.format(g_i18n:getText("shop_incomeValue"), g_i18n:formatMoney(storeItem.specs.incomePerHour[g_currentMission.missionInfo.difficulty]))
1189end

PlacementScreen

Description
Object Placement HUD Screen.
-- Shown in-game when placing objects.
-- @field messageText Hint message display text

new

Description
Create a new PlacementScreen instance.
Definition
new(table target, table custom_mt, table messageCenter, table placementController)
Arguments
tabletargetScreenElement controller instance
tablecustom_mt[optional] Sub-class meta table for inheritance
tablemessageCenterMessageCenter reference for local network UI event handling
tableplacementControllerPlacementScreenController instance which handles placement logic
Return Values
tableinstanceinstance of object
tablePlacementScreeninstance

mouseEvent

Description
Handle mouse input event.
Custom logic for PC version mouse input.
Definition
mouseEvent()
Return Values
tableinstanceinstance of object

updateMessageText

Description
Update message text, if present.
Definition
updateMessageText()
Return Values
booleantrueif loading was successful else false

setPlacementItem

Description
Set a placeable object for placement or selling.
Definition
setPlacementItem(item Placement, isSellMode If, obj Sellable)
Arguments
itemPlacementitem from the store
isSellModeIftrue, we want to sell the given item
objSellableobject
Return Values
booleansuccesssuccess

onMouseModeChanged

Description
Called when the mouse input mode changes.
Definition
onMouseModeChanged()
Return Values
tableinstanceinstance of object

handleControllerMessage

Description
Handles messages dispatched to this view by the controller.
Definition
handleControllerMessage(messageId Message, text Message, callback [optional], callbackTarget [optional])
Arguments
messageIdMessageID as defined in PlacementScreenController.MESSAGE
textMessagetext to display
callback[optional]Callback for message dialog completion
callbackTarget[optional]Callback target which is given as the first argument to the callback if supplied
Return Values
booleantrueif loading was successful else false

PlacementScreenController

Description
Placeable placement controller.
-- Handles placement and selling logic for placeable objects in the PlacementScreen view.
--@category GUI

new

Description
Create a new PlacementScreenController instance.
Definition
new(table l10n, table inputManager, table placeableTypeManager)
Arguments
tablel10nI18N reference for string localization.
tableinputManagerInputBinding reference for input action registration
tableplaceableTypeManagerPlaceableTypeManager reference
Return Values
tablecategoriesa list of categories

setMouseModeChangeCallback

Description
Set the callback used to trigger a mouse mode change.
Definition
setMouseModeChangeCallback(function callback)
Arguments
functioncallbackMouse mode callback function, signature: function(isMouseMode)
Return Values
tablecategorythe corresponding category

setMessageDispatchCallback

Description
Set the callback used to dispatch UI messages.
Definition
setMessageDispatchCallback(function callback)
Arguments
functioncallbackMessage dispatch callback function, signature: function(messageId, text, callbackFunction, callbackTarget)
Return Values
tableinstanceinstance of object

setExitCallback

Description
Set the callback used to exit placement mode.
Definition
setExitCallback(function callback)
Arguments
functioncallbackExit callback, signature: function()
Return Values
tableinstanceinstance of object

setClient

Description
Set the reference to the network client.
Definition
setClient()
Return Values
tableinstanceinstance of object

setCurrentMission

Description
Set the reference to the current mission controller when starting a game.
Definition
setCurrentMission()
Return Values
tablemodthe mod object

setHUD

Description
Set the reference to the in-game HUD.
Definition
setHUD()
Return Values
booleansuccesstrue if mod was removed, else false

initialize

Description
Initialize the controller.
Definition
initialize()
Return Values
tablemodthe mod object

initializeCamera

Description
Set up the placement camera.
Definition
initializeCamera()
Return Values
tablemodthe mod object

reset

Description
Reset controller state, e.g. when leaving the controlled view.
Definition
reset()
Return Values
tablemodthe mod object

updateCameraMovement

Description
Update camera position and orientation based on player input.
Definition
updateCameraMovement(dt Delta, movementMultiplier Speed)
Arguments
dtDeltatime in milliseconds
movementMultiplierSpeedfactor for movement
Return Values
tablemodsa list of mods

getMouseEdgeScrollingMovement

Description
Get camera movement for mouse edge scrolling.
Definition
getMouseEdgeScrollingMovement()
Return Values
tablemodsa list of multiplayer mods
xdirectionmovement [-1, 1]
Zdirectionmovement [-1, 1]

applyCameraMovement

Description
Apply a movement to the camera (and view).
Definition
applyCameraMovement(moveX X, moveZ Z, movementMultiplier Movement)
Arguments
moveXXdirection movement [-1, 1]
moveZZdirection movement [-1, 1]
movementMultiplierMovementspeed factor
Return Values
tablemodsa list of active mods

updateCameraPosition

Description
Update the camera position and orientation based on terrain and zoom state.
Definition
updateCameraPosition()
Return Values
integernumModsnumber of mods

updatePlaceablePreview

Description
Update the placeable preview.
Definition
updatePlaceablePreview()
Return Values
integernumModsnumber of valid mods

acceptSelection

Description
Accept the current selection (selling or placing object).
Definition
acceptSelection()
Return Values
booleanareAvailabletrue if all hashes are available else false

sellWarningInfoOk

Description
Called when the player acknowledges the sell warning.
Definition
sellWarningInfoOk()
Return Values
booleanisAvailabletrue if hash is available else false

onSellCallback

Description
Called when the player confirms selling a placeable.
Definition
onSellCallback()
Return Values
tableinstanceinstance of object

updateSlots

Description
Update placeable object slots usage.
Definition
updateSlots()
Return Values
booleantrueif loading was successful else false

onPlaceableBought

Description
Called on BuyPlaceableEvent success.
Definition
onPlaceableBought()
Return Values
booleansuccesstrue if added else false

onPlaceableBuyFailed

Description
Called on BuyPlaceableEvent failure.
Definition
onPlaceableBuyFailed()
Return Values
tableinstanceinstance of object

onPlaceableSold

Description
Called on SellPlaceableEvent success.
Definition
onPlaceableSold()
Return Values
tableinstanceinstance of object

onPlaceableSellFailed

Description
Called on SellPlaceableEvent failure.
Definition
onPlaceableSellFailed()
Return Values
tableinstanceinstance of object

buyPlaceable

Description
Buy a currently previewed placeable.
This operation also makes some final checks and dispatches information dialogs if anything goes wrong.
Definition
buyPlaceable()
Return Values
booleantrueif loading was successful else false

findSellObjectAt

Description
Find a sellable object under a cursor position.
The results of the search are processed in PlacementScreenController.onSellObjectRaycast().
Definition
findSellObjectAt(posX Cursor, posY Cursor)
Arguments
posXCursorX position in screen space
posYCursorY position in screen space
Return Values
tablebaleTypebaleType object

sellPlaceable

Description
Sell a given placeable object.
Definition
sellPlaceable()
Return Values
integertoolTypeIndextool type index

setPlacementItem

Description
Set a placeable object for placement or selling.
Definition
setPlacementItem(item Placement, isSellMode If, obj Sellable)
Arguments
itemPlacementitem from the store
isSellModeIftrue, we want to sell the given item
objSellableobject
Return Values
tableinstanceinstance of object

calculatePlacementHeight

Description
Calculate the placement height for a given world position based on the current player input height factor.
Definition
calculatePlacementHeight()
Return Values
booleantrueif loading was successful else false

isPlacementValid

Description
Check if a preview placement is valid (without terrain modification).
Definition
isPlacementValid(Placeable Placeable, x Preview, y Preview, Z Preview, yRot Placeable, distance Distance)
Arguments
PlaceablePlaceableinstance
xPreviewX position in world space
yPreviewY position in world space
ZPreviewZ position in world space
yRotPlaceableY rotation in radians
distanceDistancefrom checking ray origin to ground
Return Values
booleantrueif loading was successful else false
Trueifthe placement is valid, false otherwise
stringReasonof being invalid

onPlacementRaycast

Description
Called when the placement raycast finishes.
Definition
onPlacementRaycast(hitObjectId ID, x Raycast, y Raycast, Z Raycast, distance Distance)
Arguments
hitObjectIdIDof the first hit object
xRaycasthit X position in world space
yRaycasthit Y position in world space
ZRaycasthit Z position in world space
distanceDistancefrom ray origin to hit position
Return Values
tablesprayTypesprayType object

startPlacementTerrainValidation

Description
Start validation of a required terrain deformation for the current placement preview.
Definition
startPlacementTerrainValidation()
Return Values
tablesprayTypethe sprayType object

addPlaceableLevelingArea

Description
Add a leveling area of a placeable to a terrain deformation object.
Definition
addPlaceableLevelingArea(terrainDeform TerrainDeformation, levelArea Table, terrainBrushId Terrain)
Arguments
terrainDeformTerrainDeformationinstance
levelAreaTablewhich holds area nodes, {start=origin node, width=first side area delimiter node, height=second side area delimiter node}
terrainBrushIdTerrainbrush ID, currently this is a map layer index (zero-based)
Return Values
tablesprayTypethe sprayType object

addPlaceableRampArea

Description
Add a leveling area for a ramp of a placeable to a terrain deformation object.
Definition
addPlaceableRampArea(terrainDeform TerrainDeformation, rampArea Table, terrainBrushId Terrain, maxRampSlope Maximum, terrainRootNode Root)
Arguments
terrainDeformTerrainDeformationinstance
rampAreaTablewhich holds area nodes, {start=origin node, width=first side area delimiter node, height=second side area delimiter node, baseRotation={rx, ry, rz}, previewShape=nodeId}
terrainBrushIdTerrainbrush ID, currently this is a map layer index (zero-based)
maxRampSlopeMaximumramp slope as an angle in radians
terrainRootNodeRootnode of the terrain for height map check
Return Values
stringfillTypeNamethe sprayType name

onTerrainValidationFinished

Description
Called when a terrain deformation validation has finished.
Definition
onTerrainValidationFinished(canDeform If, displacedVolume Volume, overlapsBlockedArea If)
Arguments
canDeformIftrue, the terrain deformation could be performed
displacedVolumeVolumedisplaced by the terrain deformation operation in cubic meters (m3)
overlapsBlockedAreaIftrue, the terrain modification overlaps a blocked area.
Return Values
integerfillTypeIndexthe sprayType index

onTerrainDeformationFinished

Description
Called when an actual (not just preview) terrain deformation operation has finished.
Definition
onTerrainDeformationFinished(canDeform If, displacedVolume Volume)
Arguments
canDeformIftrue, the terrain deformation was performed
displacedVolumeVolumedisplaced by the terrain deformation operation in cubic meters (m3)
Return Values
tablesprayTypethe sprayType object

cancelTerrainDeformation

Description
Cancel a currently active terrain deformation process, if necessary.
This will cancel any ongoing deformation checks and operations and release all relevant blocking flags.
Definition
cancelTerrainDeformation()
Return Values
integersprayTypeIndexthe sprayType index

onSellObjectRaycast

Description
Called when the sell object raycast finishes.
Definition
onSellObjectRaycast(hitObjectId ID, x Raycast, y Raycast, Z Raycast, distance Distance)
Arguments
hitObjectIdIDof the first hit object
xRaycasthit X position in world space
yRaycasthit Y position in world space
ZRaycasthit Z position in world space
distanceDistancefrom ray origin to hit position
Return Values
tablesprayTypeslist of sprayTypes

determineCameraPosition

Description
Determine the current camera position and orientation.
Definition
determineCameraPosition()
Return Values
tableinstanceinstance of object
CameraXworld space position
CameraZworld space position
CameraYrotation in radians

canBuy

Description
Determine if there is enough storage room to buy a currently previewed placeable object.
Definition
canBuy()
Return Values
tableinstanceinstance of object

canPlace

Description
Determine if a previewed placeable object can be placed at its current position.
Definition
canPlace()
Return Values
booleantrueif loading was successful else false

resetInputState

Description
Reset event input state.
Definition
resetInputState()
Return Values
tablebaleTypebaleType object

registerActionEvents

Description
Register required action events.
Definition
registerActionEvents()
Return Values
stringtoolTypeNametool type name

removeActionEvents

Description
Remove action events registered on this screen.
Definition
removeActionEvents()
Return Values
integertoolTypeIndextool type index

updateActionEvents

Description
Update action event activity states.
Definition
updateActionEvents()
Return Values
integernumToolTypesnumber of tool types

PlayerSetFarmAnswerEvent

Description
Player farm setting answer event.
-- Triggered in response to PlayerSetFarmEvent.

emptyNew

Description
Create an empty instance
Definition
emptyNew()
Return Values
tableinstanceInstance of object
Code
27function PlayerSetFarmAnswerEvent:emptyNew()
28 local self = Event:new(PlayerSetFarmAnswerEvent_mt)
29 return self
30end

new

Description
Create an instance of PlayerSetFarmAnswerEvent.
Definition
new(int answerState, int farmId, string password)
Arguments
intanswerState
intfarmIdFarm ID
stringpasswordPassword used for PlayerSetFarmEvent
Return Values
tableinstanceInstance of PlayerSetFarmAnswerEvent
Code
38function PlayerSetFarmAnswerEvent:new(answerState, farmId, password)
39 local self = PlayerSetFarmAnswerEvent:emptyNew()
40
41 self.answerState = answerState
42 self.farmId = farmId
43 self.password = password
44
45 return self
46end

writeStream

Description
Writes network stream
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
Code
52function PlayerSetFarmAnswerEvent:writeStream(streamId, connection)
53 streamWriteUIntN(streamId, self.answerState, PlayerSetFarmAnswerEvent.SEND_NUM_BITS)
54 streamWriteUIntN(streamId, self.farmId, FarmManager.FARM_ID_SEND_NUM_BITS)
55
56 local passwordCorrect = self.answerState == PlayerSetFarmAnswerEvent.STATE.OK
57 local passwordSet = self.password ~= nil
58 if streamWriteBool(streamId, passwordCorrect and passwordSet) then
59 streamWriteString(streamId, self.password)
60 end
61end

readStream

Description
Reads network stream
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
Code
67function PlayerSetFarmAnswerEvent:readStream(streamId, connection)
68 self.answerState = streamReadUIntN(streamId, PlayerSetFarmAnswerEvent.SEND_NUM_BITS)
69 self.farmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
70
71 if streamReadBool(streamId) then
72 self.password = streamReadString(streamId)
73 end
74
75 self:run(connection)
76end

run

Description
Run event
Definition
run(table connection)
Arguments
tableconnectionconnection information
Code
81function PlayerSetFarmAnswerEvent:run(connection)
82 if not connection:getIsServer() then -- server side, should not happen
83 g_logManager:devWarning("PlayerSetFarmAnswerEvent is a server to client only event")
84 else -- client side
85 if self.answerState == PlayerSetFarmAnswerEvent.STATE.OK then
86 g_messageCenter:publish(PlayerSetFarmAnswerEvent, {self.answerState, self.farmId, self.password})
87 elseif self.answerState == PlayerSetFarmAnswerEvent.STATE.PASSWORD_REQUIRED then
88 g_messageCenter:publish(PlayerSetFarmAnswerEvent, {self.answerState, self.farmId})
89 end
90 end
91end

PlaySampleMixin

Description
Play UI sound sample mixin.
-- Add this mixin to a GuiElement to enable it to play UI sounds.
-- Added methods:
GuiElement:setPlaySampleCallback(callback): Set a callback for playing UI sound samples, signature: function(sampleName).
GuiElement:playSample(index, count): Called by the decorated GuiElement to play a sound sample using a name from GuiSoundPlayer.SOUND_SAMPLES.
GuiElement:disablePlaySample(): Permanently disables playing samples for special cases (i.e. separate sound logic)
--@category GUI

addTo

Description
See GuiMixin:addTo().
Definition
addTo()

setPlaySampleCallback

Description
Set a callback to play a UI sound sample.
Definition
setPlaySampleCallback(table guiElement, function callback)
Arguments
tableguiElementGuiElement instance
functioncallbackPlay sample callback, signature: function(sampleName)

playSample

Description
Request playing a UI sound sample identified by name.
Definition
playSample(table guiElement, string sampleName)
Arguments
tableguiElementGuiElement instance
stringsampleNameSample name, use one of GuiSoundPlayer.SOUND_SAMPLES.

disablePlaySample

Description
Permanently disable playing samples on the decorated GuiElement for special cases.
Definition
disablePlaySample()

clone

Description
Clone this mixin's state from a source to a destination GuiElement instance.
Definition
clone()

PolygonChain

Description
Creating data grid

new

Description
@param table customMt custom metatable
Definition
new()
Return Values
tableinstanceinstance of object
Code
19function PolygonChain:new(customMt)
20 local self = {}
21 setmetatable(self, customMt or PolygonChain_mt)
22
23 self.controlNodes = {}
24
25 return self
26end

delete

Description
Deletes data grid
Definition
delete()
Code
30function PolygonChain:delete()
31 self.controlNodes = nil
32end

RenderElement

Description
Render display as an overlay
--@category GUI
--@xmlConfig RenderElement#filename string Path to the i3d to be rendered in the overlay

createScene

Description
Create the scene and the overlay. Call destroyScene to clean up resources.
Definition
createScene()

destroyScene

Description
Destroy the scene and the overlay, cleaning up resources.
Definition
destroyScene()

SavegameController

Description
Savegame persistence controller.
-- Handles loading and saving of mission game states.

new

Description
Create a new instance of SavegameController.
Definition
new()
Return Values
floatmaxPtoRpmmax pto rpm

loadSavegames

Description
Load the savegame meta data list.
Definition
loadSavegames()
Return Values
floatneededPowerneeded power

resetStorageDeviceSelection

Description
Reset the storage device selection for saving.
Definition
resetStorageDeviceSelection()
Return Values
stringl10nl10n text
floatneededPowerneeded power in kw
floatneededPowerneeded power in hp

updateSavegames

Description
Start updating the savegame list in the engine.
Definition
updateSavegames()

onSaveGameUpdateComplete

Description
Called when updating the save game list in the engine has finished.
Definition
onSaveGameUpdateComplete()

locateBackups

Description
Locate backups for a savegame instance in its backup path.
Definition
locateBackups(string backupBasePath, string backupDirBase)
Arguments
stringbackupBasePathBackup base path
stringbackupDirBaseSavegame-specific backup base directory
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

assignBackupDeleteFlags

Description
Check and mark backups for deletion, based on creation time.
Definition
assignBackupDeleteFlags()
Return Values
boolean

createBackup

Description
Create an actual savegame backup.
Definition
createBackup(table savegame, string backupBasePath, string backupDirFull, string backupDirBase)
Arguments
tablesavegameSavegame to back up
stringbackupBasePathBackup base path
stringbackupDirFullFull savegame-specific backup directory
stringbackupDirBaseSavegame-specific backup base directory
Return Values
booleanupdatedpart was updated

backupSavegame

Description
Create a backup of the given savegame.
Definition
backupSavegame()
Return Values
booleanisActiveis active

onSaveStartComplete

Description
Called when saving can begin or there is an IO problem with the target path.
Definition
onSaveStartComplete()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

onSaveComplete

Description
Called when the saving game process has finished.
Definition
onSaveComplete()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

onSavegameDeleted

Description
Called when a savegame has been deleted by the engine or an error occurred.
Definition
onSavegameDeleted()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

getCanStartGame

Description
Check if a savegame can be started.
Definition
getCanStartGame()
Return Values
booleancanFoldridge markers can be folden

getCanDeleteGame

Description
Check if a savegame can be deleted.
Definition
getCanDeleteGame()
Return Values
booleansuccesssuccess

getSavegame

Description
Get a savegame by index.
Definition
getSavegame()
Return Values
booleansuccesssuccess

getIsSaving

Description
Check if a game is being saved.
Definition
getIsSaving()
Return Values
booleanisActivespeed rotating part is active

getSavingErrorCode

Description
Get the current saving error code.
Definition
getSavingErrorCode()
Return Values
booleanisActivework area is active

getIsWaitingForSavegameInfo

Description
Check if the save game info is currently being updated.
Definition
getIsWaitingForSavegameInfo()
Return Values
floatdirtMultipliercurrent wear multiplier

getNumberOfSavegames

Description
Get the number of known savegames from the engine.
Definition
getNumberOfSavegames()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

isStorageDeviceUnavailable

Description
Check if the storage device is unavailable
Definition
isStorageDeviceUnavailable()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

ScreenElement

Description
Base screen element. All full-screen GUI views inherit from this.
-- ScreenElement inherits from FrameElement and has no additional configuration, but contains UI logic shared across all
full screen views.
--@category GUI
-- @field pageSelector Paging navigation controls container, only defined if the view supports paging by configuration

onClickOk

Description
Handle OK click event.
Definition
onClickOk()
Return Values
boolTrueif the event was not used, false if it was used.

onClickActivate

Description
Handle activate click event.
Definition
onClickActivate()
Return Values
boolTrueif the event was not used, false if it was used.

onClickCancel

Description
Handle cancel click event.
Definition
onClickCancel()
Return Values
boolTrueif the event was not used, false if it was used.

onPagePrevious

Description
Handle previous page event.
Definition
onPagePrevious()

onPageNext

Description
Handle next page event.
Definition
onPageNext()

onClickBack

Description
Handle back click event.
Definition
onClickBack(bool forceBack, bool usedMenuButton)
Arguments
boolforceBackIf true, the screen must allow going back
boolusedMenuButtonIf true, the menu action key/button was used to trigger this event
Return Values
boolTrueif the event was not used, false if it was used.

setReturnScreenClass

Description
Set the class of the return screen which should be opened when the "back" action is triggered on this screen.
Definition
setReturnScreenClass()

setNextScreenClickSoundMuted

Description
Mute the next click sound. Used to override click sounds for the activate/cancel actions
Definition
setNextScreenClickSoundMuted()

SettingsAdvancedFrame

Description
Advanced graphic settings frame.
--@category GUI
SettingsAdvancedFrame = {}
Parent
InGameMenuFrameElement

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
booleantrueif loading was successful else false

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableselfnew instance of object

SettingsConsoleFrame

Description
Console settings frame.
--@category GUI
SettingsConsoleFrame = {}
Parent
InGameMenuFrameElement

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
booleansuccesssuccess

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableselfnew instance of object

SettingsControlsFrame

Description
Controls binding settings frame.
-- This is only supposed to be active in the PC version of the game.
--@category GUI

new

Description
Create a new SettingsControlsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
booleansuccesssuccess

initialize

Description
Late initialization.
Definition
initialize(table controlsController)
Arguments
tablecontrolsControllerNew controls controller instance which provides input capture logic for control
bindings. This controller must not be shared between components.
Return Values
floatxx translation
floatyy translation
floatzz translation
floatrxx rotation
floatryy rotation
floatrzz rotation
floatsxx scale
floatsyy scale
floatszz scale
integervisibilityvisibility

requestClose

Description
Request to close this frame.
If there are pending changes, a saving prompt will be shown and direct closing denied.
Definition
requestClose()

onYesNoSaveControls

Description
Handle saving confirmation on leaving the frame.
Definition
onYesNoSaveControls()

revertChanges

Description
Revert any binding changes since the last save.
Definition
revertChanges()

saveChanges

Description
Save binding changes.
Definition
saveChanges()

updateMenuButtons

Description
Update menu button information.
Definition
updateMenuButtons()

updateHeader

Description
Update header elements' state.
Definition
updateHeader()

setDevicePage

Description
Set the device page.
Definition
setDevicePage(bool toKeyboard)
Arguments
booltoKeyboardIf true, set the page to keyboard, otherwise set it to gamepad

switchDevice

Description
Switch the current binding device (kb / mouse or gamepads).
Switches between tables if possible.
Definition
switchDevice()

setupControlsView

Description
Set up the controls view with input binding tables.
Definition
setupControlsView()

assignDeviceTableData

Description
Assigns table data to all device input binding table elements.
If called after initialization, this will completely rebuild the data. This may be desired or required when new
devices are detected.
Definition
assignDeviceTableData()
Return Values
booleansuccesssuccess

setRequestButtonUpdateCallback

Description
Set a callback for requesting a button display update (e.g. when switching device pages).
Definition
setRequestButtonUpdateCallback()
Return Values
tableinstanceInstance of object

setControlsMessage

Description
Set the controls notification message.
Definition
setControlsMessage(messageId ID, additionalText [optional], addLine [optional])
Arguments
messageIdIDof message as defined as a constant in ControlsController.
additionalText[optional]More text to add to the message. Must always be a list, since it can be used to hold formatting arguments.
addLine[optional]If true, will add the message to the previous text instead of overwriting it.
Return Values
booleansuccesssuccess

notifyInputGatheringFinished

Description
Notify the screen that input gathering has finished.
Unlocks navigation and closes any open dialogs.
Definition
notifyInputGatheringFinished(madeChange True)
Arguments
madeChangeTrueif any action has been assigned a key/button
Return Values
integerfillTypecurrent fill type id

showInputPrompt

Description
Show an input prompt dialog.
Definition
showInputPrompt()
Return Values
integerfillLevelcurrent fill level

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
booleancanBeSoldbale can be sold

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
tableinstanceInstance of object

bindControls

Description
Store data bindings for a device category.
The data bindings have an abstract field name (e.g. "action") as key and a table column name as value. The column
name must correspond to the name of a table row template element's name, which is also configured as a column name
in the table configuration.
Definition
bindControls(table bindings, int deviceCategory)
Arguments
tablebindingsData binding table {name: column}
intdeviceCategoryDevice category for which these bindings are stored
Return Values
tableinstanceInstance of object

getActionDataFromClickedTableButton

Description
Get the action data associated with a clicked action input button.
Definition
getActionDataFromClickedTableButton(tableButton Clicked, isKeyboard If)
Arguments
tableButtonClickedaction input button element
isKeyboardIftrue, the input action device is keyboard and mouse, otherwise it's a gamepad/controller
Return Values
booleansuccesssuccess

updateDisplay

Description
Update the controls display data.
Definition
updateDisplay()
Return Values
booleansuccesssuccess

onInputClicked

Description
Handle clicks on input action buttons.
Definition
onInputClicked(int deviceCategory, int bindingId, table actionData)
Arguments
intdeviceCategoryInput action device category
intbindingIdBinding ID as defined in ControlsController (primary, secondary, tertiary)
tableactionDataInput action data
Return Values
tableinstanceInstance of object

onClickDefaults

Description
Handle "reset to defaults" button activation.
Definition
onClickDefaults()
Return Values
booleansuccesssuccess

onClickKeyboardHeader

Description
Handle clicking the keyboard controls header.
Definition
onClickKeyboardHeader()
Return Values
booleansuccesssuccess

onClickGamepadHeader

Description
Handle clicking the gamepad controls header.
Definition
onClickGamepadHeader()
Return Values
floatoffsetoffset

SettingsDeviceFrame

Description
Console settings frame.
--@category GUI
SettingsDeviceFrame = {}
Parent
InGameMenuFrameElement

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
booleanisCloserToFrontis closer to front

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
booleancanInteractcan interact

update

Description
Get the frame's main content element's screen position.
Definition
update()
Return Values
booleancanClosecan close silo

updateController

Description
Update controller and mouse sensitivity and deadzone settings values.
Definition
updateController()
Return Values
booleancanOpencan open silo

SettingsGeneralFrame

Description
General game settings frame.
--@category GUI
-- @field inputHelpMode In-game input display help mode option (auto, keyboard, gamepad)

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
floatxx world position
floatyy world position
floatzz world position

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()

SettingsModel

Description
Settings menu model.
-- Provides an interface model between game settings and the UI for re-use between several components. The model keeps
a common, transient state until saved. When saving, the settings are applied to the global game settings and written
to the player's configuration file.
--@category GUI

new

Description
Create a new instance.
Definition
new(table gameSettings, int settingsFileHandle, table l10n, table soundMixer)
Arguments
tablegameSettingsGameSettings object which holds the currently active and applied game settings
intsettingsFileHandleEngine file handle of the player's settings file
tablel10nI18N reference for localized display string resolution
tablesoundMixerSoundMixer reference for direct application of volume settings
Return Values
tableSettingsModelinstance

initialize

Description
Initialize model.
Read current configuration settings and populate valid display and configuration option values.
Definition
initialize()

addManagedSettings

Description
Add managed valid settings which receive their initial value from the loaded game settings or the engine.
Definition
addManagedSettings()

addSetting

Description
Add a setting to the model.
Reader and writer functions need to be provided which transform display values (usually indices) to actual setting
values and interact with the current game setting or engine states. Writer function can have side-effects, such as
directly applying values to the engine state or modifying dependent sub-settings.
Definition
addSetting(string gameSettingsKey, function readerFunction, function writerFunction, boolean noRestartRequired)
Arguments
stringgameSettingsKeyKey of the setting in GameSettings
functionreaderFunctionFunction which reads and processes the setting value identified by the key, signature: function(settingsKey)
functionwriterFunctionFunction which processes and writes the setting value identified by the key, signature: function(value, settingsKey)
booleannoRestartRequiredtrue if no restart is required to apply the setting

setValue

Description
Set a settings value.
Definition
setValue(string settingKey, table value)
Arguments
stringsettingKeySetting key, use one of the values in SettingsModel.SETTING.
tablevalueNew setting value

getValue

Description
Get a settings value.
Definition
getValue(string settingKey)
Arguments
stringsettingKeySetting key, use one of the values in SettingsModel.SETTING.
Return Values
tableCurrentlyactive (changed) settings value

setSettingsFileHandle

Description
Set the settings file handle when it changes (e.g. possible in the gamepad sign-in process).
Definition
setSettingsFileHandle()

refresh

Description
Refresh settings values from their reader functions.
Use this when other components might have changed the settings state and the model needs to reflect those changes
now.
Definition
refresh()

refreshChangedValue

Description
Refresh settings values from their reader functions.
Use this when other components might have changed the settings state and the model needs to reflect those changes
now.
Definition
refreshChangedValue()

hasChanges

Description
Check if any setting has been changed in the model.
Definition
hasChanges()
Return Values
boolTrueif any setting has been changed, false otherwise

needsRestartToApplyChanges

Description
Check if any setting has been changed in the model.
Definition
needsRestartToApplyChanges()
Return Values
boolTrueif any setting has been changed, false otherwise

applyChanges

Description
Apply the currently held, transient settings to the game settings.
Definition
applyChanges(bool doSave)
Arguments
booldoSaveIf true, the changes will also be persisted to storage.

saveChanges

Description
Save the game settings which may have been modified by this model.
This will not apply transient changes but only persist the currently applied game settings.
Definition
saveChanges()

createControlDisplayValues

Description
Populate value and string lists for control elements display.
Definition
createControlDisplayValues()

getBrightnessTexts

Description
Get valid brightness option texts.
Definition
getBrightnessTexts()

getFovYTexts

Description
Get valid FOV Y option texts.
Definition
getFovYTexts()

getUiScaleTexts

Description
Get valid UI scale texts.
Definition
getUiScaleTexts()

getAudioVolumeTexts

Description
Get valid audio volume texts.
Definition
getAudioVolumeTexts()

getCameraSensitivityTexts

Description
Get valid camera sensitivity texts.
Definition
getCameraSensitivityTexts()

getVehicleArmSensitivityTexts

Description
Get valid camera sensitivity texts.
Definition
getVehicleArmSensitivityTexts()

getSteeringBackSpeedTexts

Description
Get valid camera sensitivity texts.
Definition
getSteeringBackSpeedTexts()

getMoneyUnitTexts

Description
Get valid money unit (=currency) texts.
Definition
getMoneyUnitTexts()

getDistanceUnitTexts

Description
Get valid distance unit texts.
Definition
getDistanceUnitTexts()

getTemperatureUnitTexts

Description
Get valid temperature unit texts.
Definition
getTemperatureUnitTexts()

getAreaUnitTexts

Description
Get valid area unit texts.
Definition
getAreaUnitTexts()

getRadioModeTexts

Description
Get valid radio mode texts.
Definition
getRadioModeTexts()

makeDefaultReaderFunction

Description
Build the default reader function.
Reads a value directly from the game settings.
Definition
makeDefaultReaderFunction()

makeDefaultWriterFunction

Description
Build the default writer function.
Writes a value directly to the game settings.
Definition
makeDefaultWriterFunction()

addDirectSetting

Description
Add a setting which can be directly read and written from and to the game settings.
Definition
addDirectSetting()

addPerformanceClassSetting

Description
Add the performance class setting.
Definition
addPerformanceClassSetting()

addWindowModeSetting

Description
Add the window mode setting.
Definition
addWindowModeSetting()

addLanguageSetting

Description
Add the language setting.
Definition
addLanguageSetting()

addMPLanguageSetting

Description
Add the language setting.
Definition
addMPLanguageSetting()

addBrightnessSetting

Description
Add the brightness setting.
Definition
addBrightnessSetting()

addVSyncSetting

Description
Add the vertical synchronization setting.
Definition
addVSyncSetting()

addFovYSetting

Description
Add the vertical field of view setting.
Definition
addFovYSetting()

addUIScaleSetting

Description
Add the UI scale setting.
Definition
addUIScaleSetting()

addCameraSensitivitySetting

Description
Add the camera sensitivity setting.
Definition
addCameraSensitivitySetting()

addVehicleArmSensitivitySetting

Description
Add the vehicleArm sensitivity setting.
Definition
addVehicleArmSensitivitySetting()

addMasterVolumeSetting

Description
Add the master volume setting.
Definition
addMasterVolumeSetting()

addMusicVolumeSetting

Description
Add the music volume setting.
Definition
addMusicVolumeSetting()

addEnvironmentVolumeSetting

Description
Add the environment volume setting.
Definition
addEnvironmentVolumeSetting()

addVehicleVolumeSetting

Description
Add the vehicle volume setting.
Definition
addVehicleVolumeSetting()

addRadioVolumeSetting

Description
Add the radio volume setting.
Definition
addRadioVolumeSetting()

addVolumeGUISetting

Description
Add the gui volume setting.
Definition
addVolumeGUISetting()

addSteeringBackSpeedSetting

Description
Add the steering back speed setting.
Definition
addSteeringBackSpeedSetting()

convertBrightnessToGamma

Description
Convert a settings brightness value to a game gamma value.
Definition
convertBrightnessToGamma()

convertGammaToBrightness

Description
Convert a game gamma value to a settings brightness value.
Definition
convertGammaToBrightness()

getVSyncByIndex

Description
Convert a v-sync option value to boolean.
Definition
getVSyncByIndex()

getVSyncIndex

Description
Convert a v-sync boolean value to an index value.
Definition
getVSyncIndex()

SettingsScreen

Description
Main Menu Settings Screen.
--@category GUI
-- @field pagingElement Paging controller element

updatePages

Description
Update page enabled states.
Definition
updatePages()

registerPage

Description
Register a page frame element in the menu.
This does not add the page to the paging component of the menu.
Definition
registerPage(table pageFrameElement, int position, function enablingPredicateFunction)
Arguments
tablepageFrameElementPage FrameElement instance
intposition[optional] Page position index in menu
functionenablingPredicateFunction[optional] A function which returns the current enabling state of the page
at any time. If the function returns true, the page should be enabled. If no argument is given, the page is
always enabled.
Return Values
tableselfinstance of class event

unregisterPage

Description
Unregister a page frame element identified by class from the menu.
This does not remove the page from the paging component of the menu or the corresponding page tab from the header.
Definition
unregisterPage(table pageFrameClass)
Arguments
tablepageFrameClassFrameElement descendant class of a page which was previously registered
Return Values
tableinstanceinstance of event
boolTrueif there was a page of the given class and it was unregistered
tableUnregisteredpage controller instance or nil
tableUnregisteredpage root GuiElement instance or nil
tableUnregisteredpage tab ListElement instance of nil

addPageTab

Description
Add a page tab in the menu header.
Call this synchronously with SettingsScreen:registerPage() to ensure a correct order of pages and tabs.
Definition
addPageTab()
Return Values
tableselfinstance of class event

updatePageTabDisplay

Description
Update page tabs display after any page changes.
Definition
updatePageTabDisplay()
Return Values
tableinstanceinstance of event

setPageTabEnabled

Description
Set enabled state of a page tab in the header.
Definition
setPageTabEnabled()
Return Values
tableinstanceInstance of object

rebuildTabList

Description
Rebuild page tab list in order.
Definition
rebuildTabList()
Return Values
tableinstanceInstance of object

setupMenuButtonInfo

Description
Define default properties and retrieval collections for menu buttons.
Definition
setupMenuButtonInfo()
Return Values
tableinstanceInstance of object

onClickPageSelection

Description
Handle activation of page selection.
Definition
onClickPageSelection()
Return Values
tableinstanceInstance of object

onPagePrevious

Description
Handle previous page event.
Definition
onPagePrevious()
Return Values
tableinstanceInstance of object

onPageNext

Description
Handle next page event.
Definition
onPageNext()
Return Values
tableinstanceInstance of object

onPageChange

Description
Handle changing to another menu page.
Definition
onPageChange()
Return Values
booleanallowsAutoDeleteallows auto delete

updateButtonsPanel

Description
Update the buttons panel when a given page is visible.
Definition
updateButtonsPanel()
Return Values
booleanhasMovedhas moved

clearMenuButtonActions

Description
Clear menu button actions, events and callbacks.
Definition
clearMenuButtonActions()
Return Values
booleaninScopein scope

assignMenuButtonInfo

Description
Assign menu button information to the in-game menu buttons.
Definition
assignMenuButtonInfo()
Return Values
floatprioritypriority

initializePageDisplay

Description
Initialize page display labels from page titles.
Definition
initializePageDisplay()
Return Values
stringrigidBodyTyperigid body type

onClickOk

Description
Handle menu confirmation input event.
Definition
onClickOk()
Return Values
tableinstanceInstance of object

ShopCategoriesFrame

Description
Shop categories frame for the in-game menu shop.
-- Displays categories/brands or purchasable items in a tile-layout.
--@category GUI

new

Description
Create a new ShopCategoriesFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
booleansuccesssuccess

initialize

Description
Initialize with categories to be displayed.
Categories must be provided as an array of tables like {id=<id>, iconFilename=<path>, label=<text>}. This will add
a category element per entry to the display list.
Definition
initialize(table categories, function categoryClickedCallback, table headerIconUVs, string headerText)
Arguments
tablecategoriesCategory definitions array
functioncategoryClickedCallbackNotification callback for category activation(click/enter), signature: function(selectedId, baseCategoryIconUVs, baseCategoryLabel, clickedCategoryLabel)
tableheaderIconUVsUV coordinates of the header icon to display
stringheaderTextHeader text to display
Return Values
tableinstanceInstance of object

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tableselfnew instance of object

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
booleansuccesssuccess

updateScrollButtons

Description
Update scroll button visibility based on the currently visible list items.
Definition
updateScrollButtons()
Return Values
booleansuccesssuccess

onClickCategory

Description
Handle a click / button activation on a category.
Definition
onClickCategory()
Return Values
booleanallowallow fill type

onDoubleClickCategory

Description
Handle a double click on a category.
Definition
onDoubleClickCategory()
Return Values
floatfillLevelfill level

onCategorySelected

Description
Handle navigation selection of a category element.
Definition
onCategorySelected()
Return Values
floatfreeCapacityfree capacity

onClickLeft

Description
Handle click on left navigation button.
Definition
onClickLeft()
Return Values
tableinstanceInstance of object

onClickRight

Description
Handle click on right navigation button.
Definition
onClickRight()
Return Values
tableinstanceInstance of object

onScroll

Description
Handle a list scrolling event.
Definition
onScroll()
Return Values
tableinstanceInstance of object

ShopConfigScreen

Description
Vehicle Shop and Configuration Screen.
--@category GUI
-- @field shopMoneyBox Layout box for player money information

new

Description
Create the shop configuration screen.
Definition
new(table shopController, table messageCenter, table l10n, table i3dManager, table brandManager, table configurationManager, table vehicleTypeManager, table inputManager, table inputDisplayManager)
Arguments
tableshopControllerShopController instance, shared across all shop screens.
tablemessageCenterMessageCenter reference for local network UI event handling
tablel10nI18N localization manager reference
tablei3dManagerI3DManager reference for asset loading
tablebrandManagerBrandManager reference
tableconfigurationManagerConfigurationManager reference
tablevehicleTypeManagerVehicleTypeManager reference
tableinputManagerInputBinding reference for camera input handling
tableinputDisplayManagerInputDisplayManager reference for camera input glyph display
Return Values
booleanisActivateableis activateable
tableShopConfigScreeninstance

createInputGlyphs

Description
Create input help glyphs.
Definition
createInputGlyphs()
Return Values
tableinstanceInstance of object

createFadeAnimations

Description
Create animations for fading the screen.
Definition
createFadeAnimations()
Return Values
booleansuccesssuccess

fadeScreen

Description
Setter function for fading animations.
Definition
fadeScreen()
Return Values
tableinstanceInstance of object

createWorkshop

Description
Load the workshop background geometry.
This will not yet link the workshop into the scene graph. That operation is done on the fly on open and close.
Definition
createWorkshop()
Return Values
booleansuccesssuccess

setWorkshopNode

Description
Set the node ID of the workshop model when loaded.
Definition
setWorkshopNode()
Return Values
booleansuccesssuccess

createCamera

Description
Create and initialize the workshop camera.
Definition
createCamera()
Return Values
stringattributesattributes
stringnodesnodes

resetCamera

Description
Reset camera rotation and distance fields.
The changes will be applied on the next update when the camera is repositioned.
Definition
resetCamera()

delete

Description
Delete this screen instance and release resources.
Definition
delete()
Return Values
tableinstanceInstance of object

updateBalanceText

Description
Update the current balance display.
Definition
updateBalanceText()
Return Values
booleansuccesssuccess

processStoreItemUpkeep

Description
Process and return daily upkeep cost of a store item.
Definition
processStoreItemUpkeep()
Return Values
booleansuccesssuccess

processStoreItemPowerOutput

Description
Process and return the power ouput of a store item.
Definition
processStoreItemPowerOutput()
Return Values
stringattributesattributes
stringnodesnodes

processStoreItemFuelCapacity

Description
Process and return the fuel capacity of a store item.
Definition
processStoreItemFuelCapacity()

processStoreItemDefCapacity

Description
Process and return the fuel capacity of a store item.
Definition
processStoreItemDefCapacity()
Return Values
tableinstanceInstance of object

processStoreItemMaxSpeed

Description
Process and retuen the maximum speed of a store item.
Definition
processStoreItemMaxSpeed()
Return Values
booleansuccesssuccess

processStoreItemCapacity

Description
Process and return the fill capacity and unit of a store item.
Definition
processStoreItemCapacity()
Return Values
tableinstanceInstance of object

processStoreItemWorkingWidth

Description
Process and return the working width of a store item.
Definition
processStoreItemWorkingWidth()
Return Values

processStoreItemWorkingSpeed

Description
Process and return the working speed of a store item.
Definition
processStoreItemWorkingSpeed()
Return Values

processStoreItemPowerNeeded

Description
Process and return the power requirement of a store item.
Definition
processStoreItemPowerNeeded()
Return Values
boolreturnstrue if placement successful

processAttributeData

Description
Process a store item's attribute data.
Changes icons and display texts.
Definition
processAttributeData()
Return Values
booleansuccesssuccess

getConfigurationCostsAndChanges

Description
Check the base and upgrade cost of a storeItem or current vehicle and whether or not there are any changes.
Definition
getConfigurationCostsAndChanges()
Return Values
stringattributesattributes
stringnodesnodes
floatBaseprice
floatUpgradeprice
boolTrueif there are changes

updatePriceData

Description
Update price display data.
Definition
updatePriceData()

updateData

Description
Update display data for a store item and/or concrete vehicle.
Definition
updateData()
Return Values
boolreturntrue if doghouse can be activated to fill bowl

overrideOptionFocus

Description
Override an option element's focus behavior.
If the first option is focused and navigation goes up, the option slider should be triggered instead. Vice versa for
the last option and down direction.
Definition
overrideOptionFocus()
Return Values

getDefaultConfigurationColorIndex

Description
Get the default color index of a color configuration.
Definition
getDefaultConfigurationColorIndex(string configName, table configItems, table vehicle)
Arguments
stringconfigNameConfiguration attribute name of the color
tableconfigItemsArray of configuration attribute options
tablevehicle[optional] Existing vehicle which is being configured
Return Values
booltrueif registration went well

disableUnusedOptions

Description
Disable unused option elements.
During configuration loading, the UI elements are populated in order until no more elements or attributes are
available. If there are more UI elements than attributes, disable those elements now.
Definition
disableUnusedOptions(int currentOptionIndex, int currentColorIndex)
Arguments
intcurrentOptionIndexIndex of first unused configuration option element
intcurrentColorIndexIndex of first unused color picker element
Return Values
booltrueif registration went well

updateButtons

Description
Update button states.
Definition
updateButtons()
Return Values
tableinstanceInstance of object

loadCurrentConfiguration

Description
Load the current configuration of a given vehicle store item.
Definition
loadCurrentConfiguration()
Return Values
booleansuccesssuccess

onVehicleLoaded

Description
Handles asynchronous vehicle loading event.
Definition
onVehicleLoaded()
Return Values
booleanisActivateableis activateable

updateSlider

Description
Update visibility and values of the options slider.
Definition
updateSlider()
Return Values
tableinstanceInstance of object

onSliderChanged

Description
Handle slider change events.
Function must be targeted by screen configuration.
Definition
onSliderChanged()
Return Values
booleansuccesssuccess

updateDisplay

Description
Update all display data based on a store item and / or vehicle.
Definition
updateDisplay(table storeItem, table vehicle, int scrollValue, bool doNotReload)
Arguments
tablestoreItemStore item reference
tablevehicleVehicle reference (for customizing)
intscrollValueCurrent scroll value in cases where there are more options than display elements.
booldoNotReloadIf true, the vehicle is not reloaded (use e.g. when scrolling)
Return Values
booleansuccesssuccess

setCurrentMission

Description
Set the current mission reference at the start of the mission.
Definition
setCurrentMission()
Return Values
booleansuccesssuccess

setEconomyManager

Description
Set the economy manager reference at the start of the mission
Definition
setEconomyManager()
Return Values
stringattributesattributes
stringnodesnodes

loadMapData

Description
Process map data.
Extracts the workshop position if possible.
Definition
loadMapData()

setWorkshopWorldPosition

Description
Set the workshop world position if a map has a custom position defined.
Definition
setWorkshopWorldPosition()
Return Values
booleanshowInfoshow info

deletePreviewVehicles

Description
Delete all preview vehicles and clear stored array.
Definition
deletePreviewVehicles()
Return Values
floatfillDeltareal fill delta

setStoreItem

Description
Set the current store item or vehicle to be modified.
Definition
setStoreItem()
Return Values
floatisAllowedis allowed

setRequestExitCallback

Description
Set a callback to request exiting this screen and the entire shop at once.
Definition
setRequestExitCallback()
Return Values
tableselfinstance of class event

shouldFocusChange

Description
Override and shadow of GuiElement:shouldFocusChange().
Always allows focus change.
Definition
shouldFocusChange()
Return Values
tableinstanceinstance of event

setConfigPrice

Description
Set the price label for a given configuration.
Definition
setConfigPrice()
Return Values
tableinstanceInstance of object

onPickColor

Description
Handle the result of the color picking dialog.
Definition
onPickColor()
Return Values
booleansuccesssuccess

selectFirstConfig

Description
Select the first configuration option.
Definition
selectFirstConfig()
Return Values
tableinstanceInstance of object

processStoreItemConfigurationSet

Description
Process a configuration set of a store item.
Definition
processStoreItemConfigurationSet(table storeItem, table configSet, table vehicle)
Arguments
tablestoreItemStoreItem reference
tableconfigSetStoreItem configuration set {name = name, configurations={i=configName}}
tablevehicle[optional] Existing Vehicle instance reference
Return Values
booleansuccesssuccess

processStoreItemSubConfigurationOption

Description
Process a sub-configuration option of a store item.
Sub-configurations are fine-grained configuration sets within vehicle configurations, e.g. wheel brands with distinct
options per brand.
Definition
processStoreItemSubConfigurationOption(table storeItem, string configName, table vehicle)
Arguments
tablestoreItemStoreItem reference
stringconfigNameVehicle configuration name
tablevehicle[optional] Existing Vehicle instance
Return Values
booleanisActiveForInputis active for input

processStoreItemConfigurationOption

Description
Process a configuration option of a store item.
Definition
processStoreItemConfigurationOption(table storeItem, string configName, table configItems, table vehicle, bool isSubConfigOption)
Arguments
tablestoreItemStoreItem reference
stringconfigNameVehicle configuration name
tableconfigItemsArray of configuration items (see StoreItemUtil.addConfigurationItem() for structure)
tablevehicle[optional] Existing Vehicle instance
boolisSubConfigOption[optional, default=false] If true, treats this option as the selection of a sub-configuration set
Return Values
booleanisActiveForSoundis active for sound

processStoreItemColorOption

Description
Process a color option of a store item.
Definition
processStoreItemColorOption(table storeItem, string configName, table colorItems, int colorPickerIndex, table vehicle)
Arguments
tablestoreItemStoreItem reference
stringconfigNameVehicle configuration name
tablecolorItemsArray of color configuration items
intcolorPickerIndexElement index in this screen of the color picker to populate with the configuration data
tablevehicle[optional] Existing Vehicle instance
Return Values
boolean
stringwarningMessagewarning message displayed in the shop

processStoreItemConfigurations

Description
Process store item configurations into more convenient data structures for display.
The processed data is stored in instance fields.
Definition
processStoreItemConfigurations()

updateConfigSetOptionElement

Description
Update a configuration option element with the configuration set selection.
Definition
updateConfigSetOptionElement()
Return Values
tableselfinstance of class event

updateConfigOptionElement

Description
Update a configuration option element with a regular configuration option.
Definition
updateConfigOptionElement()
Return Values
tableinstanceinstance of event

updateSubConfigOptionElement

Description
Update a configuration option element with a sub-configuration selection.
Definition
updateSubConfigOptionElement()
Return Values
tableinstanceInstance of object

updateConfigOptionsData

Description
Update display data in config options based on the current scroll value.
Definition
updateConfigOptionsData()
Return Values
booleanisInRangeis in range
intNumberof used config option elements

updateConfigOptionsNavigation

Description
Update config option navigation behavior.
Overrides focus navigation between elements and including scrolling.
Definition
updateConfigOptionsNavigation(int scrollValue, int usedConfigElementCount, int usedColorElementCount)
Arguments
intscrollValueCurrent scrolling value
intusedConfigElementCountNumber of config option elements used
intusedColorElementCountNumber of color option elements used
Return Values
booleanisInRangeis in range

updateConfigOptionsDisplay

Description
Update configuration display elements based on the currently available configurations and scrolling value.
Definition
updateConfigOptionsDisplay()
Return Values
booleansuccesssuccess

update

Description
Update the configuration screen's state.
Definition
update()
Return Values
booleansuccesssuccess

updateCamera

Description
Update camera orientation and position.
Definition
updateCamera()
Return Values
booleansuccesssuccess

updateDepthOfField

Description
Update the depth of field blur effect.
Definition
updateDepthOfField()
Return Values
booleansuccesssuccess

draw

Description
Draw the shop config screen.
Override for custom drawing.
Definition
draw()
Return Values
stringattributesattributes
stringnodesnodes

onOpen

Description
Event function called when opening this screen.
Definition
onOpen()

onClose

Description
Event function called when closing this screen.
Definition
onClose()
Return Values
integerpriceprice

onClickOk

Description
Handle a click or button activation of the "Buy" button.
Definition
onClickOk()
Return Values

onYesNoBuy

Description
Buying confirmation dialog callback.
Definition
onYesNoBuy()
Return Values
integerdailyUpkeepdaily up keep

onVehicleBought

Description
Handle vehicle buy event.
Definition
onVehicleBought()
Return Values
integersellPricesell price

onClickActivate

Description
Handle a click or button activation of the "Lease" button.
Definition
onClickActivate()
Return Values
{i={x, y, z, side1x, side1y, side1z, side2x, side2y, side2z}}, all numbers in world space coordinates

onYesNoLease

Description
Handle leasing dialog confirmation.
Definition
onYesNoLease()
Return Values
tablecapacityAndUnitcapacity and unit

onClickBack

Description
Handle back button activation.
Definition
onClickBack()
Return Values
integerincomePerHourincome per hour

onCallback

Description
Trigger the callback set in setCallbacks() to notify another component of the current configuration.
Definition
onCallback(bool leaseItem, table storeItem, table configurations, float price)
Arguments
boolleaseItemIf true, the item should be leased
tablestoreItemStoreItem instance
tableconfigurationsItem configuration attributes table
floatpriceItem configuration price
Return Values
tableinstanceInstance of object

updateInputGlyphs

Description
Update input glyphs when input context changes.
Definition
updateInputGlyphs()
Return Values
booleansuccesssuccess

registerInputActions

Description
Register required input action events.
Definition
registerInputActions()
Return Values
booleansuccesssuccess

disableAlternateBindings

Description
Disable alternate bindings for menu navigation.
This will disable some default bindings which interfere with camera controls (e.g. D-Pad on controller). Whenever any
input event is modified, this method must be called again afterwards.
Definition
disableAlternateBindings()
Return Values
stringattributesattributes
stringnodesnodes

onCameraLeftRight

Description
Handle input for camera left/right.
Definition
onCameraLeftRight()

onCameraUpDown

Description
Handle input for camera up down.
Definition
onCameraUpDown()
Return Values
booleansuccesssuccess

onCameraZoom

Description
Handle input for camera zoom.
Definition
onCameraZoom()
Return Values
booleansuccesssuccess

updateInput

Description
Update input for this frame.
Definition
updateInput()
Return Values
stringattributesattributes
stringnodesnodes

limitXRotation

Description
Limit camera X rotation by the constant maximum and the maximum camera height.
Definition
limitXRotation()

updateInputContext

Description
Update input context and activate suitable events.
Definition
updateInputContext()
Return Values
tablecapacityAndUnitcapacity and unit

ShopController

Description
Shop buying/selling process controller.
-- Handle buying and selling logic, display data and synchronization of shop screens.
--@category GUI

new

Description
Create a new ShopController.
Definition
new(table messageCenter, table l10n, table storeManager, table brandManager, table fillTypeManager)
Arguments
tablemessageCenterMessageCenter reference for local network UI event handling
tablel10nI18N reference
tablestoreManagerStoreManager reference for store item loading
tablebrandManagerBrandManager reference for brands loading
tablefillTypeManagerFillTypeManager reference for fill type data access
Return Values
integerincomePerHourincome per hour

subscribeEvents

Description
Subscribe to receive notifications for shop events.
Definition
subscribeEvents()
Return Values
tableinstanceInstance of object

addBrandForDisplay

Description
Add a brand loaded from store items to the display collection.
Definition
addBrandForDisplay()
Return Values
booleansuccesssuccess

addCategoryForDisplay

Description
Add a category loaded from store items to a suitable display collection.
Definition
addCategoryForDisplay()
Return Values
booleansuccesssuccess

load

Description
Load brands and items category data.
Definition
load()
Return Values
stringattributesattributes
stringnodesnodes

setClient

Description
Set the network client on mission loading.
Definition
setClient()

setCurrentMission

Description
Set the current mission after loading.
Definition
setCurrentMission()
Return Values
tablecapacityAndUnitcapacity and unit

setUpdateShopItemsCallback

Description
Set the callback to trigger a shop item list update.
Definition
setUpdateShopItemsCallback()
Return Values
integerincomePerHourincome per hour

setUpdateAllItemsCallback

Description
Set the callback to trigger a full shop update.
Definition
setUpdateAllItemsCallback()
Return Values
tableinstanceInstance of object

setSwitchToConfigurationCallback

Description
Set the callback to switch views to the vehicle configuration screen.
Definition
setSwitchToConfigurationCallback()
Return Values
booleansuccesssuccess

setStartPlacementModeCallback

Description
Set the callback to enter placement mode.
Definition
setStartPlacementModeCallback()
Return Values
booleansuccesssuccess

filterOwnedItemsByFarmId

Description
Filter a collection of owned items by their farm ID.
The given collection will not be modified.
Definition
filterOwnedItemsByFarmId(table ownedFarmItems, int farmId)
Arguments
tableownedFarmItemsCollection of owned farm items (for structure see BaseMission.addItemToList)
intfarmIdFarm ID
Return Values
booleansuccesssuccess
tableNewcollection of filtered owned items

setOwnedFarmItems

Description
Set the array of owned items for the garage view of the current player's farm.
Definition
setOwnedFarmItems(table ownedFarmItems, int playerFarmId)
Arguments
tableownedFarmItemsCollection of owned farm items (for structure see BaseMission.addItemToList)
intplayerFarmIdFarm ID
Return Values
tableinstanceInstance of object

setLeasedFarmItems

Description
Set the array of leased items for the garage view of the current player's farm.
Definition
setLeasedFarmItems(table leasedFarmItems, int playerFarmId)
Arguments
tableleasedFarmItemsCollection of owned farm items (for structure see BaseMission.addItemToList)
intplayerFarmIdFarm ID
Return Values
booleansuccesssuccess

update

Description
Update the shop controller state.
Delays buy events by one frame.
Definition
update()
Return Values
booleansuccesssuccess

makeDisplayItem

Description
Make a display item out of a store item and optionally a concrete object.
Definition
makeDisplayItem()
Return Values
booleansuccesssuccess

getOwnedItems

Description
Get an array of items owned by the player's farm.
Definition
getOwnedItems()
Return Values
tableinstanceInstance of object

getLeasedVehicles

Description
Get an array of vehicles leased by the player's farm.
Definition
getLeasedVehicles()
Return Values
booleansuccesssuccess

getOwnedFarmItems

Description
Get the collection of owned farm items for the current player's farm.
Definition
getOwnedFarmItems()
Return Values
booleanisActivateableis activateable

getLeasedFarmItems

Description
Get the collection of leased farm items for the current player's farm.
Definition
getLeasedFarmItems()
Return Values
tableinstanceInstance of object

getBrands

Description
Get an array of known brands structured for display.
Definition
getBrands()
Return Values
booltrueif ok
tableArrayof brands in the form of {i={id = brand.index, iconFilename = brand.image, label = brand.title}}

getVehicleCategories

Description
Get an array of known vehicle categories structured for display.
Definition
getVehicleCategories()
Return Values
tablereturnsthe graphics root node
tableArrayof vehicle categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

getToolCategories

Description
Get an array of tool categories structured for display.
Definition
getToolCategories()
Return Values
booltrueif input is allowed.
tableArrayof tool categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

getObjectCategories

Description
Get an array of object categories structured for display.
Definition
getObjectCategories()
Return Values
floatposXx position of player
floatposYy position of player
floatposZz position of player
floatgraphicsRotYrotation of the player
tableArrayof object categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

getPlaceableCategories

Description
Get an array of placeable categories structured for display.
Definition
getPlaceableCategories()
Return Values
tableArrayof placeable categories in the form of {i={id = category.index, iconFilename = category.image, label = category.title}}

getItemsByBrand

Description
Get store items for a given brand ID.
Definition
getItemsByBrand()

getItemsByCategory

Description
Get shop display items for a given category name.
Definition
getItemsByCategory()

canBeBought

Description
Check if a store item can be bought at a given price and considering the current game state.
Definition
canBeBought()
Return Values
boolreturnstrue if distance to player root node is lower than clip distance

buy

Description
Buy an item.
Definition
buy(table storeItem, bool outsideBuy)
Arguments
tablestoreItemStoreItem to buy
booloutsideBuyIf true, means that an item is "bought" without anyone paying for it, e.g. as an achievement bonus
Return Values
floatreturnscalculated priority

buyVehicle

Description
Buy a vehicle.
Definition
buyVehicle()
Return Values
stringthatwill be displayed on console

onYesNoBuyObject

Description
Buy object confirmation dialog callback.
Definition
onYesNoBuyObject()
Return Values
stringthatwill be displayed on console

buyObject

Description
Buy an object.
Definition
buyObject()
Return Values
stringthatwill be displayed on console

buyHandTool

Description
Buy a hand tool.
Definition
buyHandTool()
Return Values
boolreturnstrue object that was hit is valid

sell

Description
Sell an item.
Definition
sell(table item)
Arguments
tableitemItem to sell
Return Values
boolreturnstrue object that was hit is valid

sellWarningInfoClickOk

Description
Show dialog for selling confirmation.
Definition
sellWarningInfoClickOk()
Return Values
tablereturnsthe handtool

onSellCallback

Description
Selling confirmation dialog callback.
Definition
onSellCallback()
Return Values
stringFilenameof currently equipped hand tool or empty string if no hand tool is equipped

onSellItem

Description
Event handling function which is called when selling an item has been confirmed.
Definition
onSellItem()
Return Values
alwaysreturnsfalse

sellPlaceable

Description
Sell a placeable object.
Activates placement mode if the player owns more than one instance of the given placeable.
Definition
sellPlaceable()
Return Values
stringthatwill be displayed on console

sellHandTool

Description
Sell a hand tool.
Definition
sellHandTool()
Return Values
tableinstanceinstance of object

sellVehicle

Description
Sell a vehicle.
Definition
sellVehicle()
Return Values
booleantrueif loading was successful else false

setConfigurations

Description
Set a buying configuration is used when sending buy events during update().
Definition
setConfigurations()
Return Values
booleantrueif loading was successful else false

finalizeBuy

Description
Finalize a buying (or leasing) process and trigger events according to the requested item type during update().
Definition
finalizeBuy()
Return Values
booleantrueif added successful else false

onHandToolSellEvent

Description
Event callback on local SellHandToolEvent execution.
Definition
onHandToolSellEvent()
Return Values
tableplayerthe player object

onHandToolSold

Description
Event callback on successful SellHandToolEvent.
Definition
onHandToolSold()
Return Values
tableplayerthe player object

onHandToolSellFailed

Description
Event callback on failed SellHandToolEvent.
Definition
onHandToolSellFailed()
Return Values
integernumbernumber of models

onVehicleBuyEvent

Description
Event callback on local BuyVehicleEvent execution.
Definition
onVehicleBuyEvent()
Return Values
tableinstanceInstance of object

onVehicleBought

Description
Event callback on successful BuyVehicleEvent.
Definition
onVehicleBought()
Return Values
tableinstanceInstance of object

onVehicleBuyFailed

Description
Event callback on failed BuyVehicleEvent.
Definition
onVehicleBuyFailed()
Return Values
tableinstanceInstance of object

onObjectBuyEvent

Description
Event callback on local BuyObjectEvent execution.
Definition
onObjectBuyEvent()
Return Values
tableinstanceInstance of PlayerSetFarmAnswerEvent

onObjectBought

Description
Event callback on successful BuyObjectEvent.
Definition
onObjectBought()
Return Values
tableinstanceInstance of object

onObjectBuyFailed

Description
Event callback on failed BuyObjectEvent.
Definition
onObjectBuyFailed()
Return Values
tableinstanceInstance of object

onHandToolBuyEvent

Description
Event callback on local BuyHandToolEvent execution.
Definition
onHandToolBuyEvent()
Return Values
tableinstanceInstance of object

onHandToolBought

Description
Event callback on successful BuyHandToolEvent.
Definition
onHandToolBought()
Return Values
tableinstanceInstance of object

onHandToolBuyFailed

Description
Event callback on failed BuyHandToolEvent.
Definition
onHandToolBuyFailed()
Return Values
tableinstanceinstance of object

onVehicleSellEvent

Description
Event callback on local SellVehicleEvent execution.
Definition
onVehicleSellEvent()
Return Values
boolreturnstrue if player can interact with object

onVehicleSold

Description
Event callback on successful SellVehicleEvent.
Definition
onVehicleSold()
Return Values
tableinstanceinstance of object

onVehicleSellFailed

Description
Event callback on failed SellVehicleEvent.
Definition
onVehicleSellFailed()
Return Values
boolreturnstrue if player can feed an animal

onPlaceableSellEvent

Description
Event callback on local SellPlaceableEvent execution.
Definition
onPlaceableSellEvent()
Return Values
tableinstanceinstance of object

onPlaceableSold

Description
Event callback on successful SellPlaceableEvent.
Definition
onPlaceableSold()
Return Values
boolreturnstrue if player can interact with an animal

onPlaceableSellFailed

Description
Event callback on failed SellPlaceableEvent.
Definition
onPlaceableSellFailed()
Return Values
tableinstanceinstance of object

onBoughtCallback

Description
Buying process termination (success or failure) information dialog callback.
Definition
onBoughtCallback()
Return Values
boolreturnstrue if player can pet an animal

onSoldCallback

Description
Selling process termination (success or failure) information dialog callback.
Definition
onSoldCallback()
Return Values
tableinstanceinstance of object

brandSortFunction

Description
Brand sorting function.
Definition
brandSortFunction()
Return Values
boolreturnstrue if player can ride an animal

categorySortFunction

Description
Category sorting function.
Uses the category order index which was set when loading. This restores category order to the XML definition.
Definition
categorySortFunction()
Return Values
tableinstanceinstance of object

displayItemSortFunction

Description
Display item sorting function (for owned and leased objects in the garage).
First sorts by the category order index provided to the display item, then by price within the same category. As a
final tie-breaker for vehicles owned at mission start, the object ID is compared to guarantee a sort order
resolution.
Definition
displayItemSortFunction()
Return Values
tableinstanceinstance of object

ShopDisplayItem

Description
Display data class for shop items.
-- Both store items and concrete items can be represented by this class to be displayed in the shop for buying or
selling.

new

Description
Create a new ShopDisplayItem instance.
Definition
new(table storeItem, table concreteItem, table attributeIconProfiles, table attributeValues, table fillTypeFilenames, table seedTypeFilenames, string functionText, int orderValue)
Arguments
tablestoreItemStore item definition table, see StoreManager.lua.
tableconcreteItemConcrete game object of the given store item type or ShopDisplayItem.NO_CONCRETE_ITEM.
tableattributeIconProfilesArray of UI profiles for attribute icons
tableattributeValuesArray of value display strings for attributes which correspond to the icons
tablefillTypeFilenamesArray of fill type icon file names
tableseedTypeFilenamesArray of seed fill type icon file names
stringfunctionTextDescription text of the item's function
intorderValueDisplay item category order value, lower is higher order

ShopItemsFrame

Description
Shop items frame for the in-game menu shop.
-- Displays purchasable items of a common category in a horizontal list layout.
--@category GUI

new

Description
Create a new ShopItemsFrame instance.
Definition
new(table subclass_mt)
Arguments
tablesubclass_mt[optional] Meta table of subclass
Return Values
booltrueif player can crouch

setItemClickCallback

Description
Set the callback to use when an item is activated (for buying or selling).
Definition
setItemClickCallback()
Return Values
tableinstanceinstance of object

setItemSelectCallback

Description
Set the callback to use when an item is selected in the view.
Definition
setItemSelectCallback()
Return Values
booltrueif player can idle

setHeader

Description
Set header icon and text.
Definition
setHeader()
Return Values
tableinstanceinstance of object

setCategory

Description
Set the category to display.
Definition
setCategory()
Return Values
booltrueif player can idle

setShowBalance

Description
Set the balance elements' visibility.
Definition
setShowBalance()
Return Values
tableinstanceinstance of object

setShowNavigation

Description
Set the navigation header's visibility.
Definition
setShowNavigation()
Return Values
booltrueif state is available

setCurrentBalance

Description
Set the current money balance display.
Definition
setCurrentBalance(float balance, string balanceString)
Arguments
floatbalanceCurrent balance of the current player
stringbalanceStringProperly formatted money string
Return Values
tableinstanceinstance of object

setSlotsUsage

Description
Set the current slot usage display for consoles.
Definition
setSlotsUsage()
Return Values
booltrueif player can idle

setDisplayItems

Description
Set an ordered array of ShopDisplayItem instances to display in this frame.
Definition
setDisplayItems()
Return Values
tableinstanceinstance of object

updateScrollButtons

Description
Update scroll button visibility based on the currently visible list items.
Definition
updateScrollButtons()
Return Values
booltrueif player can jump

getStoreItemDisplayPrice

Description
Get a store items price (buy or sell value) for displaying.
Definition
getStoreItemDisplayPrice()
Return Values
tableinstanceinstance of object

assignItemFillTypesData

Description
Assign fill types data to detail box.
Creates icons for fill types.
Definition
assignItemFillTypesData(string baseIconProfile, table iconFilenames, int attributeIndex)
Arguments
stringbaseIconProfileUI profile for the fill type base icon
tableiconFilenamesArray of filenames of fill type icons
intattributeIndexIndex of attribute slot to use
Return Values
tableplayerstate
intNextusable attribute slot index after these fill types

assignItemTextData

Description
Assign text data to detail box.
Definition
assignItemTextData(table displayItem)
Arguments
tabledisplayItemShopDisplayItem which holds item attribute data
Return Values
booltrueif player state is available
intNumberof attributes used for text data

assignItemAttributeData

Description
Assign display data of a selected ShopDisplayItem to the attribute elements.
Definition
assignItemAttributeData(table displayItem)
Arguments
tabledisplayItemShopDisplayItem which holds item attribute data
Return Values
booltrueif player state is active

getMainElementSize

Description
Get the frame's main content element's screen size.
Definition
getMainElementSize()
Return Values
tableinstanceinstance of object

getMainElementPosition

Description
Get the frame's main content element's screen position.
Definition
getMainElementPosition()
Return Values
booltrueif player can idle

onClickItem

Description
Handle a click / button activation on an item.
Definition
onClickItem()
Return Values
tableinstanceinstance of object

onDoubleClickItem

Description
Handle a double-click on an item.
Definition
onDoubleClickItem()
Return Values
booltrueif player can run

onClickLeft

Description
Handle click on left navigation button.
Definition
onClickLeft()
Return Values
booltrueif player can run

onClickRight

Description
Handle click on right navigation button.
Definition
onClickRight()
Return Values
tableinstanceinstance of object

onScroll

Description
Handle a list scroll event.
Definition
onScroll()
Return Values
booltrueif player can swim

onItemSelected

Description
Handle selection of an item.
Definition
onItemSelected()
Return Values
tableinstanceinstance of object

SideNotification

Description
HUD side notification element.
-- Displays notifications issued by other game components at the side of the screen.
--@category GUI

new

Description
Create a new SideNotification.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD atlas texture
Return Values
tableinstanceinstance of object
tableSideNotificationinstance

addNotification

Description
Add a notification message to display.
Definition
addNotification(string text, table color, int displayDuration)
Arguments
stringtextDisplay message text
tablecolorColor array as {r, g, b, a}
intdisplayDurationDisplay duration of message in milliseconds
Return Values
tableinstanceinstance of object

update

Description
Update notifications state.
Definition
update()
Return Values
tableselfinstance

draw

Description
Draw the notifications.
Definition
draw()
Return Values
tableinstanceinstance of object

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor
Return Values
booleantrueif loading was successful else false

setScale

Description
Set uniform UI scale.
Definition
setScale()
Return Values
booleantrueif loading was successful else false

updateSizeAndPositions

Description
Update sizes and positions of this elements and its children.
Definition
updateSizeAndPositions()
Return Values
tableanimalslist all animals

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Return Values
tableanimalthe animal object

createBackground

Description
Create the background overlay.
Definition
createBackground()
Return Values
tableanimalthe animal object

createComponents

Description
Create required display components.
Definition
createComponents()
Return Values
tableanimalthe animal object

SiloExtensionPlaceable

Description
When trying to sell an extension that is required to store all fills, show a warning before selling the extension and the contents.

load

Description
Load silo extension
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
46function SiloExtensionPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
47 if not SiloExtensionPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
48 return false
49 end
50
51 local xmlFile = loadXMLFile("TempXML", xmlFilename)
52
53 local storageKey = "placeable.storage"
54 if hasXMLProperty(xmlFile, storageKey) then
55 local storageNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, storageKey.."#node"))
56 if storageNode ~= nil then
57 self.storage = Storage:new(self.isServer, self.isClient)
58 self.storage:load(storageNode, xmlFile, storageKey)
59 else
60 g_logManager:xmlWarning(xmlFilename, "Missing 'node' for storage '%s'!", storageKey)
61 end
62 else
63 g_logManager:xmlWarning(xmlFilename, "Missing 'storage' for siloExtension '%s'!", xmlFilename)
64 end
65
66 delete(xmlFile)
67
68 return true
69end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
73function SiloExtensionPlaceable:finalizePlacement()
74 SiloExtensionPlaceable:superClass().finalizePlacement(self)
75
76 local lastFoundUnloadingStations = g_currentMission:getStorageTargetsInRange(g_currentMission.unloadingStations, self.storage)
77 local lastFoundLoadingStations = g_currentMission:getStorageTargetsInRange(g_currentMission.loadingStations, self.storage)
78
79 self.storage:setOwnerFarmId(self:getOwnerFarmId(), true)
80 g_currentMission:addStorage(self.storage)
81 self.storage:register(true)
82
83 g_currentMission:addStorageToUnloadingStations(self.storage, lastFoundUnloadingStations, false)
84 g_currentMission:addStorageToLoadingStations(self.storage, lastFoundLoadingStations, false)
85end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
91function SiloExtensionPlaceable:readStream(streamId, connection)
92 SiloExtensionPlaceable:superClass().readStream(self, streamId, connection)
93 if connection:getIsServer() then
94 local storageId = NetworkUtil.readNodeObjectId(streamId)
95 self.storage:readStream(streamId, connection)
96 g_client:finishRegisterObject(self.storage, storageId)
97 end
98end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
104function SiloExtensionPlaceable:writeStream(streamId, connection)
105 SiloExtensionPlaceable:superClass().writeStream(self, streamId, connection)
106 if not connection:getIsServer() then
107 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.storage))
108 self.storage:writeStream(streamId, connection)
109 g_server:registerObjectInStream(connection, self.storage)
110 end
111end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
127function SiloExtensionPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
128 if not SiloExtensionPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
129 return false
130 end
131
132 if not self.storage:loadFromXMLFile(xmlFile, key..".storage") then
133 return false
134 end
135
136 return true
137end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
144function SiloExtensionPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
145 SiloExtensionPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
146
147 self.storage:saveToXMLFile(xmlFile, key..".storage", usedModNames)
148end

canBeSold

Description
show a warning before selling the extension and the contents.
Definition
canBeSold()

SliderElement

Description
Draggable viewport slider element.
-- If #hasButtons is true or not present, this element requires 2 ButtonElement instances as the first children, which
provide another way to scroll in addition to clicking the bar or dragging the handle.
-- Used layers: "image" for a background image, "sliderImage" for a slider handle background image.
-- Implicit callback:
onSliderValueChanged(element, newValue) is called on all children and the target data element when the slider value
changes, if those elements have the method defined.
--@category GUI
--@xmlConfig GuiElement#direction string [optional] Slider orientation, defaults to "x". Valid values: "x" for horizontal, "y" for vertical.

updateSliderButtons

Description
Update the disabled-ness of the slider buttons depending on current state
Definition
updateSliderButtons()

canReceiveFocus

Description
Determine if this SliderElement can receive focus.
Definition
canReceiveFocus()

SpeakerDisplay

Description
Player speaker display for consoles.
-- Displays currently speaking players for consoles only. This display is used in place of the chat window.
--@category GUI

new

Description
Create a new SpeakerDisplay.
Definition
new(string hudAtlasPath, table ingameMap)
Arguments
stringhudAtlasPathPath to the HUD atlas texture.
tableingameMapIngameMap reference for positioning
Return Values
stringanimaltype
tableSpeakerDisplayinstance

setUsers

Description
Set the references to the currently connected users.
Definition
setUsers()
Return Values
table

onMenuVisibilityChange

Description
Handle menu visibility state change.
Definition
onMenuVisibilityChange()
Return Values
tablestoreinformation [shopItemName, canBeBought, imageFilename, price]

updateSpeakingState

Description
Update current speaking state for all connected users.
Definition
updateSpeakingState()
Return Values
tableinstanceinstance of object

updateVisibility

Description
Update visibility states based on active speakers.
Definition
updateVisibility()
Return Values
booleantrueif loading was successful else false

update

Description
Update the display state each frame.
Definition
update()
Return Values
tablereturnsa food group or nil if nothing is found

setScale

Description
Set this element's UI scale.
Definition
setScale()
Return Values
tableinstanceInstance of object

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor
Return Values
booltrueif load is successful

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Return Values
integeridof the animal group

createBackground

Description
Create the background overlay.
Definition
createBackground()
Return Values
integernumberof trees found

createSpeakerLine

Description
Create a line for an active speaker.
Definition
createSpeakerLine()
Return Values
booltrueto continue counting trees

createComponents

Description
Create required display components.
Definition
createComponents()
Return Values
tableinstanceinstance of object

SpeedMeterDisplay

Description
Vehicle HUD speed meter display element.
-- Displays gauges for current speed, fuel level and vehicle wear / damage. Also shows operating time, textual speed
display and cruise control state.
--@category GUI

new

Description
Create a new SpeedMeterDisplay instance.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
Return Values
booleansuccesssuccess

getBasePosition

Description
Get this element's base position as a reference for other component's positioning.
Definition
getBasePosition()
Return Values
stringattributesattributes
stringnodesnodes

createComponents

Description
Create display components for the speed meter.
Components are created with an implicit scale of 1. Scaling should only ever happen after initialization.
Definition
createComponents(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas

delete

Description
Delete this instance and all managed components.
Definition
delete()
Return Values
booleaninScopein scope

setVehicle

Description
Set the current vehicle which provides the data for the speed meter.
Definition
setVehicle(table vehicle)
Arguments
tablevehicleVehicle reference
Return Values
floatprioritypriority

update

Description
Update the state of the speed meter.
Definition
update()
Return Values
floatclosestdistance squared in m

updateOperatingTime

Description
Update operating time drawing parameters.
Definition
updateOperatingTime()
Return Values
integerreturnsnumber of animals

updateCruiseControl

Description
Update cruise control drawing parameters.
Definition
updateCruiseControl()
Return Values
boolreturnstrue if there is water

updateGaugeIndicator

Description
Update a gauge indicator needle.
Definition
updateGaugeIndicator(table Indicator, float radiusX, float radiusY, float rotation)
Arguments
tableIndicatorHUDElement
floatradiusXRadius X component of distance to the gauge center
floatradiusYRadius Y component of distance to the gauge center
floatrotationRotation angle of the indicator in radians
Return Values
floatseparateForceXx component of steering force. default is 0.
floatseparateForceYy component of steering force. default is 0.
floatseparateForceZz component of steering force. default is 0.

updateGaugeFillSegments

Description
Update gauge fill segments.
Definition
updateGaugeFillSegments(table fillSegments, float gaugeValue)
Arguments
tablefillSegmentsArray of segment elements
floatgaugeValueCurrent gauge indication value [0, 1]

updateGaugePartialSegments

Description
Update partial gauge segment elements.
Definition
updateGaugePartialSegments(table partialSegments, float indicatorRotation, int rotationDirection, float gaugeRadiusX, float gaugeRadiusY, float gaugeMinAngle, flaot fullSegmentAngle, float detailSegmentAngle, bool isPartialOnly)
Arguments
tablepartialSegmentsArray of segment elements
floatindicatorRotationCurrent indicator rotation angle in radians
introtationDirectionDirection value for the rotation, 1 is counter-clockwise, -1 is clockwise
floatgaugeRadiusXRadius X component of distance to gauge center in screen space
floatgaugeRadiusYRadius Y component of distance to gauge center in screen space
floatgaugeMinAngleAngle of gauge zero position in radians
flaotfullSegmentAngleAngle which spans a filled segment in radians
floatdetailSegmentAngleSmallest angle which can be covered by a partial segment in radians
boolisPartialOnlyIf true, the current gauge has no fill segments and uses only partial segments to display values

updateSpeedGauge

Description
Update the speed gauge state.
Definition
updateSpeedGauge()
Return Values
floatwanderForceXx component of steering force. default is 0.
floatwanderForceYy component of steering force. default is 0.
floatwanderForceZz component of steering force. default is 0.
floatwanderAnglenew wandering angle in rad. default is 0.

updateDamageGauge

Description
Update the damage gauge state.
Definition
updateDamageGauge()

getVehicleFuelLevelAndCapacity

Description
Get fuel level and capacity of a vehicle.
Definition
getVehicleFuelLevelAndCapacity()

updateFuelGauge

Description
Update the fuel gauge state.
Definition
updateFuelGauge()

onAnimateVisibilityFinished

Description
Override of HUDDisplayElement.
Also updates the scaled values which are relative to the current position.
Definition
onAnimateVisibilityFinished()
Return Values
floatseekForceXx component of steering force. default is 0.
floatseekForceYy component of steering force. default is 0.
floatseekForceZz component of steering force. default is 0.

draw

Description
Draw the speed meter.
Definition
draw()

drawOperatingTimeText

Description
Draw vehicle operating time if set.
Definition
drawOperatingTimeText(table vehicle)
Arguments
tablevehicleCurrent vehicle

drawCruiseControlText

Description
Draw the text portion of the cruise control element.
Definition
drawCruiseControlText()
Return Values
booltrueis any player is close to ground

drawSpeedText

Description
Draw the current speed in text.
Definition
drawSpeedText()
Return Values
booltrueis any player is close

fadeFuelGauge

Description
Fade the fuel gauge elements.
Definition
fadeFuelGauge()
Return Values
tableinstanceInstance of object

animateFuelGaugeToggle

Description
Animate (de-)activation of the fuel gauge.
Definition
animateFuelGaugeToggle()
Return Values
boolreturnstrue if load is successful

fadeDamageGauge

Description
Fade the damage gauge elements.
Definition
fadeDamageGauge()
Return Values
floatxworld position. default is 0
floatxworld position. default is 0
floatxworld position. default is 0

animateDamageGaugeToggle

Description
Animate (de-)activation of the damage gauge.
Definition
animateDamageGaugeToggle()

setScale

Description
Set the speed meter scale.
Overrides HUDElement.setScale().
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor, applied to both width and height dimensions

storeGaugeCenterPosition

Description
Calculate and store the gauge center position, including the current UI scale.
Definition
storeGaugeCenterPosition(float baseX, float baseY)
Arguments
floatbaseXGauge background element X position in screen space
floatbaseYGauge background element Y position in screen space
Return Values
boolreturnstrue if animals are spawned

storeScaledValues

Description
Calculate and store scaling values based on the current UI scale.
Definition
storeScaledValues(float baseX, float baseY)
Arguments
floatbaseXGauge background element X position in screen space
floatbaseYGauge background element Y position in screen space
Return Values
boolreturnstrue if all tests are validated

getBackgroundPosition

Description
Get the position of the background element, which provides the SpeedMeterDisplay's absolute position.
Definition
getBackgroundPosition(float backgroundWidth)
Arguments
floatbackgroundWidthScaled background width in pixels
Return Values
integernumberof trees found

createBackground

Description
Create the background overlay for the speed meter.
Definition
createBackground(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
Return Values
booltrueto continue counting trees
tableOverlayinstance

createGaugeBackground

Description
Create the gauge background.
Definition
createGaugeBackground()
Return Values
boolreturntrue is on field

createSideGaugeBackground

Description
Create a side gauge background element.
Definition
createSideGaugeBackground()
Return Values
boolreturnstrue if there is water

createGaugeIconElements

Description
Create gauge icons.
Definition
createGaugeIconElements()
Return Values
boolreturnstrue if current time in hours range

createHorizontalSeparator

Description
Create the horizontal separator HUD element.
Definition
createHorizontalSeparator()
Return Values
integerreturnsthe number of animals to spawn

createCruiseControlElement

Description
Create the cruise control HUD element.
Definition
createCruiseControlElement()
Return Values
boolreturnstrue if animals are spawned

createOperatingTimeElement

Description
Create the operating time HUD element.
Definition
createOperatingTimeElement()
Return Values
stringthatwill be displayed on console

createIndicator

Description
Create a movable indicator needle element.
Definition
createIndicator(string hudAtlasPath, table size, table uvs, table color, table pivot)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
tablesizePixel size of the indicator as an array {width, height}
tableuvsUV coordinates of the indicator texture part as an array {x, y, width, height}
tablecolorColor of the indicator as an RGBA array
tablepivotRotation pivot offset of the indicator as an array {x, y}
Return Values
stringthatwill be displayed on console
tableHUDElementinstance

createGaugeFillElements

Description
Create fill elements for large segments of a gauge.
Definition
createGaugeFillElements(string hudAtlasPath, float baseX, float baseY, float gaugeStartAngle, float gaugeEndAngle, float fillSegmentAngle, table radius, table segmentSize, table segmentPivot, table segmentUVs, table segmentColor)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
floatbaseXBase X position of the gauge element in screen space
floatbaseYBase Y position of the gauge element in screen space
floatgaugeStartAngleGauge starting angle position
floatgaugeEndAngleGauge ending angle position
floatfillSegmentAngleAngle spanned by a fill segment
tableradiusRadius of the gauge as an array {x, y}
tablesegmentSizePixel size of a fill segment as an array {width, height}
tablesegmentPivotRotation pivot offset of a fill segment as an array {x, y}
tablesegmentUVsUV coordinates of a fill segment as an array {x, y, width, height}
tablesegmentColorColor of a fill segment as an RGBA array
Return Values
stringthatwill be displayed on console

createGaugePartialElements

Description
Create gauge elements which span the spaces inbetween fill segments and their indicator needle.
Definition
createGaugePartialElements(string hudAtlasPath, float baseX, float baseY, table fullSegmentSize, table segmentPivot, table segmentColor, table gaugeSegmentUVs)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
floatbaseXBase X position of the gauge element in screen space
floatbaseYBase Y position of the gauge element in screen space
tablefullSegmentSizePixel size of a full segment as an array {width, height}
tablesegmentPivotRotation pivot offset of a segment as an array {x, y}
tablesegmentColorColor of a segment as an RGBA array
tablegaugeSegmentUVsArray of segment UV arrays ordered by size {sizeIndex={x, y, width, height}}
Return Values
stringthatwill be displayed on console

createSpeedGaugeIndicator

Description
Create the indicator needle for the speed gauge.
Definition
createSpeedGaugeIndicator()
Return Values

createSpeedGaugeElements

Description
Create the segment elements for the speed gauge.
Definition
createSpeedGaugeElements()
Return Values

createDamageGaugeIndicator

Description
Create the indicator needle for the damage gauge.
Definition
createDamageGaugeIndicator()
Return Values
stringthatwill be displayed on console

createDamageGaugeElements

Description
Create the gauge segments for the damage gauge.
Definition
createDamageGaugeElements()
Return Values
stringthatwill be displayed on console

createFuelGaugeIndicator

Description
Create the indicator needle for the fuel gauge.
Definition
createFuelGaugeIndicator()
Return Values
tableinstanceinstance of object

createFuelGaugeElements

Description
Create the segment elements for the fuel gauge.
Definition
createFuelGaugeElements()
Return Values
tableinstanceinstance of object

StartMissionInfo

Description
Structured data for mission starts.
-- This serves as a data transfer object between GUI screens when setting up a game.

new

Description
Create a new StartMissionInfo instance.
Definition
new()
Return Values
booleandetachAlloweddetach is allowed

reset

Description
Reset all information for a new setup.
Definition
reset()
Return Values
floatwearMultipliercurrent wear multiplier

StartupScreen

Description
Game Startup Screen.
-- Shows splash and intro videos, leads on to main menu.

exposeControlsAsFields

Description
Duck-typed dummy function to make this class behave like a ScreenElement on initialization.
See Gui:loadGui() for the processing part which requires this.
Definition
exposeControlsAsFields()
Return Values
booltrueif player can idle

StoreManager

Description
Category type for grouping (e.g. in the shop UI)

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
26function StoreManager:new(customMt)
27 local self = AbstractManager:new(customMt or StoreManager_mt)
28
29 return self
30end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
34function StoreManager:initDataStructures()
35 self.numOfCategories = 0
36 self.categories = {}
37 self.items = {}
38 self.xmlFilenameToItem = {}
39 self.modStoreItems = {}
40
41 self.specTypes = {}
42 self.nameToSpecType = {}
43end

loadMapData

Description
Load manager data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
48function StoreManager:loadMapData(xmlFile, missionInfo, baseDirectory)
49 StoreManager:superClass().loadMapData(self)
50
51 -- local all store categories
52 local categoryXMLFile = loadXMLFile("storeCategoriesXML", "dataS/storeCategories.xml")
53 local i = 0
54 while true do
55 local baseXMLName = string.format("categories.category(%d)", i)
56
57 if not hasXMLProperty(categoryXMLFile, baseXMLName) then
58 break
59 end
60 local name = getXMLString(categoryXMLFile, baseXMLName .. "#name")
61 local title = getXMLString(categoryXMLFile, baseXMLName .. "#title")
62 local imageFilename = getXMLString(categoryXMLFile, baseXMLName .. "#image")
63 local type = getXMLString(categoryXMLFile, baseXMLName .. "#type")
64
65 if title ~= nil and title:sub(1, 6) == "$l10n_" then
66 title = g_i18n:getText(title:sub(7))
67 end
68
69 self:addCategory(name, title, imageFilename, type, "")
70
71 i = i + 1
72 end
73 delete(categoryXMLFile)
74
75 -- now load all storeitems
76
77 local storeItemsFilename = "dataS/storeItems.xml"
78 if g_isPresentationVersionSpecialStore then
79 storeItemsFilename = "dataS/storeItems_presentationVersion.xml"
80 end
81
82 self:loadItemsFromXML(storeItemsFilename)
83
84 if xmlFile ~= nil then
85 local mapStoreItemsFilename = getXMLString(xmlFile, "map.storeItems#filename")
86 if mapStoreItemsFilename ~= nil then
87 mapStoreItemsFilename = Utils.getFilename(mapStoreItemsFilename, baseDirectory)
88 self:loadItemsFromXML(mapStoreItemsFilename)
89 end
90 end
91
92 for _, item in ipairs(self.modStoreItems) do
93 g_deferredLoadingManager:addSubtask(function()
94 self:loadItem(item.xmlFilename, item.baseDir, item.customEnvironment, item.isMod, item.isBundleItem, item.dlcTitle)
95 end)
96 end
97
98 return true
99end

addCategory

Description
Adds a new store category
Definition
addCategory(string name, string title, string imageFilename, string baseDir)
Arguments
stringnamecategory index name
stringtitlecategory title
stringimageFilenameimage
stringbaseDirbase directory
Return Values
booleantrueif adding was successful else false
Code
128function StoreManager:addCategory(name, title, imageFilename, type, baseDir)
129 if name == nil or name == "" then
130 print("Warning: Could not register store category. Name is missing or empty!")
131 return false
132 end
133 if not ClassUtil.getIsValidIndexName(name) then
134 print("Warning: '"..tostring(name).."' is no valid name for a category!")
135 return false
136 end
137 if title == nil or title == "" then
138 print("Warning: Could not register store category. Title is missing or empty!")
139 return false
140 end
141 if imageFilename == nil or imageFilename == "" then
142 print("Warning: Could not register store category. Image is missing or empty!")
143 return false
144 end
145 if baseDir == nil then
146 print("Warning: Could not register store category. Basedirectory not defined!")
147 return false
148 end
149
150 name = name:upper()
151
152 if self.categories[name] == nil then
153 self.numOfCategories = self.numOfCategories + 1
154
155 local category = {}
156 category.name = name
157 category.title = title
158 category.image = Utils.getFilename(imageFilename, baseDir)
159 category.type = StoreManager.CATEGORY_TYPE[type] ~= nil and type or StoreManager.CATEGORY_TYPE.NONE
160 category.orderId = self.numOfCategories
161
162 self.categories[name] = category
163 return true
164 end
165 return false
166end

removeCategory

Description
Removes a store category
Definition
removeCategory(string name)
Arguments
stringnamecategory index name
Code
171function StoreManager:removeCategory(name)
172 if not ClassUtil.getIsValidIndexName(name) then
173 print("Warning: '"..tostring(name).."' is no valid name for a category!")
174 return
175 end
176
177 name = name:upper()
178
179 for _, item in pairs(self.items) do
180 if item.category == name then
181 item.category = "MISC"
182 end
183 end
184 self.categories[name] = nil
185end

getCategoryByName

Description
Gets a store category by name
Definition
getCategoryByName(string name)
Arguments
stringnamecategory index name
Return Values
tablecategorythe category object
Code
191function StoreManager:getCategoryByName(name)
192 if name ~= nil then
193 return self.categories[name:upper()]
194 end
195 return nil
196end

addSpecType

Description
Adds a new spec type
Definition
addSpecType(string name, string profile, function loadFunc, function getValueFunc)
Arguments
stringnamespec type index name
stringprofilespec type gui profile
functionloadFuncthe loading function pointer
functiongetValueFuncthe get value function pointer
Code
204function StoreManager:addSpecType(name, profile, loadFunc, getValueFunc)
205 if not ClassUtil.getIsValidIndexName(name) then
206 print("Warning: '"..tostring(name).."' is no valid name for a spec type!")
207 return
208 end
209
210 name = name
211
212 if self.nameToSpecType == nil then
213 printCallstack()
214 end
215
216 if self.nameToSpecType[name] ~= nil then
217 print("Error: spec type name '" ..name.. "' is already in use!")
218 return
219 end
220
221 local specType = {}
222 specType.name = name
223 specType.profile = profile
224 specType.loadFunc = loadFunc
225 specType.getValueFunc = getValueFunc
226
227 self.nameToSpecType[name] = specType
228 table.insert(self.specTypes, specType)
229end

getSpecTypes

Description
Gets all spec types
Definition
getSpecTypes()
Return Values
tablespecTypesa list of spec types
Code
234function StoreManager:getSpecTypes()
235 return self.specTypes
236end

getSpecTypeByName

Description
Gets a spec type by name
Definition
getSpecTypeByName(string name)
Arguments
stringnamespec type index name
Return Values
tablespecTypethe corresponding spectype
Code
242function StoreManager:getSpecTypeByName(name)
243 if not ClassUtil.getIsValidIndexName(name) then
244 print("Warning: '"..tostring(name).."' is no valid name for a spec type!")
245 return
246 end
247
248 return self.nameToSpecType[name]
249end

addItem

Description
Adds a new store item
Definition
addItem(table storeItem)
Arguments
tablestoreItemthe storeitem object
Return Values
booleanwasSuccessfulltrue if added else false
Code
255function StoreManager:addItem(storeItem)
256 if self.xmlFilenameToItem[storeItem.xmlFilenameLower] ~= nil then
257 return false
258 end
259
260 table.insert(self.items, storeItem)
261 storeItem.id = #self.items
262 self.xmlFilenameToItem[storeItem.xmlFilenameLower] = storeItem
263 return true
264end

removeItemByIndex

Description
Removes a storeitem by index
Definition
removeItemByIndex(integer index)
Arguments
integerindexstoreitem index
Code
269function StoreManager:removeItemByIndex(index)
270 local item = self.items[index]
271 if item ~= nil then
272 self.xmlFilenameToItem[item.xmlFilenameLower] = nil
273
274 -- item.id must always match the index in the arry, thus swap the last to the removed position and reduce size
275 local numItems = table.getn(self.items)
276 if index < numItems then
277 self.items[index] = self.items[numItems]
278 self.items[index].id = index
279 end
280 table.remove(self.items, numItems)
281 end
282end

getItems

Description
Gets all storeitems
Definition
getItems()
Return Values
tableitemsa list of all store items
Code
287function StoreManager:getItems()
288 return self.items
289end

getItemByIndex

Description
Gets a store item by index
Definition
getItemByIndex(integer index)
Arguments
integerindexstore item index
Return Values
tablestoreItemthe storeitem oject
Code
295function StoreManager:getItemByIndex(index)
296 if index ~= nil then
297 return self.items[index]
298 end
299 return nil
300end

getItemByXMLFilename

Description
Gets a store item xml filename
Definition
getItemByXMLFilename(string xmlFilename)
Arguments
stringxmlFilenamestoreitem xml filename
Return Values
tablestoreItemthe storeitem object
Code
306function StoreManager:getItemByXMLFilename(xmlFilename)
307 if xmlFilename ~= nil then
308 return self.xmlFilenameToItem[xmlFilename:lower()]
309 end
310end

getItemByCustomEnvironment

Description
Gets a store item xml filename
Definition
getItemByCustomEnvironment(string xmlFilename)
Arguments
stringxmlFilenamestoreitem xml filename
Return Values
tablestoreItemthe storeitem object
Code
316function StoreManager:getItemByCustomEnvironment(customEnvironment)
317 local items = {}
318 for _, item in ipairs(self.items) do
319 if item.customEnvironment == customEnvironment then
320 table.insert(items, item)
321 end
322 end
323
324 return items
325end

loadItem

Description
Loads a storeitem from xml file
Definition
loadItem(string xmlFilename, string baseDir, string customEnvironment, boolean isMod, boolean isBundleItem, string dlcTitle)
Arguments
stringxmlFilenamethe storeitem xml filename
stringbaseDirthe base directory
stringcustomEnvironmenta custom environment
booleanisModtrue if item is a mod, else false
booleanisBundleItemtrue if item is bundleItem, else false
stringdlcTitleoptional dlc title
Return Values
tablestoreItemthe storeitem object
Code
340function StoreManager:loadItem(xmlFilename, baseDir, customEnvironment, isMod, isBundleItem, dlcTitle)
341 local xmlFilename = Utils.getFilename(xmlFilename, baseDir)
342 local xmlFile = loadXMLFile("storeItemXML", xmlFilename)
343 local baseXMLName = getXMLRootName(xmlFile)
344 local storeDataXMLName = baseXMLName..".storeData"
345
346 if not hasXMLProperty(xmlFile, storeDataXMLName) then
347 g_logManager:xmlError(xmlFilename, "No storeData found. StoreItem will be ignored!")
348 delete(xmlFile)
349 return nil
350 end
351
352 local isValid = true
353 local name = XMLUtil.getXMLI18NValue(xmlFile, storeDataXMLName, getXMLString, "name", nil, customEnvironment, true)
354 if name == nil then
355 g_logManager:xmlWarning(xmlFilename, "Name missing for storeitem. Ignoring store item!")
356 isValid = false
357 end
358
359 local imageFilename = Utils.getNoNil(getXMLString(xmlFile, storeDataXMLName..".image"), "")
360 if imageFilename == "" then
361 g_logManager:xmlWarning(xmlFilename, "Image icon is missing for storeitem. Ignoring store item!")
362 isValid = false
363 end
364
365 if not isValid then
366 delete(xmlFile)
367 return nil
368 end
369
370 local storeItem = {}
371 storeItem.name = name
372 storeItem.xmlFilename = xmlFilename
373 storeItem.xmlFilenameLower = xmlFilename:lower()
374 storeItem.imageFilename = Utils.getFilename(imageFilename, baseDir)
375 storeItem.functions = StoreItemUtil.getFunctionsFromXML(xmlFile, storeDataXMLName, customEnvironment)
376 storeItem.specs = StoreItemUtil.getSpecsFromXML(self.specTypes, xmlFile, customEnvironment)
377 storeItem.brandIndex = StoreItemUtil.getBrandIndexFromXML(xmlFile, storeDataXMLName, xmlFilename)
378 storeItem.species = Utils.getNoNil(getXMLString(xmlFile, storeDataXMLName..".species"), "")
379 storeItem.canBeSold = Utils.getNoNil(getXMLBool(xmlFile, storeDataXMLName..".canBeSold"), true)
380 storeItem.showInStore = Utils.getNoNil(getXMLBool(xmlFile, storeDataXMLName..".showInStore"), not isBundleItem)
381 storeItem.isBundleItem = isBundleItem
382 storeItem.allowLeasing = Utils.getNoNil(getXMLBool(xmlFile, storeDataXMLName..".allowLeasing"), true)
383 storeItem.maxItemCount = getXMLInt(xmlFile, storeDataXMLName..".maxItemCount")
384 storeItem.rotation = Utils.getNoNilRad(getXMLFloat(xmlFile, storeDataXMLName..".rotation"), 0)
385 storeItem.shopTranslationOffset = StringUtil.getVectorNFromString(getXMLString(xmlFile, storeDataXMLName..".shopTranslationOffset"), 3)
386 storeItem.shopRotationOffset = StringUtil.getRadiansFromString(getXMLString(xmlFile, storeDataXMLName..".shopRotationOffset"), 3)
387 storeItem.shopHeight = Utils.getNoNil(getXMLFloat(xmlFile, storeDataXMLName..".shopHeight"), 0)
388 storeItem.shopFoldingState = Utils.getNoNil(getXMLBool(xmlFile, storeDataXMLName..".shopFoldingState"), 0)
389 storeItem.sharedVramUsage, storeItem.perInstanceVramUsage, storeItem.ignoreVramUsage = StoreItemUtil.getVRamUsageFromXML(xmlFile, storeDataXMLName)
390 storeItem.dlcTitle = dlcTitle
391 storeItem.isMod = isMod
392 storeItem.customEnvironment = customEnvironment
393
394 local categoryName = getXMLString(xmlFile, storeDataXMLName..".category")
395 local category = self:getCategoryByName(categoryName)
396 if category == nil then
397 g_logManager:xmlWarning(xmlFilename, "Invalid category '%s' in store data! Using 'misc' instead!", tostring(categoryName))
398 category = self:getCategoryByName("misc")
399 end
400 storeItem.categoryName = category.name
401
402 storeItem.configurations = StoreItemUtil.getConfigurationsFromXML(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, storeItem)
403 storeItem.subConfigurations = StoreItemUtil.getSubConfigurationsFromXML(storeItem.configurations)
404 storeItem.configurationSets = StoreItemUtil.getConfigurationSetsFromXML(storeItem, xmlFile, baseXMLName, baseDir, customEnvironment, isMod)
405 storeItem.price = Utils.getNoNil(getXMLFloat(xmlFile, storeDataXMLName..".price"), 0)
406 if storeItem.price < 0 then
407 g_logManager:xmlWarning(xmlFilename, "Price has to be greater than 0. Using default 10.000 instead!")
408 storeItem.price = 10000
409 end
410 storeItem.dailyUpkeep = Utils.getNoNil(getXMLFloat(xmlFile, storeDataXMLName..".dailyUpkeep"), 0)
411 storeItem.runningLeasingFactor = Utils.getNoNil(getXMLFloat(xmlFile, storeDataXMLName..".runningLeasingFactor"), EconomyManager.DEFAULT_RUNNING_LEASING_FACTOR)
412 storeItem.lifetime = Utils.getNoNil(getXMLFloat(xmlFile, storeDataXMLName..".lifetime"), 600)
413
414
415 if hasXMLProperty(xmlFile, storeDataXMLName..".bundleElements") then
416 local bundleInfo = {bundleItems={}, attacherInfo={}}
417 local price = 0
418 local lifetime = math.huge
419 local dailyUpkeep = 0
420 local runningLeasingFactor = 0
421 local i = 0
422 while true do
423 local bundleKey = string.format(storeDataXMLName..".bundleElements.bundleElement(%d)", i)
424 if not hasXMLProperty(xmlFile, bundleKey) then
425 break
426 end
427 local bundleXmlFile = getXMLString(xmlFile, bundleKey..".xmlFilename")
428 local offset = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, bundleKey..".offset"), "0 0 0"), 3)
429 local rotation = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, bundleKey..".yRotation"), 0))
430 if bundleXmlFile ~= nil then
431 local completePath = Utils.getFilename(bundleXmlFile, baseDir)
432 local item = self:getItemByXMLFilename(completePath)
433 if item == nil then
434 item = self:loadItem(bundleXmlFile, baseDir, customEnvironment, isMod, true, dlcTitle)
435 end
436 if item ~= nil then
437 price = price + item.price
438 dailyUpkeep = dailyUpkeep + item.dailyUpkeep
439 runningLeasingFactor = runningLeasingFactor + item.runningLeasingFactor
440 lifetime = math.min(lifetime, item.lifetime)
441 table.insert(bundleInfo.bundleItems, {item=item, xmlFilename=item.xmlFilename, offset=offset, rotation=rotation, price=item.price})
442 end
443 end
444 i = i + 1
445 end
446 local i = 0
447 while true do
448 local attachKey = string.format(storeDataXMLName..".attacherInfo.attach(%d)", i)
449 if not hasXMLProperty(xmlFile, attachKey) then
450 break
451 end
452 local bundleElement0 = getXMLInt(xmlFile, attachKey.."#bundleElement0")
453 local bundleElement1 = getXMLInt(xmlFile, attachKey.."#bundleElement1")
454 local attacherJointIndex = getXMLInt(xmlFile, attachKey.."#attacherJointIndex")
455 local inputAttacherJointIndex = getXMLInt(xmlFile, attachKey.."#inputAttacherJointIndex")
456 if bundleElement0 ~= nil and bundleElement1 ~= nil and attacherJointIndex ~= nil and inputAttacherJointIndex ~= nil then
457 table.insert(bundleInfo.attacherInfo, {bundleElement0=bundleElement0, bundleElement1=bundleElement1, attacherJointIndex=attacherJointIndex, inputAttacherJointIndex=inputAttacherJointIndex})
458 end
459 i = i + 1
460 end
461
462 storeItem.price = price
463 storeItem.dailyUpkeep = dailyUpkeep
464 storeItem.runningLeasingFactor = runningLeasingFactor
465 storeItem.lifetime = lifetime
466 storeItem.bundleInfo = bundleInfo
467 end
468
469 self:addItem(storeItem)
470
471 delete(xmlFile)
472
473 return storeItem
474end

TableElement

Description
Table GUI element.
-- Allows sorting by columns when clicking on header elements. Header elements should ideally be defined just before
the table itself, but never within the table.
--@category GUI
--@xmlConfig GuiElement#rowTemplateName string Element Name of row template. The template will be replicated to fill the table's view and then discarded during initialization.

onGuiSetupFinished

Description
Called when the GUI is completely loaded. Link relevant collaborators of this table.
Definition
onGuiSetupFinished()

buildTableRows

Description
Build table row GUI elements.
First look for the row template, then replicate it as many times as configured (#itemsPerCol attribute)
Definition
buildTableRows()

processCellElements

Description
Process cell elements for cell-based navigation.
Definition
processCellElements()

applyAlternatingBackgroundsToRows

Description
Apply alternating background GUI profiles to rows if the required profiles have been specified (see configuration
properties).
Definition
applyAlternatingBackgroundsToRows()

addRow

Description
Add a data row to the end of this table.
Definition
addRow(dataRow DataRow, refreshView boolean)
Arguments
dataRowDataRowwhich holds an ID and column values as DataCell instances
refreshViewbooleanIf true, triggers a refresh of the table's view.

removeRow

Description
Remove a row from this table.
Definition
removeRow(index Index, refreshView boolean)
Arguments
indexIndexof row to be removed.
refreshViewbooleanIf true, triggers a refresh of the table's view.

clearData

Description
Clear all data from the table.
Definition
clearData(refreshView boolean)
Arguments
refreshViewbooleanIf true, triggers a refresh of the table's view.

getViewDataCell

Description
Get a cell identified by row index and column name from this table's current view data.
Definition
getViewDataCell(rowIndex Index, colName string)
Arguments
rowIndexIndexof row in view
colNamestringName of data column
Return Values
DataCellornil if not found.

getDataCell

Description
Get a cell identified by row index and column name from this table's data.
Definition
getDataCell(rowIndex Index, colName string)
Arguments
rowIndexIndexof row in data
colNamestringName of data column
Return Values
DataCellornil if not found.

setCellText

Description
Set the text of a specific cell.
If the cell element does not have a setText() method, this method has no effect. Make sure to only target TextElement
descendants.
Definition
setCellText(rowIndex Index, colName string, text string, refreshView boolean)
Arguments
rowIndexIndexof row in data
colNamestringName of data column
textstringNew text value
refreshViewbooleanIf true, triggers a refresh of the table's view. Use this when changing sortable column data.

setCellVisibility

Description
Set visibility of a specific cell.
Definition
setCellVisibility(rowIndex Index, colName string, isVisible boolean)
Arguments
rowIndexIndexof row in data
colNamestringName of data column
isVisiblebooleanNew visibility value of the cell element

setCellOverrideGuiProfile

Description
Apply a temporary overriding GUI profile to a specific cell.
GUI profiles are defined in dataS/guiProfiles.xml. If this is called without a profile name argument, the original
profile is applied on the next table refresh.
Definition
setCellOverrideGuiProfile(rowIndex Index, colName string, profileName string)
Arguments
rowIndexIndexof row in data
colNamestringName of data column
profileNamestringName of GUI profile to override or nil to reset.

disableSorting

Description
Disables all sorting, does not restore item order.
Definition
disableSorting()

deleteListItems

Description
Delete all list items.
Override from ListElement: Clears all data and updates the view.
Definition
deleteListItems()

onClickHeader

Description
Handle clicks on a header element for sorting.
This must be called by the containing screen on callback. The view update needs to be triggered separately.
Definition
onClickHeader(headerElement The)
Arguments
headerElementTheheader which has been clicked.

getSortableColumn

Description
Get a columns data in SortCell instances to apply sorting.
Definition
getSortableColumn(columnName Name)
Arguments
columnNameNameof the data column, must be configured in #columnNames
Return Values
ListofSortCell for the requested column name

setCustomSortFunction

Description
Set a custom sorting function to expand on the default data sorting function.
Definition
setCustomSortFunction(sortFunction Sorting, useBeforeData If)
Arguments
sortFunctionSortingfunction which takes two SortCell instances to compare and returns a numeric
value; value < 0 : e1 < e2, value == 0 : e1 == e2, value > 0 : e1 > e2
useBeforeDataIftrue, the custom function will be the first order function. Otherwise, elements will be
ordered by data first and custom sorting second.

setProfileOverrideFilterFunction

Description
Set a filter function for the application of GUI profile overrides.
Definition
setProfileOverrideFilterFunction(filterFunction Must)
Arguments
filterFunctionMusttake a DataRow instance and return true if the override profile should be applied or false
otherwise.

getSortFunction

Description
Get the table sorting function. If a custom sorting function has been set, the standard data cell sorting will be
decorated by it. When setting a custom sorting function, another parameter is given which determines if the custom
function should be the first or second criterion in sorting.
Definition
getSortFunction(isAscending True)
Arguments
isAscendingTrueif data should be sorted in ascending order, false if descending

updateSortedView

Description
Updates the sorted data view with the required sorting order
Definition
updateSortedView(columnName Name, sortingOrder TableHeaderElement.SORTING_X)
Arguments
columnNameNameof the column by which rows will be sorted or nil to revert to unsorted state
sortingOrderTableHeaderElement.SORTING_Xvalue for sort order

invalidateLayout

Description
Rebuild the table layout.
This will reposition all row elements and fade them out. If they receive data, they are made visible again.
Definition
invalidateLayout()

updateSelectedIndex

Description
Update the selected index after view / data changes.
The method tries getting the new selected index by matching data row IDs.
Definition
updateSelectedIndex()

updateRows

Description
Apply data and attributes from visible items to row elements.
Definition
updateRows()

scrollToItemInView

Description
Scrolls to an item so that it naturally comes into view.
If the target index is above, this will set the item at the top. Likewise, if the index is below the current view,
the item will be shown at the bottom.
Definition
scrollToItemInView(index Target)
Arguments
indexTargetindex to scroll to

updateView

Description
Update the table's view. Use this for external updates after data changes.
Fills in data into row elements according to current data and sorting order.
Definition
updateView(refocus If)
Arguments
refocusIftrue, the view will be scrolled to the currently selected item after the update.

getItemIndexByRealRowColumn

Description
Get item index from a row selection.
Override from ListElement: only handles rows.
Definition
getItemIndexByRealRowColumn(realRow Row)
Arguments
realRowRowdata selection index

setSelectionByRealRowAndColumn

Description
Set selection based on list row and column.
Override from ListElement: reads data index from selected table row to select it.
Definition
setSelectionByRealRowAndColumn(realRow Row)
Arguments
realRowRowselection index

updateRowSelection

Description
Update selection state of table rows
Definition
updateRowSelection()
Return Values
indexofselected row

getItemFactor

Description
Get an item factor for visual proportions.
Override from ListElement: Simplified table interaction with slider element to require straight indices only.
Therefore this only needs to return 1 now.
Definition
getItemFactor()
Return Values

scrollTo

Description
Scroll to a data view index position.
Definition
scrollTo(index Data, updateSlider If)
Arguments
indexDataindex. The view will update to show the indexed data item at the top.
updateSliderIftrue, will update the slider position if present

setSelectedIndex

Description
Set the selected index in table data view.
Scrolls to the newly selected row index if necessary.
Definition
setSelectedIndex(index Numeric, force If)
Arguments
indexNumericindex in table data view
forceIftrue, always forces a selection changed callback, even if the index remains the same

getSelectedElement

Description
Get the selected element.
Override from ListElement: Instead of returning raw GuiElement instances, this will provide the selected DataRow.
Definition
getSelectedElement()
Return Values
dataRowinstanceor nil, selected data index or 0

getSelectedTableRow

Description
Get the currently selected, visible TableRow instance.
Definition
getSelectedTableRow()

getDataRowForElement

Description
Get the data row which corresponds to the visual position of a given element.
This is useful for cases when getSelectedElement() does not currently represent a valid state, e.g. in click
callbacks of buttons contained in table rows (called before the table's mouse event).
Definition
getDataRowForElement(element GuiElement)
Arguments
elementGuiElementinstance which should be part of this table's row elements
Return Values
dataRowinstanceor nil (element not part of table row)

getItemCount

Description
Get the number of data view rows.
Override from ListElement.
Definition
getItemCount()
Return Values
numberofdata view rows

updateItemPositions

Description
Update item and data indices of rows.
Definition
updateItemPositions()

shouldFocusChange

Description
Determine if focus should change from this element in a given direction.
Override from ListElement: Change focus when moving out to the side or selection is at the start/end of the table.
Definition
shouldFocusChange(direction Focus)
Arguments
directionFocusnavigation direction

onFocusEnter

Description
Handle receiving focus event
Definition
onFocusEnter()

getFocusTarget

Description

Get the actual focus target, in case a child or parent element needs to be targeted instead.
Definition
getFocusTarget(incomingDirection (Optional), moveDirection (Optional))
Arguments
incomingDirection(Optional)If specified, may return different targets for different incoming directions.
moveDirection(Optional)Actual movement direction per input. This is the opposing direction of incomingDirection.
Return Values
GuiElementActualelement to focus.

onMouseUp

Description
Handle mouse button up (after down) event
Override from ListElement: also update visual selection status of table row elements.
Definition
onMouseUp()

inputEvent

Description
Handle navigation input on this table.
Definition
inputEvent()

delayNavigationInput

Description
Lock and delay up and down directions for focus navigation.
Definition
delayNavigationInput()

TableHeaderElement

Description
Table header element to use within tables.
-- Children which serve as sorting icons are to be marked in the screen XML configuration by setting the name attribute
to "iconAscending" or "iconDescending" depending on which sorting state they are intended to represent. Headers must
be defined outside of tables, because anything within a table is considered a table item.
--@category GUI
--@xmlConfig GuiElement#targetTableId string Configured ID of the decorated table

addElement

Description
Add a child element to this GUI element. This element searches for marked children to use as sorting icons.
Definition
addElement(element Element)
Arguments
elementElementto add.

toggleSorting

Description
Toggle this header's sorting display state, if allowed.
Definition
toggleSorting()
Return Values
Thenewsorting order

disableSorting

Description
Disable sorting on this header by setting its sorting state to OFF.
Definition
disableSorting()

updateSortingDisplay

Description
Update the header's display with its new state.
Definition
updateSortingDisplay()

TerrainDeformation

Description
Terrain deformation.
-- This class wraps terrain deformation engine functions for convenient usage.
--@category Terrain

new

Description
Create a new terrain deformation object.
Take care to call "apply" on each such object to ensure proper handling and clean-up on the engine side.
Definition
new(terrainNode Terrain)
Arguments
terrainNodeTerrainroot node, typically retrieved from "currentMission.terrainRootNode" or similar.

addArea

Description
Add a parallelogram area.
Terrain will be modified to fit to this area and receive the provided material. Several areas can be added per
deformation process.
Definition
addArea(x Parallelogram, y Parallelogram, Z Parallelogram, side1X Parallelogram, side1Y Parallelogram, side1Z Parallelogram, side2X Parallelogram, side2Y Parallelogram, side2Z Parallelogram, terrainBrushId Terrain)
Arguments
xParallelogramorigin X position in world space
yParallelogramorigin Y position in world space
ZParallelogramorigin Z position in world space
side1XParallelogramside 1 X position offset relative to origin
side1YParallelogramside 1 Y position offset relative to origin
side1ZParallelogramside 1 Z position offset relative to origin
side2XParallelogramside 2 X position offset relative to origin
side2YParallelogramside 2 Y position offset relative to origin
side2ZParallelogramside 2 Z position offset relative to origin
terrainBrushIdTerrainmaterial ID, currently just the map layer index to apply

setOutsideAreaBrush

Description
Set terrain material for areas outside of the given parallelograms but within the smoothing radius.
Definition
setOutsideAreaBrush(brushId Terrain)
Arguments
brushIdTerrainmaterial ID, currently just the map layer index to apply

setOutsideAreaConstraints

Description
Set the constraints for smoothing the area outside the added parallelogram areas.
Definition
setOutsideAreaConstraints(maxSmoothDistance Radius, maxSlope Maximum, maxEdgeAngle Maximum)
Arguments
maxSmoothDistanceRadiusaround parallelogram areas to apply smoothing
maxSlopeMaximumallowed slope of terrain created by smoothing in radians
maxEdgeAngleMaximumallowed angle between individual polygons in the smoothed terrain in radians, this allows reducing the rate of change of the slope

getBlockedAreaMapSize

Description
Get the size of the area map needed for the terrain
Definition
getBlockedAreaMapSize()

setDynamicObjectCollisionMask

Description
Set the collision mask used to detect dynamic objects that are in the way of the deformation
Definition
setDynamicObjectCollisionMask()

setDynamicObjectMaxDisplacement

Description
Set the max displacement allowed for dynamic objects
Definition
setDynamicObjectMaxDisplacement()

setBlockedAreaMap

Description
Set an area map of terrain which must not be modified.
When a "1" appears in the channel for a terrain cell, the terrain remains unmodified at that point. Smoothing occurs
around the blocked areas as well as around the parallelogram areas.
Definition
setBlockedAreaMap(bitVectorMapId ID, channel Bit)
Arguments
bitVectorMapIdIDof a bit vector map which needs to have the size as returned by getBlockedAreaMapSize()
channelBitindex of the channel within the bit vector map to test for blocking information

setBlockedAreaMaxDisplacement

Description
Set the max displacement allowed for the blocked area before a blocked failure occurs
Definition
setBlockedAreaMaxDisplacement()

apply

Description
Apply the terrain deformation.
Definition
apply(previewOnly If, callbackFunc Name, callbackObject Object)
Arguments
previewOnlyIftrue, will only return callback data without committing changes to the terrain. Otherwise, the
modification will be applied directly, if possible.
callbackFuncNameof a callback function which is called when calculation is finished. Signature: function(callbackObject, canDeform, displacedVolume, blocked)
callbackObjectObjectwhich holds callbackFunc and first argument to callback if set. If no callbackObject is provided, the callback function is assumed to be global and will be called as such.

cancel

Description
Cancel an ongoing terrain deformation process.
This will cancel calculations after apply() has been called and before the callback. Otherwise it has no effect.
Definition
cancel()

TextElement

Description
Text display element
--@category GUI
--@xmlConfig GuiElement#textColor string [optional] Normal state text color, defaults to white [1, 1, 1, 1]. Format: "[r] [g] [b] [a]" where each value is in the range of [0.0, 1.0]. The first three values represent red, green and blue color channels and the last is the alpha (translucency) value. When setting this property in guiProfiles.xml, preset values as defined at the top of that file may also be used.

getTextPosition

Description
Get the text position for drawing for the current alignment settings and including modifications to text.
Definition
getTextPosition()

TextInputDialog

Description
Text input dialog.
-- @field textElement Text input element

new

Description
Create a new TextInputDialog instance.
Definition
new()

TextInputElement

Description
Text input element which captures strings from player input.
-- Used layers: "cursor" for a text input cursor icon.
-- TODO: IME property docs
--@category GUI
--@xmlConfig GuiElement#imeKeyboardType string [optional] Input method editor keyboard type, defaults to "normal". TODO: add valid types based on engine code

setCaptureInput

Description
Set input capturing state.
When capturing, the standard input bindings are disabled (input context switch).
Definition
setCaptureInput()

inputEvent

Description
Handle GUI input events.
Reacts to confirmation and cancel actions. Also see GuiElement.inputEvent().
Definition
inputEvent()

ToggleButtonElement

Description
Toggle button
-- TODO: Refactor child display element retrieval
-- Used layers: "image" for the background.
--@category GUI
--@xmlConfig GuiElement#isChecked bool [optional] If true, the button is initialized in checked state.
--@xmlConfig GuiElement#onClick callback [optional] onClick(element, isChecked) Called when the element is clicked. Receives this element and the current toggle state as a boolean (true for checked, false for unchecked).

getFocusTarget

Description
Get the actual focus target of this element.
Definition
getFocusTarget()

TopNotification

Description
HUD top notification element.
-- Displays notifications issued by other game components at the top of the screen.
--@category GUI

new

Description
Create a new TopNotification.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD atlas texture.
Return Values
tablevaluevalue at the given position
tableTopNotificationinstance

setNotification

Description
Set a notification to be displayed in a frame at the top of the screen.
If another notification is being displayed, it is immediately replaced by this new one.
Definition
setNotification(string title, string text, string info, table iconKey, int duration)
Arguments
stringtitleNotification title
stringtextNotification message text
stringinfoAdditional info text
tableiconKey[optional] Icon key for a display icon, use a value from TopNotification.ICON
intduration[optional] Display duration in milliseconds. Negative values or nil default to a long-ish standard duration.
Return Values
tableinstanceinstance of object

getHidingTranslation

Description
Get the screen space translation for hiding.
Override in sub-classes if a different translation is required.
Definition
getHidingTranslation()
Return Values
tablevaluevalue at the given position
floatScreenspace X translation
floatScreenspace Y translation

update

Description
Update notification state.
Definition
update()
Return Values
integerrowrow
integercolumncolumn

draw

Description
Draw notification.
Definition
draw()

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor
Return Values
tableinstanceinstance of object

setScale

Description
Set uniform UI scale.
Definition
setScale()
Return Values
tableinstanceinstance of object

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Return Values
booleantrueif loading was successful else false

createBackground

Description
Create the background overlay.
Definition
createBackground()
Return Values
booleancanTipcan tip to ground

createComponents

Description
Create required display components.
Definition
createComponents()
Return Values
integerfillTypefill type found

Tween

Description
Tween class which linearly interpolates a quantity from a start value to an end value over a given duration.
--@category GUI

new

Description
Create a new Tween.
Definition
new(table subClass, function setterFunction, float startValue, float endValue, float duration)
Arguments
tablesubClassSubclass metatable for inheritance
functionsetterFunctionValue setter function. Signature: callback(value) or callback(target, value).
floatstartValueOriginal value
floatendValueTarget value
floatdurationDuration of tween in milliseconds

getDuration

Description
Get this tween's duration in milliseconds.
Definition
getDuration()

getFinished

Description
Check if this tween has finished.
Definition
getFinished()

reset

Description
Reset this tween to play it again.
Definition
reset()

setTarget

Description
Set a callback target for this tween.
If a target has been set, the setter function must support receiving the target as its first argument.
Definition
setTarget()

update

Description
Update the tween's state.
Definition
update()

tweenValue

Description
Get the current tween value.
Definition
tweenValue()

applyValue

Description
Apply a value via the setter function.
Definition
applyValue()

TweenSequence

Description
Tween sequence.
-- Allows setting up more complex tweening by defining sequences of tweens, intervals and callbacks. A sequence is
itself a Tween, so you may even define and add sub-sequences.
-- Before a sequence reacts to update() calls, it must be started with start(). This also applies after resetting.
-- Adding tweens, callbacks and intervals will append them to the current sequence. Insertion of tweens and callbacks
will insert them at the given relative instants, allowing for overlapping tweens and arbitrary callback times.
Inserting an interval will push pack all later instants by the given time.
--@category GUI

new

Description
Create a new TweenSequence.
Definition
new(table functionTarget)
Arguments
tablefunctionTarget[optional] Target table which is supplied by default to all tween setter functions and
callbacks as the first argument. If not specified, the setters and callbacks will be called with one value only.

insertTween

Description
Insert a tween at a given instant.
Definition
insertTween(table tween, float instant)
Arguments
tabletweenTween instance
floatinstantTime in milliseconds after sequence start

addTween

Description
Add a tween to the end of the sequence.
Definition
addTween(table tween)
Arguments
tabletweenTween instance

insertInterval

Description
Insert an interval at the given instant.
This will push back all later instants by the interval. Use this to insert pauses into the sequence.
Definition
insertInterval(float interval, float instant)
Arguments
floatintervalInterval time in milliseconds
floatinstantTime in milliseconds after sequence start

addInterval

Description
Add an interval at the end of the sequence.
Use this to add a pause to the sequence.
Definition
addInterval()

insertCallback

Description
Insert a callback at the given instant.
Definition
insertCallback(function callback, table callbackState, float instant)
Arguments
functioncallbackCallback function with signature of either callback(target, value) or callback(value)
tablecallbackStateAny value which is passed to the callback as its first (no target) or second (with target) argument
floatinstantTime in milliseconds after sequence start

addCallback

Description
Add a callback at the end of the sequence.
Definition
addCallback(function callback, table callbackState)
Arguments
functioncallbackCallback function with signature of either callback(target, value) or callback(value)
tablecallbackStateAny value which is passed to the callback as its first (no target) or second (with target) argument

getDuration

Description
Get this tween's duration in milliseconds.
Definition
getDuration()

setTarget

Description
Set a callback target for this tween.
If a target has been set, the setter function must support receiving the target as its first argument.
Definition
setTarget()

setLooping

Description
Set the looping state for this sequence.
Definition
setLooping(bool isLooping)
Arguments
boolisLoopingIf true, will restart the sequence when finished, including callbacks!

start

Description
Start the sequence.
A sequence will only update its state when it has been started.
Definition
start()

stop

Description
Stop the sequence.
Definition
stop()

reset

Description
Reset the sequence to its initial state.
Definition
reset()

update

Description
Update the sequence state over time.
Definition
update()

updateTweens

Description
Update active sequence tweens.
Definition
updateTweens(float lastInstant, float dt)
Arguments
floatlastInstantLast instant which received an update
floatdtDelta time

updateCallbacks

Description
Update callback states.
Definition
updateCallbacks()

UnBanDialog

Description
Un-ban dialog.
-- Displays a list of banned users to allow administrators to lift their bans.
-- @field dialogElement Main dialog frame GUI element which holds other elements

new

Description
Create a new UnBanDialog instance.
Definition
new()

rebuildBanList

Description
(Re-)Builds the ban list from ban storage data.
Definition
rebuildBanList()

updateButtons

Description
Update unban buttons visibility.
Definition
updateButtons()

setCallback

Description
Set the function which is called when this dialog returns.
Definition
setCallback()

closeAndCallback

Description
Close and call the notification callback.
Definition
closeAndCallback()

onListSelectionChanged

Description
Handle changes in the ban list selection.
Definition
onListSelectionChanged()

onClickBack

Description
Handle activation of the back button event.
Definition
onClickBack()

onClickCancel

Description
Handle activation of the cancel button event which unbans a single player.
Definition
onClickCancel()

onClickActivate

Description
Handle activation of the activate button event which unbans all users.
Definition
onClickActivate()

VehicleHUDExtension

Description
Custom vehicle HUD drawing extension.
-- This serves as the base class for custom specific drawing cases of vehicles in the HUD, e.g. MixerWagon fill levels.
-- To create new HUD extensions for vehicle specializations:
1. sub-class this base class
2. source() the sub-class module after its corresponding specialization's table has been declared
3. call VehicleHUDExtension.registerHUDExtension([specialization], [HUDextension]) in sub-class module
--@category GUI

new

Description
Base constructor for vehicle HUD extensions.
Definition
new(table class_mt, table vehicle, float uiScale, table uiTextColor, float uiTextSize)
Arguments
tableclass_mtSub-class metatable
tablevehicleVehicle which has the specialization required by a sub-class
floatuiScaleCurrent UI scale
tableuiTextColorHUD text drawing color as an RGBA array
floatuiTextSizeHUD text size
Return Values
floatfillLevelfill level found

delete

Description
Delete this instance and clean up resources.
Definition
delete()
Return Values
floatdensityHeightdensity height
floatdeltaDensityHeightdelta of density height to terrain underneath

addComponentForCleanup

Description
Add a display component for cleanup on delete().
Added components must support delete() themselves or they will be ignored.
Definition
addComponentForCleanup()

getDisplayHeight

Description
Get this HUD extension's display height.
Override in subclasses.
Definition
getDisplayHeight()
Return Values
floatphysicsDensityHeightdensity height
floatdeltaPhysicsDensityHeightdelta of physics collision to terrain underneath

canDraw

Description
Determine if this HUD extension is in a valid state for a call to draw() in the current frame.
Override in sub-classes with custom logic.
Definition
canDraw()
Return Values
boolIftrue, the HUD extension should be drawn in the current frame.

draw

Description
Draw HUD extension.
Definition
draw(float leftPosX, float rightPosX, float posY)
Arguments
floatleftPosXLeft input help panel column start position
floatrightPosXRight input help panel column start position
floatposYCurrent input help panel drawing vertical offset
Return Values
floatdroppedreal fill level dropped
floatlineOffsetline offset
floatModifiedinput help panel drawing vertical offset

registerHUDExtension

Description
Register a HUD extension for a specialization.
Definition
registerHUDExtension(table specializationType, table hudExtensionType)
Arguments
tablespecializationTypeVehicle specialization class type table
tablehudExtensionTypeHUD extension class type table corresponding to the given vehicle specialization

createHUDExtensionForSpecialization

Description
HUD extension factory method, creates a HUD extension for a given vehicle specialization.
Definition
createHUDExtensionForSpecialization(table spec, table vehicle, float uiScale, table uiTextColor, float uiTextSize)
Arguments
tablespecSpecialization reference
tablevehicleVehicle which has the given specialization
floatuiScaleCurrent UI scale
tableuiTextColorHUD text drawing color as an RGBA array
floatuiTextSizeHUD text size
Return Values
floatdroppedreal fill level dropped
floatlineOffsetline offset
tableHUDextension instance or nil of no extension has been registered for the given specialization

hasHUDExtensionForSpecialization

Description
Check if there is a HUD extension for a given specialization.
Definition
hasHUDExtensionForSpecialization()

VehicleSchemaDisplay

Description
HUD vehicle schema display.
-- Displays a schematic view of the current vehicle configuration.
--@category GUI

new

Description
Create a new instance of VehicleSchemaDisplay.
Definition
new(table modManager)
Arguments
tablemodManagerModManager reference
Return Values
floatfillLevelfill level removed

delete

Description
Delete this element.
Also deletes all loaded vehicle schema overlays.
Definition
delete()
Return Values
floatfillLevelfill level changed

loadVehicleSchemaOverlays

Description
Load vehicle schema overlays from global and mod definitions.
Definition
loadVehicleSchemaOverlays()
Return Values
tableinstanceInstance of object

loadVehicleSchemaOverlaysFromXML

Description
Load and create vehicle schema overlays from XML definitions.
Definition
loadVehicleSchemaOverlaysFromXML(int xmlFile, string modPath)
Arguments
intxmlFileXML file handle of vehicle schema definitions
stringmodPathPath to the current mod description or nil for the base game
Return Values
booleantrueif loading was successful else false

setVehicle

Description
Set the currently controlled vehicle to display its schematic view.
Definition
setVehicle(table vehicle)
Arguments
tablevehicleVehicle reference
Return Values
tableinstanceinstance of object

lateSetDocked

Description
Animation method to set docked state at a delayed time by callback.
Definition
lateSetDocked()
Return Values
booleantrueif loading was successful else false

setDocked

Description
Set the schema's docking state.
This element's position is updated based on the docking state.
Definition
setDocked(bool isDocked)
Arguments
boolisDockedIf true, the schema should be display docked to the HUD input help display. Otherwise, it will
take the input help's place in the top left corner.
Return Values
booleantrueif loading was successful else false

draw

Description
Draw the vehicle schema display.
Only draws the schema if a controlled vehicle is set.
Definition
draw()
Return Values
booleantrueif loading was successful else false

animateDocking

Description
Animate docking / undocking from input help display.
Definition
animateDocking(float startX, float startY, float targetX, float targetY, bool isDocking)
Arguments
floatstartXScreen space starting X position of animation
floatstartYScreen space starting Y position of animation
floattargetXScreen space target X position of animation
floattargetYScreen space target Y position of animation
boolisDockingIf true, moving to docking position. If false, moving to stand-alone position.
Return Values
integermapHandleid of bitvector

collectVehicleSchemaDisplayOverlays

Description
Recursively get vehicle schema overlay parts for a vehicle configuration.
Definition
collectVehicleSchemaDisplayOverlays()
Return Values
booleanisOwnedtrue if farm owns world position point, else false

getVehicleSchemaOverlays

Description
Get a vehicle configuration's schema overlays, including the root vehicle.
Definition
getVehicleSchemaOverlays()
Return Values
integerfarmIdid of farm. Returns 0 if land is not owned by anyone
tableArrayof overlay descriptions: {overlay=overlay, x=0, y=0, rotation=0, invertX=false, invisibleBorderRight=vehicle.schemaOverlay.invisibleBorderRight, invisibleBorderLeft=vehicle.schemaOverlay.invisibleBorderLeft}
floatScreenspace height of root vehicle schema overlay

getSchemaDelimiters

Description
Get minimum and maximum screen space X positions of vehicle schema overlay descriptions.
The returned positions are relative to the position of the root vehicle schema overlay.
Definition
getSchemaDelimiters(table overlayDescriptions)
Arguments
tableoverlayDescriptionsArray of overlay descriptions, see VehicleSchemaDisplay:getVehicleSchemaOverlays()
Return Values
integerfarmlandIdfarmland id. if 0, world position is no valid/buyable farmland
floatMinimumX position (left)
floatMaximumX position (right)

drawVehicleSchemaOverlays

Description
Draw vehicle schema icons for a given vehicle.
Definition
drawVehicleSchemaOverlays(table vehicle)
Arguments
tablevehicleCurrent vehicle
Return Values
booleanisValidtrue if id is valid, else false

getSchemaOverlayForState

Description
Get a schema overlay for a given vehicle's schema overlay data and current state.
Definition
getSchemaOverlayForState(table schemaOverlayData, bool isTurnedOn, bool isSelected, bool isImplement)
Arguments
tableschemaOverlayDataVehicleSchemaOverlayData instance of the current vehicle
boolisTurnedOnTrue if the vehicle is currently turned on, i.e. its function is active
boolisSelectedTrue if the vehicle is currently selected for input
boolisImplementTrue if the vehicle is an implement (i.e. attached to a motorized vehicle), false if it's the root vehicle
Return Values
tablefarmlandfarmland object
tableSchemaOverlay instance

setScale

Description
Set this element's UI scale.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor
Return Values
tablefarmlandsall available farmlands

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Return Values
farmlandIdstablelist of farmland ids owned by given farm id

getBackgroundPosition

Description
Get the vehicle schema's base background position.
Definition
getBackgroundPosition(bool isDocked, float uiScale)
Arguments
boolisDockedIf true, the vehicle schema is docked to the input help display
floatuiScaleCurrent UI scale
Return Values
floatlocalPosXlocal position x
floatlocalPosZlocal position z

createBackground

Description
Create an empty background positioning overlay.
Definition
createBackground()

VehicleSchemaOverlayData

Description
Vehicle schema overlay data.
-- The game HUD draws vehicle schemas based on this data.
--@category Vehicles

new

Description
Create a new VehicleSchemaOverlayData instance.
Definition
new(float offsetX, float offsetY, string schemaNameDefault, string schemaNameOn, string schemaNameSelected, string schemaNameSelectedOn, float invisibleBorderRight, float invisibleBorderLeft)
Arguments
floatoffsetXSchema X position offset as a fraction of the schema overlay size width
floatoffsetYSchema Y position offset as a fraction of the schema overlay size height
stringschemaNameDefaultName of schema overlay for the vehicle default state
stringschemaNameOnName of schema overlay for the vehicle turned on state
stringschemaNameSelectedName of schema overlay for the vehicle selected state
stringschemaNameSelectedOnName of schema overlay for the vehicle selected and turned on state
floatinvisibleBorderRightRight margin width of schema overlay display expressed as a fraction of the overlay width
floatinvisibleBorderLeftLeft margin width of schema overlay display expressed as a fraction of the overlay width

addAttacherJoint

Description
Add attacher joint information.
Definition
addAttacherJoint(float attacherOffsetX, float attacherOffsetY, float rotation, bool invertX, liftedOffsetX X, liftedOffsetY Y)
Arguments
floatattacherOffsetXAttached vehicle schema overlay X offset expressed as a fraction of the overlay width
floatattacherOffsetYAttached vehicle schema overlay Y offset expressed as a fraction of the overlay height
floatrotationAttached vehicle schema rotation
boolinvertXIf true, the attached vehicle schema needs to be flipped horizontally (e.g. front attachments)
liftedOffsetXXposition offset in lifted position in reference resolution pixels
liftedOffsetYYposition offset in lifted position in reference resolution pixels

WorkMode

Description
This is the specialization for switchable work modes
-- @author Stefan Maurus

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
21function WorkMode.prerequisitesPresent(specializations)
22 return SpecializationUtil.hasSpecialization(WorkArea, specializations)
23 and SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations)
24end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
59function WorkMode:onLoad(savegame)
60 local spec = self.spec_workMode
61
62 spec.state = 1
63 spec.stateMax = 0
64
65 local baseKey = "vehicle.workModes"
66
67 spec.foldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, string.format("%s#foldMaxLimit", baseKey)), 1)
68 spec.foldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, string.format("%s#foldMinLimit", baseKey)), 0)
69 spec.allowChangeOnLowered = Utils.getNoNil(getXMLBool(self.xmlFile, string.format("%s#allowChangeOnLowered", baseKey)), true)
70
71 spec.workModes = {}
72 local i = 0
73 while true do
74 local key = string.format("%s.workMode(%d)", baseKey, i)
75 if not hasXMLProperty(self.xmlFile, key) then
76 break
77 end
78
79 local entry = {}
80 entry.name = g_i18n:getText( getXMLString(self.xmlFile, key .. "#name") )
81 local inputBindingName = getXMLString(self.xmlFile, key .. "#inputBindingName")
82 if inputBindingName ~= nil then
83 if InputAction[inputBindingName] ~= nil then
84 entry.inputAction = InputAction[inputBindingName]
85 end
86 end
87
88 entry.turnedOnAnimations = {}
89 local j = 0
90 while true do
91 local key2 = string.format("%s.turnedOnAnimations.turnedOnAnimation(%d)", key, j)
92 if not hasXMLProperty(self.xmlFile, key2) then
93 break
94 end
95
96 local turnedOnAnimation = {}
97 turnedOnAnimation.name = getXMLString(self.xmlFile, key2.."#name")
98 turnedOnAnimation.turnOnFadeTime = Utils.getNoNil(getXMLFloat(self.xmlFile, key2.."#turnOnFadeTime"), 1) * 1000
99 turnedOnAnimation.turnOffFadeTime = Utils.getNoNil(getXMLFloat(self.xmlFile, key2.."#turnOffFadeTime"), 1) * 1000
100 turnedOnAnimation.speedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, key2.."#speedScale"), 1)
101
102 turnedOnAnimation.speedDirection = 0
103 turnedOnAnimation.currentSpeed = 0
104
105 if self:getAnimationExists(turnedOnAnimation.name) then
106 table.insert(entry.turnedOnAnimations, turnedOnAnimation)
107 end
108
109 j = j + 1
110 end
111
112 entry.loweringAnimations = {}
113 j = 0
114 while true do
115 local key2 = string.format("%s.loweringAnimations.loweringAnimation(%d)", key, j)
116 if not hasXMLProperty(self.xmlFile, key2) then
117 break
118 end
119
120 local loweringAnimation = {}
121 loweringAnimation.name = getXMLString(self.xmlFile, key2.."#name")
122 loweringAnimation.speed = Utils.getNoNil(getXMLFloat(self.xmlFile, key2.."#speed"), 1)
123
124 if self:getAnimationExists(loweringAnimation.name) then
125 table.insert(entry.loweringAnimations, loweringAnimation)
126 end
127
128 j = j + 1
129 end
130
131 entry.workAreas = {}
132 j = 0
133 while true do
134 local key2 = string.format("%s.workAreas.workArea(%d)", key, j)
135 if not hasXMLProperty(self.xmlFile, key2) then
136 break
137 end
138
139 local workArea = {}
140 workArea.workAreaIndex = Utils.getNoNil(getXMLInt(self.xmlFile, key2.."#workAreaIndex"), j+1)
141 workArea.dropAreaIndex = Utils.getNoNil(getXMLInt(self.xmlFile, key2.."#dropAreaIndex"), j+1)
142
143 table.insert(entry.workAreas, workArea)
144
145 j = j + 1
146 end
147
148 entry.animations = {}
149 j = 0
150 while true do
151 local animKey = string.format("%s.animation(%d)", key, j)
152 if not hasXMLProperty(self.xmlFile, animKey) then
153 break
154 end
155
156 local animation = {}
157 animation.animName = getXMLString(self.xmlFile, animKey .. "#name")
158 animation.animSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, animKey .. "#speed"), 1.0)
159 animation.stopTime = getXMLFloat(self.xmlFile, animKey .. "#stopTime")
160 animation.repeatAfterUnfolding = Utils.getNoNil(getXMLBool(self.xmlFile, animKey .. "#repeatAfterUnfolding"), false)
161 animation.repeatStartTime = getXMLFloat(self.xmlFile, animKey .. "#repeatStartTime")
162 animation.repeated = false
163
164 if self:getAnimationExists(animation.animName) then
165 table.insert(entry.animations, animation)
166 end
167
168 j = j + 1
169 end
170
171 entry.windrowerEffects = g_effectManager:loadEffect(self.xmlFile, string.format("%s.windrowerEffect", key), self.components, self, self.i3dMappings)
172 entry.animationNodes = g_animationManager:loadAnimations(self.xmlFile, key..".animationNodes", self.components, self, self.i3dMappings)
173
174 table.insert(spec.workModes, entry)
175 i = i + 1
176 end
177
178 spec.stateMax = table.getn(spec.workModes)
179 if spec.stateMax > ((2^WorkMode.WORKMODE_SEND_NUM_BITS) - 1) then
180 print("Error: WorkMode only supports "..((2^WorkMode.WORKMODE_SEND_NUM_BITS) - 1).." modes!")
181 end
182
183 if spec.stateMax > 0 then
184 self:setWorkMode(1, true)
185 end
186
187 spec.accumulatedFruitType = FruitType.UNKNOWN
188 spec.dirtyFlag = self:getNextDirtyFlag()
189end

onReadStream

Description
Called on client side on join
Definition
onReadStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
234function WorkMode:onReadStream(streamId, connection)
235 local spec = self.spec_workMode
236 if spec.stateMax == 0 then
237 return
238 end
239
240 local state = streamReadUIntN(streamId, WorkMode.WORKMODE_SEND_NUM_BITS)
241 self:setWorkMode(state, true)
242end

onWriteStream

Description
Called on server side on join
Definition
onWriteStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
248function WorkMode:onWriteStream(streamId, connection)
249 local spec = self.spec_workMode
250 if spec.stateMax == 0 then
251 return
252 end
253
254 streamWriteUIntN(streamId, spec.state, WorkMode.WORKMODE_SEND_NUM_BITS)
255end

onReadUpdateStream

Description
Called on on update
Definition
onReadUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
262function WorkMode:onReadUpdateStream(streamId, timestamp, connection)
263 if connection:getIsServer() then
264 if streamReadBool(streamId) then
265 local spec = self.spec_workMode
266
267 local mode = spec.workModes[spec.state]
268 for _, effect in ipairs(mode.windrowerEffects) do
269 if streamReadBool(streamId) then
270 effect.lastChargeTime = g_currentMission.time
271 end
272 end
273
274 spec.accumulatedFruitType = streamReadUIntN(streamId, 6)
275 end
276 end
277end

onWriteUpdateStream

Description
Called on on update
Definition
onWriteUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
284function WorkMode:onWriteUpdateStream(streamId, connection, dirtyMask)
285 if not connection:getIsServer() then
286 local spec = self.spec_workMode
287 if streamWriteBool(streamId, bitAND(dirtyMask, spec.dirtyFlag) ~= 0) then
288 local mode = spec.workModes[spec.state]
289
290 for _, effect in ipairs(mode.windrowerEffects) do
291 streamWriteBool(streamId, effect.lastChargeTime + 500 > g_currentMission.time)
292 end
293
294 streamWriteUIntN(streamId, spec.accumulatedFruitType, 6)
295 end
296 end
297end

onUpdate

Description
Called on update
Definition
onUpdate(float dt)
Arguments
floatdttime since last call in ms
Code
302function WorkMode:onUpdate(dt, isActiveForInput, isSelected)
303 local spec = self.spec_workMode
304 if spec.stateMax == 0 then
305 return
306 end
307
308 if self.isClient then
309 local mode = spec.workModes[spec.state]
310
311 for _, turnedOnAnimation in pairs(mode.turnedOnAnimations) do
312 if turnedOnAnimation.speedDirection ~= 0 then
313 local duration = turnedOnAnimation.turnOnFadeTime
314 if turnedOnAnimation.speedDirection == -1 then
315 duration = turnedOnAnimation.turnOffFadeTime
316 end
317 turnedOnAnimation.currentSpeed = MathUtil.clamp(turnedOnAnimation.currentSpeed + turnedOnAnimation.speedDirection * dt/duration, 0, 1)
318 self:setAnimationSpeed(turnedOnAnimation.name, turnedOnAnimation.currentSpeed*turnedOnAnimation.speedScale)
319 if turnedOnAnimation.speedDirection == -1 and turnedOnAnimation.currentSpeed == 0 then
320 self:stopAnimation(turnedOnAnimation.name, true)
321 end
322
323 if turnedOnAnimation.currentSpeed == 1 or turnedOnAnimation.currentSpeed == 0 then
324 turnedOnAnimation.speedDirection = 0
325 end
326 end
327 end
328
329 for _, effect in pairs(mode.windrowerEffects) do
330 if effect.lastChargeTime + 500 > g_currentMission.time then
331 local fillType = g_fruitTypeManager:getWindrowFillTypeIndexByFruitTypeIndex(spec.accumulatedFruitType)
332 if fillType ~= nil then
333 effect:setFillType(fillType)
334 if not effect:isRunning() then
335 g_effectManager:startEffect(effect)
336 end
337 end
338 else
339 if effect.turnOffRequiredEffect == 0 or (effect.turnOffRequiredEffect ~= 0 and not mode.windrowerEffects[effect.turnOffRequiredEffect]:isRunning()) then
340 g_effectManager:stopEffect(effect)
341 end
342 end
343 end
344 end
345
346 if self.isServer then
347 local mode = spec.workModes[spec.state]
348
349 local fruitType
350 local workAreaCharge
351 for _, area in ipairs(mode.workAreas) do
352 local workArea = self.spec_workArea.workAreas[area.workAreaIndex]
353 if workArea ~= nil then
354 if workArea.lastValidPickupFruitType ~= FruitType.UNKNOWN then
355 fruitType = workArea.lastValidPickupFruitType
356 end
357 workAreaCharge = workAreaCharge or workArea.lastPickupLiters ~= 0
358 end
359 end
360
361 if fruitType ~= nil then
362 if fruitType ~= spec.accumulatedFruitType then
363 spec.accumulatedFruitType = fruitType
364 self:raiseDirtyFlags(spec.dirtyFlag)
365 end
366 end
367
368 for _, effect in pairs(mode.windrowerEffects) do
369 if workAreaCharge then
370 effect.lastChargeTime = g_currentMission.time
371 self:raiseDirtyFlags(spec.dirtyFlag)
372 end
373 end
374 end
375end

onDraw

Description
Called on draw
Definition
onDraw(boolean isActiveForInput, boolean isSelected)
Arguments
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
421function WorkMode:onDraw(isActiveForInput, isSelected)
422 local spec = self.spec_workMode
423 if spec.stateMax == 0 then
424 return
425 else
426 local mode = spec.workModes[spec.state]
427 g_currentMission:addExtraPrintText(string.format(g_i18n:getText("action_workModeSelected"), mode.name))
428
429 local allowWorkModeChange = self:getIsWorkModeChangeAllowed()
430
431 local actionEvent = spec.actionEvents[InputAction.TOGGLE_WORKMODE]
432 if actionEvent ~= nil then
433 g_inputBinding:setActionEventActive(actionEvent.actionEventId, allowWorkModeChange)
434 end
435
436 for _, workMode in ipairs(spec.workModes) do
437 if workMode.inputAction ~= nil then
438 actionEvent = spec.actionEvents[workMode.inputAction]
439 if actionEvent ~= nil then
440 g_inputBinding:setActionEventActive(actionEvent.actionEventId, allowWorkModeChange)
441 end
442 end
443 end
444 end
445end

onDeactivate

Description
Called on deactivate
Definition
onDeactivate()
Code
449function WorkMode:onDeactivate()
450 WorkMode.deactivateWindrowerEffects(self)
451end

deactivateWindrowerEffects

Description
Called on deactivate
Definition
deactivateWindrowerEffects()
Code
455function WorkMode:deactivateWindrowerEffects()
456 if self.isClient then
457 local spec = self.spec_workMode
458 for _, mode in pairs(spec.workModes) do
459 if mode.windrowerEffects ~= nil then
460 g_effectManager:stopEffects(mode.windrowerEffects)
461 end
462 end
463 end
464end

setWorkMode

Description
Change work mode
Definition
setWorkMode(integer state, boolean noEventSend)
Arguments
integerstatenew state
booleannoEventSendno event send
Code
470function WorkMode:setWorkMode(state, noEventSend)
471 local spec = self.spec_workMode
472
473 if noEventSend == nil or noEventSend == false then
474 if g_server ~= nil then
475 g_server:broadcastEvent(SetWorkModeEvent:new(self, state), nil, nil, self)
476 else
477 g_client:getServerConnection():sendEvent(SetWorkModeEvent:new(self, state))
478 end
479 end
480
481 if state ~= spec.state then
482 local currentMode = spec.workModes[spec.state]
483 if currentMode.animations ~= nil then
484 for _,anim in pairs(currentMode.animations) do
485 local curTime = self:getAnimationTime(anim.animName)
486 if anim.stopTime == nil then
487 self:playAnimation(anim.animName, -anim.animSpeed, curTime, noEventSend)
488 end
489 end
490 g_animationManager:stopAnimations(currentMode.animationNodes)
491 end
492
493 local newMode = spec.workModes[state]
494 if newMode.animations ~= nil then
495 for _,anim in pairs(newMode.animations) do
496 local curTime = self:getAnimationTime(anim.animName)
497 if anim.stopTime ~= nil then
498 self:setAnimationStopTime(anim.animName, anim.stopTime)
499 local speed = 1.0
500 if curTime > anim.stopTime then
501 speed = -1.0
502 end
503 self:playAnimation(anim.animName, speed, curTime, noEventSend)
504 else
505 self:playAnimation(anim.animName, anim.animSpeed, curTime, noEventSend)
506 end
507 end
508 if self:getIsTurnedOn() then
509 g_animationManager:stopAnimations(newMode.animationNodes)
510 end
511 end
512
513 for _, effect in pairs(currentMode.windrowerEffects) do
514 g_effectManager:stopEffect(effect)
515 end
516 end
517
518 local workAreaSpec = self.spec_workArea
519 if workAreaSpec ~= nil then
520 local workAreas = workAreaSpec.workAreas
521 for _, workArea in pairs(spec.workModes[state].workAreas) do
522 local workAreaToSet = workAreas[workArea.workAreaIndex]
523 if workAreaToSet ~= nil then
524 workAreaToSet.dropWindrowWorkAreaIndex = workArea.dropAreaIndex -- windrower
525 workAreaToSet.dropAreaIndex = workArea.dropAreaIndex -- mower
526 end
527 end
528 end
529
530 spec.state = state
531end

getIsWorkModeChangeAllowed

Description
Returns if work mode change is allowed
Definition
getIsWorkModeChangeAllowed()
Return Values
booleanisAllowedis allowed
Code
557function WorkMode:getIsWorkModeChangeAllowed()
558 local spec = self.spec_workMode
559
560 if self.getFoldAnimTime ~= nil then
561 if self:getFoldAnimTime() > spec.foldMaxLimit or self:getFoldAnimTime() < spec.foldMinLimit then
562 return false
563 end
564 end
565
566 if not spec.allowChangeOnLowered then
567 local attacherVehicle = self:getAttacherVehicle()
568 if attacherVehicle ~= nil then
569 local index = attacherVehicle:getAttacherJointIndexFromObject(self)
570 local attacherJoint = attacherVehicle:getAttacherJointByJointDescIndex(index)
571
572 if attacherJoint.moveDown then
573 return false
574 end
575 end
576 end
577
578 return true
579end

onTurnedOff

Description
Called on turn off
Definition
onTurnedOff(boolean noEventSend)
Arguments
booleannoEventSendno event send
Code
584function WorkMode:onTurnedOff()
585 local spec = self.spec_workMode
586 if spec.stateMax == 0 then
587 return
588 end
589
590 if self.isClient then
591 WorkMode.deactivateWindrowerEffects(self)
592 local mode = spec.workModes[spec.state]
593
594 for _, turnedOnAnimation in pairs(mode.turnedOnAnimations) do
595 turnedOnAnimation.speedDirection = -1
596 end
597 g_animationManager:stopAnimations(mode.animationNodes)
598 end
599end

onTurnedOn

Description
Called on turn on
Definition
onTurnedOn(boolean noEventSend)
Arguments
booleannoEventSendno event send
Code
604function WorkMode:onTurnedOn()
605 local spec = self.spec_workMode
606 if spec.stateMax == 0 then
607 return
608 end
609
610 if self.isClient then
611 local mode = spec.workModes[spec.state]
612
613 for _, turnedOnAnimation in pairs(mode.turnedOnAnimations) do
614 turnedOnAnimation.speedDirection = 1
615 self:playAnimation(turnedOnAnimation.name, turnedOnAnimation.currentSpeed*turnedOnAnimation.speedScale, self:getAnimationTime(turnedOnAnimation.name), true)
616 end
617 g_animationManager:startAnimations(mode.animationNodes)
618 end
619end

onSetLowered

Description
Called on change lowering state
Definition
onSetLowered(boolean lowered)
Arguments
booleanloweredattachable is lowered
Code
624function WorkMode:onSetLowered(lowered)
625 local spec = self.spec_workMode
626 if spec.stateMax == 0 then
627 return
628 end
629
630 if self.getFoldAnimTime ~= nil then
631 local foldAnimTime = self:getFoldAnimTime()
632 if foldAnimTime ~= 1 and foldAnimTime ~= 0 and foldAnimTime ~= self.foldMiddleAnimTime then
633 spec.playDelayedLoweringAnimation = lowered
634 return
635 end
636 end
637
638 local mode = spec.workModes[spec.state]
639
640 for _, loweringAnimation in pairs(mode.loweringAnimations) do
641 if lowered then
642 if self:getAnimationTime(loweringAnimation.name) < 1 then
643 self:playAnimation(loweringAnimation.name, loweringAnimation.speed, nil, true)
644 end
645 else
646 if self:getAnimationTime(loweringAnimation.name) > 0 then
647 self:playAnimation(loweringAnimation.name, -loweringAnimation.speed, nil, true)
648 end
649 end
650 end
651end

onFoldStateChanged

Description
Called on fold state change
Definition
onFoldStateChanged(integer direction)
Arguments
integerdirectiondirection of folding
Code
656function WorkMode:onFoldStateChanged(direction, moveToMiddle)
657 local spec = self.spec_workMode
658 if spec.stateMax == 0 then
659 return
660 end
661
662 if direction > 0 then
663 local mode = spec.workModes[spec.state]
664
665 for _, anim in pairs(mode.animations) do
666 if anim.repeatAfterUnfolding then
667 anim.repeated = false
668 end
669 end
670 end
671end

AnimationManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
18function AnimationManager:new(customMt)
19 local self = AbstractManager:new(customMt or AnimationManager_mt)
20
21 return self
22end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
26function AnimationManager:initDataStructures()
27 self.runningAnimations = {}
28 self.registeredAnimationClasses = {}
29end

AITurnStrategy

Description

validateCollisionBox

Description
checks if calculation of box is valid (check for NAN)
Definition
validateCollisionBox()

HelperManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
18function HelperManager:new(customMt)
19 local self = AbstractManager:new(customMt or HelperManager_mt)
20 return self
21end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
25function HelperManager:initDataStructures()
26 self.numHelpers = 0
27 self.helpers = {}
28 self.nameToIndex = {}
29 self.indexToHelper = {}
30 self.availableHelpers = {}
31end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
42function HelperManager:loadMapData(xmlFile, missionInfo, baseDirectory)
43 HelperManager:superClass().loadMapData(self)
44
45 self:loadDefaultTypes()
46 return XMLUtil.loadDataFromMapXML(xmlFile, "helpers", baseDirectory, self, self.loadHelpers, missionInfo, baseDirectory)
47end

loadHelpers

Description
Load data on map load
Definition
loadHelpers()
Return Values
booleantrueif loading was successful else false
Code
52function HelperManager:loadHelpers(xmlFile, missionInfo, baseDirectory, isBaseType)
53 local i = 0
54 while true do
55 local key = string.format("map.helpers.helper(%d)", i)
56 if not hasXMLProperty(xmlFile, key) then
57 break
58 end
59
60 local name = getXMLString(xmlFile, key.."#name")
61 local title = getXMLString(xmlFile, key.."#title")
62 local filename = getXMLString(xmlFile, key.."#filename")
63
64 self:addHelper(name, title, filename, baseDirectory, isBaseType)
65
66 i = i + 1
67 end
68
69 return true
70end

addHelper

Description
Adds a new helper
Definition
addHelper(string name, string filename, string baseDir)
Arguments
stringnamehelper index name
stringfilenamehelper config filename
stringbaseDirthe base directory
Return Values
booleantrueif added successful else false
Code
78function HelperManager:addHelper(name, title, filename, baseDir, isBaseType)
79 if not ClassUtil.getIsValidIndexName(name) then
80 print("Warning: '"..tostring(name).."' is not a valid name for a helper. Ignoring helper!")
81 return nil
82 end
83
84 name = name:upper()
85
86 if isBaseType and self.nameToIndex[name] ~= nil then
87 print("Warning: Helper '"..tostring(name).."' already exists. Ignoring helper!")
88 return nil
89 end
90
91 local helper = self.helpers[name]
92 if helper == nil then
93 if filename == nil or filename == "" then
94 print("Warning: Missing helper config file for helper '"..tostring(name).."'. Ignoring helper!")
95 return nil
96 end
97
98 self.numHelpers = self.numHelpers + 1
99
100 helper = {}
101 helper.name = name
102 helper.index = self.numHelpers
103 helper.title = name
104 if title ~= nil then
105 helper.title = g_i18n:convertText(title)
106 end
107 helper.filename = Utils.getFilename(filename, baseDir)
108
109 self.helpers[name] = helper
110 self.nameToIndex[name] = self.numHelpers
111 self.indexToHelper[self.numHelpers] = helper
112 table.insert(self.availableHelpers, helper)
113 else
114 if title ~= nil then
115 helper.title = g_i18n:convertText(title)
116 end
117 if filename ~= nil then
118 helper.filename = Utils.getFilename(filename, baseDir)
119 end
120 end
121
122 return helper
123end

getRandomHelper

Description
Gets a random helper
Definition
getRandomHelper()
Return Values
tablehelpera random helper object
Code
128function HelperManager:getRandomHelper()
129 return self.availableHelpers[math.random(1, #self.availableHelpers)]
130end

getRandomIndex

Description
Gets a random helper index
Definition
getRandomIndex()
Return Values
integerhelperIndexa random helper index
Code
135function HelperManager:getRandomIndex()
136 return math.random(1, self.numHelpers)
137end

getHelperByIndex

Description
Gets a helper by index
Definition
getHelperByIndex(integer index)
Arguments
integerindexthe helper index
Return Values
tablehelperthe helper object
Code
143function HelperManager:getHelperByIndex(index)
144 if index ~= nil then
145 return self.indexToHelper[index]
146 end
147 return nil
148end

getHelperByName

Description
Gets a helper by index name
Definition
getHelperByName(string name)
Arguments
stringnamethe helper index name
Return Values
tablehelperthe helper object
Code
154function HelperManager:getHelperByName(name)
155 if name ~= nil then
156 name = name:upper()
157 return self.helpers[name]
158 end
159 return nil
160end

useHelper

Description
Marks a helper as 'in use'
Definition
useHelper(table helper)
Arguments
tablehelperthe helper object
Return Values
booleansuccesstrue if helper is marked else false
Code
166function HelperManager:useHelper(helper)
167 for k, h in pairs(self.availableHelpers) do
168 if h == helper then
169 table.remove(self.availableHelpers, k)
170 return true
171 end
172 end
173 return false
174end

releaseHelper

Description
Marks a helper as 'not in use'
Definition
releaseHelper(table helper)
Arguments
tablehelperthe helper object
Code
179function HelperManager:releaseHelper(helper)
180 table.insert(self.availableHelpers, helper)
181end

getNumOfHelpers

Description
Gets number of helpers
Definition
getNumOfHelpers()
Return Values
integernumOfHelperstotal number of helpers
Code
186function HelperManager:getNumOfHelpers()
187 return self.numHelpers
188end

NPCManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
18function NPCManager:new(customMt)
19 local self = AbstractManager:new(customMt or NPCManager_mt)
20 return self
21end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
25function NPCManager:initDataStructures()
26 self.numNpcs = 0
27 self.npcs = {}
28 self.nameToIndex = {}
29 self.indexToNpc = {}
30end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
41function NPCManager:loadMapData(xmlFile, missionInfo, baseDirectory)
42 NPCManager:superClass().loadMapData(self)
43
44 self:loadDefaultTypes(missionInfo, baseDirectory)
45 return XMLUtil.loadDataFromMapXML(xmlFile, "npcs", baseDirectory, self, self.loadNPCs, missionInfo, baseDirectory)
46end

loadNPCs

Description
Load data on map load
Definition
loadNPCs()
Return Values
booleantrueif loading was successful else false
Code
51function NPCManager:loadNPCs(xmlFile, missionInfo, baseDirectory, isBaseType)
52
53 local i = 0
54 while true do
55 local key = string.format("map.npcs.npc(%d)", i)
56 if not hasXMLProperty(xmlFile, key) then
57 break
58 end
59
60 local name = getXMLString(xmlFile, key.."#name")
61 local title = getXMLString(xmlFile, key.."#title")
62 local category = getXMLString(xmlFile, key.."#category")
63 local imageFilename = getXMLString(xmlFile, key.."#imageFilename")
64
65 self:addNPC(name, title, category, imageFilename, baseDirectory, isBaseType)
66
67 i = i + 1
68 end
69
70 return true
71end

saveToXMLFile

Description
Write data to savegame file
Definition
saveToXMLFile(string xmlFilename)
Arguments
stringxmlFilenamefile path
Return Values
booleantrueif loading was successful else false
Code
77function NPCManager:saveToXMLFile(xmlFilename)
78 -- save npcs to xml
79 local xmlFile = createXMLFile("npcsXML", xmlFilename, "npcs")
80 if xmlFile ~= nil then
81 for k, npc in ipairs(self.indexToNpc) do
82 local npcKey = string.format("npcs.npc(%d)", k-1)
83 setXMLString(xmlFile, npcKey.."#name", npc.name)
84 setXMLInt(xmlFile, npcKey.."#finishedMissions", npc.finishedMissions)
85 end
86
87 saveXMLFile(xmlFile)
88 delete(xmlFile)
89
90 return true
91 end
92
93 return false
94end

loadFromXMLFile

Description
Load data from xml savegame file
Definition
loadFromXMLFile(string filename)
Arguments
stringfilenamexml filename
Code
99function NPCManager:loadFromXMLFile(xmlFilename)
100 if xmlFilename == nil then
101 return false
102 end
103
104 local xmlFile = loadXMLFile("npcXML", xmlFilename)
105
106 if xmlFile == 0 then
107 return false
108 end
109
110 local i = 0
111 while true do
112 local key = string.format("npcs.npc(%d)", i)
113 if not hasXMLProperty(xmlFile, key) then
114 break
115 end
116
117 local name = getXMLString(xmlFile, key.."#name")
118 local npc = self:getNPCByName(name)
119 if npc ~= nil then
120 npc.finishedMissions = Utils.getNoNil(getXMLInt(xmlFile, key.."#finishedMissions"), 0)
121 else
122 print("Warning: Npc '"..tostring(name).."' not found!")
123 end
124 i = i + 1
125 end
126
127 delete(xmlFile)
128
129 return true
130end

addNPC

Description
Adds a new npc
Definition
addNPC(string name, string title, string category, string imageFilename, string baseDir)
Arguments
stringnamenpc index name
stringtitlenpc real name
stringcategorynpc category (e.g. young, middle, old, female)
stringimageFilenamenpc image filename
stringbaseDirthe base directory
Return Values
booleantrueif added successful else false
Code
140function NPCManager:addNPC(name, title, category, imageFilename, baseDir, isBaseType)
141 if not ClassUtil.getIsValidIndexName(name) then
142 print("Warning: '"..tostring(name).."' is not a valid name for a npc. Ignoring npc!")
143 return nil
144 end
145
146 name = name:upper()
147
148 if isBaseType and self.nameToIndex[name] ~= nil then
149 print("Warning: NPC '"..tostring(name).."' already exists. Ignoring npc!")
150 return nil
151 end
152
153 local npc = self.npcs[name]
154 if npc == nil then
155 if title == nil or title == "" then
156 print("Warning: '"..tostring(title).."' is not a valid title for a npc. Ignoring npc!")
157 return nil
158 end
159 if category == nil or category == "" then
160 print("Warning: '"..tostring(category).."' is not a valid category for a npc. Ignoring npc!")
161 return nil
162 end
163 if imageFilename == nil or imageFilename == "" then
164 print("Warning: Missing npc image file for npc '"..tostring(name).."'. Ignoring npc!")
165 return nil
166 end
167
168 self.numNpcs = self.numNpcs + 1
169 npc = {}
170 npc.name = name
171 npc.title = g_i18n:convertText(title)
172 npc.index = self.numNpcs
173 npc.imageFilename = Utils.getFilename(imageFilename, baseDir)
174 npc.finishedMissions = 0
175
176 self.npcs[name] = npc
177 self.nameToIndex[name] = self.numNpcs
178 self.indexToNpc[self.numNpcs] = npc
179 else
180 if title ~= nil and title ~= "" then
181 npc.title = g_i18n:convertText(title)
182 end
183 if imageFilename ~= nil and imageFilename ~= "" then
184 npc.imageFilename = Utils.getFilename(imageFilename, baseDir)
185 end
186 end
187
188 return npc
189end

getRandomNPC

Description
Gets a random npc
Definition
getRandomNPC()
Return Values
tablenpca random npc object
Code
194function NPCManager:getRandomNPC()
195 return self.indexToNpc[self:getRandomIndex()]
196end

getRandomIndex

Description
Gets a random npc index
Definition
getRandomIndex()
Return Values
integernpcIndexa random npc index
Code
201function NPCManager:getRandomIndex()
202 return math.random(1, self.numNpcs)
203end

getNPCByIndex

Description
Gets a npc by index
Definition
getNPCByIndex(integer index)
Arguments
integerindexthe npc index
Return Values
tablenpcthe npc object
Code
209function NPCManager:getNPCByIndex(index)
210 if index ~= nil then
211 return self.indexToNpc[index]
212 end
213 return nil
214end

getNPCByName

Description
Gets a npc by index name
Definition
getNPCByName(string name)
Arguments
stringnamethe npc index name
Return Values
tablenpcthe npc object
Code
220function NPCManager:getNPCByName(name)
221 if name ~= nil then
222 name = name:upper()
223 return self.npcs[name]
224 end
225 return nil
226end

I3DManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of basket trigger object
tableinstanceinstance of object
Code
17function I3DManager:new(customMt)
18 local self = AbstractManager:new(customMt or I3DManager_mt)
19
20 return self
21end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Return Values
booleansuccesssuccess
Code
25function I3DManager:initDataStructures()
26 self.sharedI3DFiles = {}
27 self.sharedI3DFilesPendingCallbacks = {}
28end

loadSharedI3DFile

Description
Loads an i3D file. A cache system is used for faster loading
Definition
loadSharedI3DFile(string filename, string baseDir, boolean callOnCreate, boolean addToPhysics, boolean verbose, function asyncCallbackFunction, table asyncCallbackObject, table asyncCallbackArguments)
Arguments
stringfilenamefilename
stringbaseDirbaseDir
booleancallOnCreatetrue if onCreate i3d callbacks should be called
booleanaddToPhysicstrue if collisions should be added to physics
booleanverboseverbose
functionasyncCallbackFunctiona callback function
tableasyncCallbackObjectcallback function target object
tableasyncCallbackArgumentsa list of arguments
Return Values
tableinstanceinstance
integeridi3d rootnode

loadSharedI3DFileFinished

Description
Called once i3d loading is finished
Definition
loadSharedI3DFileFinished(integer nodeId, table arguments)
Arguments
integernodeIdi3d node id
tableargumentsa list of arguments
Return Values
booleanisActivateableis activateable

fillSharedI3DFileCache

Description
Adds an i3d file to cache
Definition
fillSharedI3DFileCache(string filename, string baseDir)
Arguments
stringfilenamefilename
stringbaseDirbaseDir
Return Values
tableinstanceinstance of basket trigger object

releaseSharedI3DFile

Description
Releases one instance. If autoDelete is true and instance count <= 0. I3d will be removed from cache
Definition
releaseSharedI3DFile(string filename, string baseDir, boolean autoDelete)
Arguments
stringfilenamefilename
stringbaseDirbaseDir
booleanautoDeletetrue if file should be removed from cache if instance count is <= 0
Return Values
booleansuccesssuccess

deleteSharedI3DFiles

Description
Clears i3d cache
Definition
deleteSharedI3DFiles()
Return Values
tableinstanceinstance of object

Chainsaw

Description
Class for chainsaws

new

Description
Creating chainsaw object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceinstance of object
tableinstanceInstance of object
Code
35function Chainsaw:new(isServer, isClient, customMt)
36 local self = HandTool:new(isServer, isClient, customMt or Chainsaw_mt)
37 return self
38end

load

Description
Load chainsaw from xml file
Definition
load(string xmlFilename, table player)
Arguments
stringxmlFilenamexml file name
tableplayerplayer
Return Values
booltrueif player can idle
booleansuccesssuccess
Code
45function Chainsaw:load(xmlFilename, player)
46 if not Chainsaw:superClass().load(self, xmlFilename, player) then
47 return false
48 end
49
50 local xmlFile = loadXMLFile("TempXML", xmlFilename)
51
52 self.rotateInput = 0
53 self.activatePressed = false
54 self.eventIdRotateHandtool = ""
55
56 self.rotationZ = 0
57 self.rotationSpeedZ = 0.003
58 self.cutSizeY = 1.1
59 self.cutSizeZ = 1.0
60 self.isCutting = false
61 self.waitingForResetAfterCut = false
62 self.cutNode = getChildAt(self.rootNode, 0)
63 self.graphicsNode = getChildAt(self.cutNode, 0)
64 self.chainNode = getChildAt(self.graphicsNode, 0)
65 self.psNode = getChildAt(self.graphicsNode, 1)
66 self.cutPositionNode = getChildAt(self.graphicsNode, 5)
67
68 self.pricePerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.chainsaw.pricePerMinute"), 50) / 1000
69 self.quicktapThreshold = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.chainsaw#quicktapThreshold"), 0.0) * 1000
70 if self.isClient then
71 self.particleSystems = {}
72
73 local i = 0
74 while true do
75 local keyPS = string.format("handTool.chainsaw.particleSystems.emitterShape(%d)", i)
76 if not hasXMLProperty(xmlFile, keyPS) then
77 break
78 end
79 local emitterShape = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, keyPS.."#node"))
80 local particleType = getXMLString(xmlFile, keyPS.."#particleType")
81 if emitterShape ~= nil then
82 local fillType = FillType.WOODCHIPS
83 local particleSystem = g_particleSystemManager:getParticleSystem(fillType, particleType)
84 if particleSystem ~= nil then
85 table.insert(self.particleSystems, ParticleUtil.copyParticleSystem(xmlFile, keyPS, particleSystem, emitterShape))
86 end
87 end
88 i = i + 1
89 end
90
91 if #self.particleSystems == 0 then
92 self.particleSystems = nil
93 end
94
95 self.handNode = Utils.getNoNil(I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.chainsaw.handNode#node")), self.rootNode)
96 self.handNodeRotation = StringUtil.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.chainsaw.handNode#rotation"), "0 0 0"), 3)
97
98 self.equipmentUVs = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.chainsaw.equipment#uvs"), "0 0"), 2)
99
100 self.chains = g_animationManager:loadAnimations(xmlFile, "handTool.chainsaw.chain", self.rootNode, self, nil)
101 self.samples = {}
102 self.samples.start = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "start", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
103 self.samples.stop = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "stop", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
104 self.samples.idle = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "idle", self.baseDirectory, self.rootNode, 0, AudioGroup.VEHICLE, nil, nil)
105 self.samples.cutStart = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "cutStart", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
106 self.samples.cutStop = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "cutStop", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
107 self.samples.cutLoop = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "cutLoop", self.baseDirectory, self.rootNode, 0, AudioGroup.VEHICLE, nil, nil)
108 self.samples.activeStart = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "activeStart", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
109 self.samples.activeStop = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "activeStop", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
110 self.samples.activeLoop = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds", "activeLoop", self.baseDirectory, self.rootNode, 0, AudioGroup.VEHICLE, nil, nil)
111 self.samplesQuicktap = {}
112 local j = 0
113 while true do
114 local sampleQuicktap = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.sounds.quickTapSounds", string.format("quickTap(%d)", j), self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
115 if sampleQuicktap == nil then
116 break
117 end
118 table.insert(self.samplesQuicktap, sampleQuicktap)
119 j = j + 1
120 end
121 self.samplesQuicktapCount = j
122
123 self.samplesTree = {}
124 self.samplesTree.cut = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.treeSounds", "cut", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
125 --self.samplesTree.falling = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.treeSounds", "falling", self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
126 self.samplesBranch = {}
127 local k = 0
128 while true do
129 local sampleBranch = g_soundManager:loadSampleFromXML(xmlFile, "handTool.chainsaw.branchSounds", string.format("branch(%d)", k), self.baseDirectory, self.rootNode, 1, AudioGroup.VEHICLE, nil, nil)
130 if sampleBranch == nil then
131 break
132 end
133 table.insert(self.samplesBranch, sampleBranch)
134 k = k + 1
135 end
136 self.samplesBranchCount = k
137 self.samplesBranchActiveTimer = 0
138
139 self.samplesTreeLinkNode = createTransformGroup("cutSoundLinkNode")
140 link(self.cutNode, self.samplesTreeLinkNode)
141
142 if self.samplesTree.cut ~= nil and self.samplesTree.cut.soundNode ~= nil then
143 link(self.samplesTreeLinkNode, self.samplesTree.cut.soundNode)
144 --link(self.samplesTreeLinkNode, self.samplesTree.falling.soundNode)
145 end
146
147 self.soundFSM = FSMUtil.create()
148 self.soundFSM:addState(Chainsaw.SOUND_STATES.START, ChainsawSoundStateStart:new(Chainsaw.SOUND_STATES.START, self, self.soundFSM))
149 self.soundFSM:addState(Chainsaw.SOUND_STATES.STOP, ChainsawSoundStateStop:new(Chainsaw.SOUND_STATES.STOP, self, self.soundFSM))
150 self.soundFSM:addState(Chainsaw.SOUND_STATES.IDLE, ChainsawSoundStateIdle:new(Chainsaw.SOUND_STATES.IDLE, self, self.soundFSM))
151 self.soundFSM:addState(Chainsaw.SOUND_STATES.ACTIVE, ChainsawSoundStateActive:new(Chainsaw.SOUND_STATES.ACTIVE, self, self.soundFSM))
152 self.soundFSM:addState(Chainsaw.SOUND_STATES.CUT, ChainsawSoundStateCut:new(Chainsaw.SOUND_STATES.CUT, self, self.soundFSM))
153 self.soundFSM:addState(Chainsaw.SOUND_STATES.QUICKTAP, ChainsawSoundStateQuicktap:new(Chainsaw.SOUND_STATES.QUICKTAP, self, self.soundFSM))
154
155 local filename = getXMLString(xmlFile, "handTool.chainsaw.ringSelector#file")
156 if filename ~= nil then
157 local i3dNode = g_i3DManager:loadSharedI3DFile(filename, self.baseDirectory, false, false, false)
158 if i3dNode ~= 0 then
159 self.ringSelectorFilename = filename
160 self.ringSelector = getChildAt(i3dNode, 0)
161 self.ringSelectorScaleOffset = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.chainsaw.ringSelector#scaleOffset"), 0.3)
162 setVisibility(self.ringSelector, false)
163 link(player.chainsawSplitShapeFocus, self.ringSelector)
164 delete(i3dNode)
165 end
166 end
167 end
168
169 self.lastWorkTime = 0
170 self.maxWorkTime = 300
171
172 self.moveSpeedY = 0.0001
173 self.speedFactor = 0
174 self.defaultCutDuration = 8.0 -- in s
175 self.maxTrunkWidthSq = 1.0 -- in m
176 self.outDuration = 0.15 -- in s
177 self.inDuration = 0.15 -- in s
178 self.cutTimer = 0.0 -- in s
179 self.outTimer = self.outDuration -- in s
180 self.transitionAlpha = 0.0 -- [0,1]
181 self.cameraTransitionState = Chainsaw.CAMERA_TRANSITION_STATES.NONE -- 0=in 1=cut 2=out
182 self.minRotationZ = math.rad(90) -- in rad
183 self.maxRotationZ = math.rad(-90) -- in rad
184 self.maxModelTranslation = 0.0 -- in m
185 self.cutFocusDistance = -1.0
186 self.startCameraDirectionY = { 0, 1, 0 }
187 self.startCameraDirectionZ = { 0, 0, 1 }
188 self.endCameraDirectionY = { 0, 1, 0 }
189 self.endCameraDirectionZ = { 0, 0, 1 }
190 self.startChainsawPosition = { 0, 0, 0 }
191 self.endChainsawPosition = { 0, 0, 0 }
192 self.showNotOwnedWarning = false
193
194 self.isCutting = false
195 self.isHorizontalCut = false
196
197 delete(xmlFile)
198
199 return true
200end

delete

Description
Deleting chainsaw
Definition
delete()
Return Values
tableinstanceinstance of object
Code
204function Chainsaw:delete()
205 if self.isClient then
206 ParticleUtil.deleteParticleSystems(self.particleSystems)
207
208 if self.ringSelector ~= nil then
209 delete(self.ringSelector)
210 end
211 for _,sample in pairs(self.samplesTree) do
212 g_soundManager:deleteSample(sample)
213 end
214 for _,sample in pairs(self.samplesBranch) do
215 g_soundManager:deleteSample(sample)
216 end
217 for _,sample in pairs(self.samples) do
218 g_soundManager:deleteSample(sample)
219 end
220 if self.ringSelectorFilename ~= nil then
221 g_i3DManager:releaseSharedI3DFile(self.ringSelectorFilename, self.baseDirectory, true)
222 end
223 g_animationManager:deleteAnimations(self.chains)
224 end
225
226 Chainsaw:superClass().delete(self)
227end

cutRaycastCallback

Description
Saves raycast information
Definition
cutRaycastCallback(integer hitObjectId, float x, float y, float z, float distance)
Arguments
integerhitObjectId
floatx
floaty
floatz
floatdistance
Return Values
booltrueif player can swim
Code
236function Chainsaw:cutRaycastCallback(hitObjectId, x, y, z, distance)
237 setWorldTranslation(self.player.chainsawCameraFocus, x, y, z)
238 self.cutFocusDistance = distance
239end

updateCutRaycast

Description
Cast ray from the player camera
Definition
updateCutRaycast()
Return Values
booltrueif player can swim
Code
243function Chainsaw:updateCutRaycast()
244 self.cutFocusDistance = -1.0
245 setTranslation(self.player.chainsawCameraFocus, 0, 0, 0)
246 local cameraPosition = {getWorldTranslation(self.player.cameraNode)}
247 local worldDirection = {unProject(0.52, 0.4, 1)} -- Transform vector from screen space into world space
248 local treeCollisionMask = 16789504 -- bits: 12,13,24
249
250 worldDirection[1],
251 worldDirection[2],
252 worldDirection[3] = MathUtil.vector3Normalize(worldDirection[1], worldDirection[2], worldDirection[3])
253 raycastClosest(cameraPosition[1], cameraPosition[2], cameraPosition[3],
254 worldDirection[1], worldDirection[2], worldDirection[3],
255 "cutRaycastCallback", self.player.cutDetectionDistance,
256 self, treeCollisionMask)
257end

testTooLow

Description
Definition
testTooLow(integer shape, float minY, float maxY, float minZ, float maxZ)
Arguments
integershape
floatminY
floatmaxY
floatminZ
floatmaxZ
Return Values
tableinstanceinstance of object
Code
267function Chainsaw:testTooLow(shape, minY, maxY, minZ, maxZ)
268 local cutTooLow = false
269 local _,y1,_ = localToLocal(self.player.chainsawSplitShapeFocus, shape, 0,minY,minZ)
270 local _,y3,_ = localToLocal(self.player.chainsawSplitShapeFocus, shape, 0,maxY,minZ)
271 local _,y4,_ = localToLocal(self.player.chainsawSplitShapeFocus, shape, 0,maxY,maxZ)
272
273 cutTooLow = y1 < 0.01 or y1 < 0.01 or y3 < 0.03 or y4 < 0.01
274 if not cutTooLow then
275 local x1,y1,z1 = localToWorld(self.player.chainsawSplitShapeFocus, 0,minY,minZ)
276 local x2,y2,z2 = localToWorld(self.player.chainsawSplitShapeFocus, 0,minY,maxZ)
277 local x3,y3,z3 = localToWorld(self.player.chainsawSplitShapeFocus, 0,maxY,minZ)
278 local x4,y4,z4 = localToWorld(self.player.chainsawSplitShapeFocus, 0,maxY,maxZ)
279 local h1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,y1,z1)
280 local h2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,y2,z2)
281 local h3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,y3,z3)
282 local h4 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x4,y4,z4)
283 cutTooLow = h1 < 0.01 or h2 < 0.01 or h3 < 0.03 or h4 < 0.01
284 end
285 if cutTooLow then
286 return true
287 end
288 return false
289end

getLookAt

Description
Given a target position we calculate a up and towards direction (result is in world reference)
Definition
getLookAt(integer camera, float target, float target, float target)
Arguments
integercameraidentifier
floattargetposition x
floattargetposition y
floattargetposition z
Return Values
tableinstanceInstance of object
float
float
float
float
float
float
Code
303function Chainsaw:getLookAt(cameraNode, targetX, targetY, targetZ)
304 local xx, xy, xz = 0, 0, 0
305 local yx, yy, yz = 0, 0, 0
306 local zx, zy, zz = 0, 0, 0
307 local nodePosition = {getWorldTranslation(cameraNode)}
308 local nodeUpDirection = {localDirectionToWorld(getParent(cameraNode), 0, -1, 0)}
309
310 zx = nodePosition[1] - targetX
311 zy = nodePosition[2] - targetY
312 zz = nodePosition[3] - targetZ
313 zx, zy, zz = MathUtil.vector3Normalize(zx, zy, zz)
314 xx, xy, xz = MathUtil.crossProduct(zx, zy, zz, nodeUpDirection[1], nodeUpDirection[2], nodeUpDirection[3])
315 xx, xy, xz = MathUtil.vector3Normalize(xx, xy, xz)
316 yx, yy, yz = MathUtil.crossProduct(zx, zy, zz, xx, xy, xz)
317 yx, yy, yz = MathUtil.vector3Normalize(yx, yy, yz)
318
319 return yx, yy, yz, zx, zy, zz
320end

getCutStartEnd

Description
Function to calculate the start and the end of the cut by using the ringSelector
Definition
getCutStartEnd()
Return Values
tableinstanceInstance of object
Code
324function Chainsaw:getCutStartEnd()
325 local selectorPosition = {getWorldTranslation(self.ringSelector)}
326 local selectorScale = {getScale(self.ringSelector)}
327 local cutDirection = {localDirectionToWorld(self.ringSelector, 0, 1, 0)}
328 local cutStartposition = { selectorPosition[1] - 0.5 * selectorScale[1] * cutDirection[1],
329 selectorPosition[2] - 0.5 * selectorScale[2] * cutDirection[2],
330 selectorPosition[3] - 0.5 * selectorScale[3] * cutDirection[3] }
331 local cutEndposition = { selectorPosition[1] + 0.5 * selectorScale[1] * cutDirection[1],
332 selectorPosition[2] + 0.5 * selectorScale[2] * cutDirection[2],
333 selectorPosition[3] + 0.5 * selectorScale[3] * cutDirection[3] }
334 return cutStartposition[1], cutStartposition[2], cutStartposition[3], cutEndposition[1], cutEndposition[2], cutEndposition[3]
335end

calculateCutDuration

Description
Definition
calculateCutDuration(float dt, bool true)
Arguments
floatdtin milliseconds
booltrueif the player is cutting
Return Values
tableinstanceInstance of object
Code
341function Chainsaw:calculateCutDuration()
342 local startX, startY, startZ, endX, endY, endZ = self:getCutStartEnd()
343 local trunkWidthSq = MathUtil.vector3LengthSq(endX - startX, endY - startY, endZ - startZ)
344 trunkWidthSq = MathUtil.clamp(trunkWidthSq, 0.0, self.maxTrunkWidthSq)
345 local cutDuration = trunkWidthSq * self.defaultCutDuration / self.maxTrunkWidthSq
346 return cutDuration
347end

updateCuttingTimers

Description
Definition
updateCuttingTimers(float dt, bool true)
Arguments
floatdtin milliseconds
booltrueif the player is cutting
Return Values
tableinstanceInstance of object
Code
353function Chainsaw:updateCuttingTimers(dt, isCutting)
354 local dtInSec = dt * 0.001
355 self.transitionAlpha = 0.0
356
357 if isCutting then
358 local cutDuration = self:calculateCutDuration()
359 if (self.cutTimer == 0.0) then
360 self.outTimer = 0.0
361 self.cameraTransitionState = Chainsaw.CAMERA_TRANSITION_STATES.IN
362 elseif self.cutTimer == self.inDuration then
363 self.cameraTransitionState = Chainsaw.CAMERA_TRANSITION_STATES.CUT
364 end
365
366 if (self.cutTimer >= 0.0) and (self.cutTimer < self.inDuration) then
367 self.cutTimer = math.min(self.cutTimer + dtInSec, self.inDuration)
368 self.transitionAlpha = MathUtil.clamp(self.cutTimer, 0.0, self.inDuration) / self.inDuration
369 elseif (self.cutTimer >= self.inDuration) and (self.cutTimer < cutDuration) then
370 local restCutDuration = math.max(cutDuration - self.inDuration, 0)
371
372 self.cutTimer = math.min(self.cutTimer + dtInSec, cutDuration)
373 self.transitionAlpha = MathUtil.clamp(self.cutTimer - self.inDuration, 0, restCutDuration) / restCutDuration
374 else
375 self.transitionAlpha = 1.0
376 end
377 else
378 cutDuration = self.defaultCutDuration
379 if self.outTimer == 0.0 then
380 self.cutTimer = 0.0
381 self.cameraTransitionState = Chainsaw.CAMERA_TRANSITION_STATES.OUT
382 end
383
384 if (self.outTimer >= 0.0) and (self.outTimer < self.outDuration) then
385 self.outTimer = math.min(self.outTimer + dtInSec, self.outDuration)
386 self.transitionAlpha = MathUtil.clamp(self.outTimer, 0.0, self.outDuration) / self.outDuration
387 end
388 end
389end

resetTransitionState

Description
Definition
resetTransitionState()
Return Values
tableinstanceInstance of object
Code
393function Chainsaw:resetTransitionState()
394 if (self.cameraTransitionState ~= Chainsaw.CAMERA_TRANSITION_STATES.NONE) then
395 self.cameraTransitionState = Chainsaw.CAMERA_TRANSITION_STATES.NONE
396 end
397end

updateCuttingCamera

Description
This function updates the timers: cuttimer and the outTimer, depending if the player is cutting or not: we switch from player camera to cutting camera as to not lose focus. We rotate the cutting camera towards the cut target. We the player has finished cutting we move the cutting camera towards the player camera and switch back to the player camera.
Definition
updateCuttingCamera(bool isCutting)
Arguments
boolisCuttingtrue if the player is cutting
Return Values
tableinstanceInstance of object
Code
402function Chainsaw:updateCuttingCamera(isCutting)
403 if isCutting then
404 if self.cameraTransitionState == Chainsaw.CAMERA_TRANSITION_STATES.IN then
405 setRotation(self.player.cuttingCameraNode, 0, 0, 0)
406 local yx, yy, yz = localDirectionToWorld(self.player.cuttingCameraNode, 0, 1, 0)
407 local zx, zy, zz = localDirectionToWorld(self.player.cuttingCameraNode, 0, 0, 1)
408 local startX, startY, startZ, _, _, _ = self:getCutStartEnd()
409
410 self.startCameraDirectionY = {yx, yy, yz}
411 self.startCameraDirectionZ = {zx, zy, zz}
412 self.endCameraDirectionY[1], self.endCameraDirectionY[2], self.endCameraDirectionY[3],
413 self.endCameraDirectionZ[1], self.endCameraDirectionZ[2], self.endCameraDirectionZ[3] = self:getLookAt(self.player.cuttingCameraNode, startX, startY, startZ)
414 elseif self.cameraTransitionState == Chainsaw.CAMERA_TRANSITION_STATES.CUT then
415 local startX, startY, startZ, endX, endY, endZ = self:getCutStartEnd()
416
417 self.startCameraDirectionY[1], self.startCameraDirectionY[2], self.startCameraDirectionY[3],
418 self.startCameraDirectionZ[1], self.startCameraDirectionZ[2], self.startCameraDirectionZ[3] = self:getLookAt(self.player.cuttingCameraNode, startX, startY, startZ)
419 self.endCameraDirectionY[1], self.endCameraDirectionY[2], self.endCameraDirectionY[3],
420 self.endCameraDirectionZ[1], self.endCameraDirectionZ[2], self.endCameraDirectionZ[3] = self:getLookAt(self.player.cuttingCameraNode, endX, endY, endZ)
421 end
422 else
423 if self.cameraTransitionState == Chainsaw.CAMERA_TRANSITION_STATES.OUT then
424 local yx, yy, yz = localDirectionToWorld(self.player.cuttingCameraNode, 0, 1, 0)
425 local zx, zy, zz = localDirectionToWorld(self.player.cuttingCameraNode, 0, 0, 1)
426 self.startCameraDirectionY = {yx, yy, yz}
427 self.startCameraDirectionZ = {zx, zy, zz}
428 setRotation(self.player.cuttingCameraNode, 0, 0, 0)
429 yx, yy, yz = localDirectionToWorld(self.player.cuttingCameraNode, 0, 1, 0)
430 zx, zy, zz = localDirectionToWorld(self.player.cuttingCameraNode, 0, 0, 1)
431 self.endCameraDirectionY = {yx, yy, yz}
432 self.endCameraDirectionZ = {zx, zy, zz}
433 end
434 end
435
436 local currentCamera = getCamera()
437 if isCutting or self.outTimer < self.outDuration then
438 if (currentCamera ~= self.player.cuttingCameraNode) then
439 g_currentMission:addSpecialCamera(self.player.cuttingCameraNode)
440 setCamera(self.player.cuttingCameraNode)
441 end
442
443 local smoothDirY = { MathUtil.lerp(self.startCameraDirectionY[1], self.endCameraDirectionY[1], self.transitionAlpha),
444 MathUtil.lerp(self.startCameraDirectionY[2], self.endCameraDirectionY[2], self.transitionAlpha),
445 MathUtil.lerp(self.startCameraDirectionY[3], self.endCameraDirectionY[3], self.transitionAlpha) }
446 local smoothDirZ = { MathUtil.lerp(self.startCameraDirectionZ[1], self.endCameraDirectionZ[1], self.transitionAlpha),
447 MathUtil.lerp(self.startCameraDirectionZ[2], self.endCameraDirectionZ[2], self.transitionAlpha),
448 MathUtil.lerp(self.startCameraDirectionZ[3], self.endCameraDirectionZ[3], self.transitionAlpha) }
449
450 smoothDirY = { worldDirectionToLocal(getParent(self.player.cuttingCameraNode), smoothDirY[1], smoothDirY[2], smoothDirY[3]) }
451 smoothDirZ = { worldDirectionToLocal(getParent(self.player.cuttingCameraNode), smoothDirZ[1], smoothDirZ[2], smoothDirZ[3]) }
452 local d,e,f = getWorldTranslation(self.player.chainsawSplitShapeFocus)
453 setDirection(self.player.cuttingCameraNode, smoothDirZ[1], smoothDirZ[2], smoothDirZ[3], smoothDirY[1], smoothDirY[2], smoothDirY[3])
454 else
455 if (currentCamera ~= self.player.cameraNode) then
456 setRotation(self.player.cuttingCameraNode, 0, 0, 0)
457 g_currentMission:removeSpecialCamera(self.player.cuttingCameraNode)
458 setCamera(self.player.cameraNode)
459 end
460 end
461end

updateChainsawModel

Description
Definition
updateChainsawModel(bool isCutting)
Arguments
boolisCutting
Return Values
tableinstanceInstance of object
Code
466function Chainsaw:updateChainsawModel(isCutting)
467 local currentPos = {getWorldTranslation(self.graphicsNode)}
468
469 if isCutting then
470 local startPos = {}
471 local endPos = {}
472 startPos[1], startPos[2], startPos[3], endPos[1], endPos[2], endPos[3] = self:getCutStartEnd()
473
474 if self.cameraTransitionState == Chainsaw.CAMERA_TRANSITION_STATES.IN then
475 self.startChainsawPosition = currentPos
476 self.endChainsawPosition = startPos
477 elseif self.cameraTransitionState == Chainsaw.CAMERA_TRANSITION_STATES.CUT then
478 self.startChainsawPosition = startPos
479 self.endChainsawPosition = endPos
480 end
481 else
482 if self.cameraTransitionState == Chainsaw.CAMERA_TRANSITION_STATES.OUT then
483 self.startChainsawPosition = currentPos
484 setTranslation(self.graphicsNode, 0, 0, 0)
485 self.endChainsawPosition = {getWorldTranslation(self.graphicsNode)}
486 end
487 end
488
489 if isCutting or self.outTimer < self.outDuration then
490 local smoothPosition = { MathUtil.lerp( self.startChainsawPosition[1], self.endChainsawPosition[1], self.transitionAlpha ),
491 MathUtil.lerp( self.startChainsawPosition[2], self.endChainsawPosition[2], self.transitionAlpha ),
492 MathUtil.lerp( self.startChainsawPosition[3], self.endChainsawPosition[3], self.transitionAlpha )}
493 local offset = {localToLocal(self.cutPositionNode, self.graphicsNode, 0,0,0)}
494 local cutDirection = {localDirectionToWorld(self.ringSelector, 0, 0, offset[3])}
495 local destination = {smoothPosition[1] - cutDirection[1], smoothPosition[2] - cutDirection[2], smoothPosition[3] - cutDirection[3]}
496 local modelTranslation = {worldToLocal(getParent(self.graphicsNode), destination[1], destination[2], destination[3])}
497 local distance = MathUtil.vector3Length(modelTranslation[1], modelTranslation[2], modelTranslation[3])
498
499 if distance > self.maxModelTranslation then
500 modelTranslation = {MathUtil.vector3Normalize(modelTranslation[1], modelTranslation[2], modelTranslation[3])}
501 modelTranslation = {modelTranslation[1]*self.maxModelTranslation, modelTranslation[2]*self.maxModelTranslation, modelTranslation[3]*self.maxModelTranslation}
502 local screen = { project(destination[1], destination[2], destination[3]) }
503 setTranslation(self.graphicsNode, modelTranslation[1], modelTranslation[2], modelTranslation[3])
504 local graph = {getWorldTranslation(self.graphicsNode)}
505 local screen2 = { project(graph[1], graph[2], graph[3]) }
506 local world2 = { unProject(screen[1], screen[2], screen2[3]) }
507
508 setWorldTranslation(self.graphicsNode, world2[1], world2[2], world2[3])
509 else
510 setTranslation(self.graphicsNode, modelTranslation[1], modelTranslation[2], modelTranslation[3])
511 end
512 else
513 setTranslation(self.graphicsNode, 0, 0, 0)
514 end
515end

getCutShapeInformation

Description
Preparing information for the splitShape methods
Definition
getCutShapeInformation(float x, float y, float z, float nx, float ny, float nz, float yx, float yy, float yz)
Arguments
floatx
floaty
floatz
floatnx
floatny
floatnz
floatyx
floatyy
floatyz
Return Values
tableinstanceInstance of object
Code
528function Chainsaw:getCutShapeInformation()
529 local x,y,z = getWorldTranslation(self.player.chainsawSplitShapeFocus)
530 local nx,ny,nz = localDirectionToWorld(self.player.chainsawSplitShapeFocus, 1,0,0)
531 local yx,yy,yz = localDirectionToWorld(self.player.chainsawSplitShapeFocus, 0,1,0)
532 return x, y, z, nx, ny, nz, yx, yy, yz
533end

update

Description
Update
Definition
update(float dt, boolean allowInput)
Arguments
floatdttime since last call in ms
booleanallowInputallow input
Return Values
tableinstanceinstance of object
Code
539function Chainsaw:update(dt, allowInput)
540 Chainsaw:superClass().update(self, dt, allowInput)
541
542 if self.isServer then
543 local price = self.pricePerSecond * (dt / 1000)
544 g_farmManager:getFarmById(self.player.farmId).stats:updateStats("expenses", price)
545 g_currentMission:addMoney(-price, self.player.farmId, "vehicleRunningCost")
546 end
547
548 if self.isClient then
549 if not self.isCutting then
550 self:updateCutRaycast()
551 end
552
553 if self.showNotOwnedWarning then
554 g_currentMission:showBlinkingWarning(g_i18n:getText("warning_youDontHaveAccessToThisLand"), 2000)
555 self.showNotOwnedWarning = false -- reset so it can be set to true later
556 end
557 end
558
559 self.shouldDelimb = false
560
561 local lockPlayerInput = false
562
563 if allowInput then
564 local isCutting = false
565 local hasBeenCut = false
566
567 setRotation(self.graphicsNode, math.rad(math.random(-1, 1)) * 0.1, math.rad(math.random(-1, 1)) * 0.1, math.rad(-180))
568
569 if self.curSplitShape == nil then
570 lockPlayerInput = self.rotateInput ~= 0
571
572 if self.rotateInput ~= 0 then
573 self.rotationZ = MathUtil.clamp(self.rotationZ + self.rotationSpeedZ * self.rotateInput * dt, self.maxRotationZ, self.minRotationZ )
574 setRotation(self.rootNode, self.handNodeRotation[1], self.handNodeRotation[2], self.handNodeRotation[3] + self.rotationZ)
575 setRotation(self.player.chainsawCameraFocus, 0, 0, -self.rotationZ)
576 end
577 end
578
579 local shape = 0
580 if not self.waitingForResetAfterCut then
581 if self.curSplitShape ~= nil or self.cutTimer == 0 then
582 local minY,maxY, minZ,maxZ
583 if self.curSplitShape == nil or not entityExists(self.curSplitShape) then
584 self.curSplitShape = nil
585
586 local x, y, z, nx, ny, nz, yx, yy, yz = self:getCutShapeInformation()
587 shape, minY, maxY, minZ, maxZ = findSplitShape(x, y, z, nx, ny, nz, yx, yy, yz, self.cutSizeY, self.cutSizeZ)
588
589 if shape ~= nil and shape ~= 0 then
590 if self:isCuttingAllowed(x, y, z) then
591 self.showNotOwnedWarning = false
592
593 local cutTooLow = self:testTooLow(shape, minY, maxY, minZ, maxZ)
594 local outsideRange = (self.cutFocusDistance < 0.0 or self.cutFocusDistance >= self.player.cutDetectionDistance)
595 if cutTooLow or outsideRange then
596 self.player.walkingIsLocked = false
597 self.curSplitShape = nil
598 shape, minY,maxY, minZ,maxZ = 0, nil,nil, nil,nil
599 end
600 else
601 self.showNotOwnedWarning = true
602 end
603 end
604 self.curSplitShapeMinY = minY
605 self.curSplitShapeMaxY = maxY
606 self.curSplitShapeMinZ = minZ
607 self.curSplitShapeMaxZ = maxZ
608 else
609 shape = self.curSplitShape
610 end
611
612 self:updateRingSelector(shape)
613 end
614 end
615
616 if self.activatePressed then
617 self.speedFactor = math.min(self.speedFactor + dt/self.maxWorkTime, 1)
618
619 if not self.waitingForResetAfterCut then
620 local inRange = (self.cutFocusDistance >= self.player.minCutDistance and self.cutFocusDistance < self.player.maxCutDistance)
621 self.shouldDelimb = inRange
622
623 if (self.curSplitShape ~= nil or self.cutTimer == 0) and inRange then
624 if self.curSplitShape ~= nil and entityExists(self.curSplitShape) then
625 lockPlayerInput = true
626 local x, y, z, nx, ny, nz, yx, yy, yz = self:getCutShapeInformation()
627 local minY, maxY, minZ, maxZ = testSplitShape(self.curSplitShape, x, y, z, nx, ny, nz, yx, yy, yz, self.cutSizeY, self.cutSizeZ)
628
629 if minY == nil then
630 -- cancel cutting if shape can't be cut anymore from current position
631 self.player.walkingIsLocked = false
632 self.curSplitShape = nil
633 else
634 local cutTooLow = self:testTooLow(self.curSplitShape, minY,maxY, minZ,maxZ)
635 if cutTooLow then
636 self.player.walkingIsLocked = false
637 self.curSplitShape = nil
638 end
639 end
640
641 self.curSplitShapeMinY = minY
642 self.curSplitShapeMaxY = maxY
643 self.curSplitShapeMinZ = minZ
644 self.curSplitShapeMaxZ = maxZ
645 else
646 if shape ~= 0 then
647 self.player.walkingIsLocked = true
648 self.curSplitShape = shape
649 end
650 end
651
652 if self.curSplitShape ~= nil then
653 local x,y,z, nx,ny,nz, yx,yy,yz = self:getCutShapeInformation()
654
655 if self:isCuttingAllowed(x, y, z) then
656 isCutting = true
657 end
658
659 if self.cutTimer > 0 then
660 self.lastWorkTime = math.min(self.lastWorkTime, self.maxWorkTime*0.7)
661 end
662
663 local cutDuration = self:calculateCutDuration()
664 if self.cutTimer >= cutDuration then
665 if g_currentMission:getIsServer() then
666 ChainsawUtil.cutSplitShape(self.curSplitShape, x, y, z, nx, ny, nz, yx, yy, yz, self.cutSizeY, self.cutSizeZ, self.player.farmId)
667 else
668 g_client:getServerConnection():sendEvent(ChainsawCutEvent:new(self.curSplitShape, x, y, z, nx, ny, nz, yx, yy, yz, self.cutSizeY, self.cutSizeZ, self.player.farmId))
669 end
670
671 hasBeenCut = true
672 self.waitingForResetAfterCut = true
673 self.player.walkingIsLocked = false
674 self.curSplitShape = nil
675 self.curSplitShapeMinY = nil
676 self:updateRingSelector(0)
677 end
678 end
679 end
680 end
681 else
682 self.speedFactor = math.max(self.speedFactor - dt / self.maxWorkTime, 0)
683 self.waitingForResetAfterCut = false
684 self.player.walkingIsLocked = false
685 self.curSplitShape = nil
686 self.curSplitShapeMinY = nil
687 self.lastWorkTime = math.max(self.lastWorkTime - dt, 0)
688 self.workUpPlayed = false
689 end
690
691 self.player:lockInput(lockPlayerInput)
692
693 self:updateCuttingTimers(dt, isCutting)
694 self:updateCuttingCamera(isCutting)
695 self:updateChainsawModel(isCutting)
696 self:updateDelimb()
697 self:setCutting(isCutting, self.rotationZ > 0.7, hasBeenCut)
698
699 self.soundFSM:update(dt)
700 end
701 self:updateParticles()
702
703 self.rotateInput = 0
704 self.activatePressed = false
705end

updateDelimb

Description
Update delimb mechanic (removing leaves, ...)
Definition
updateDelimb()
Return Values
booleantrueif loading was successful else false
Code
713function Chainsaw:updateDelimb()
714 if self.shouldDelimb then
715 local x,y,z = getWorldTranslation(self.player.chainsawSplitShapeFocus)
716 local nx,ny,nz = localDirectionToWorld(self.player.chainsawSplitShapeFocus, 1,0,0)
717 local yx,yy,yz = localDirectionToWorld(self.player.chainsawSplitShapeFocus, 0,1,0)
718 if g_server == nil then
719 g_client:getServerConnection():sendEvent(ChainsawDelimbEvent:new(self.player, x, y, z, nx, ny, nz, yx, yy, yz, false))
720 else
721 local ret = findAndRemoveSplitShapeAttachments(x, y, z, nx, ny, nz, yx, yy, yz, 0.7, self.cutSizeY, self.cutSizeZ)
722 if ret then
723 self:setOnDelimb(true)
724 end
725 end
726 end
727end

updateParticles

Description
Update particle system
Definition
updateParticles()
Return Values
tablethebrand object or nil of an error occured
Code
731function Chainsaw:updateParticles()
732 if self.particleSystems ~= nil then
733 local active = false
734 if self.isCutting and ((self.samplesBranchActiveTimer > g_currentMission.time) or (self.curSplitShapeMinY ~= nil and self.curSplitShapeMaxY ~= nil and self.cutTimer > self.inDuration)) then
735 active = true
736 end
737 if self.isCutting and not self.player.isEntered then
738 active = true
739 end
740 for _, ps in pairs(self.particleSystems) do
741 ParticleUtil.setEmittingState(ps, active)
742 end
743 end
744end

updateRingSelector

Description
Update ring selector
Definition
updateRingSelector(integer shape)
Arguments
integershape
Return Values
tablebrandthe brand object
Code
749function Chainsaw:updateRingSelector(shape)
750 if self.ringSelector ~= nil then
751 local hasShape = (shape ~= nil) and (shape ~= 0)
752
753 if g_woodCuttingMarkerEnabled and hasShape then
754 local inDetectionRange = false
755 local inCutRange = false
756
757 if self.cutFocusDistance ~= nil and (self.cutFocusDistance >= 0.0 and self.cutFocusDistance < self.player.cutDetectionDistance) then
758 inDetectionRange = true
759 inCutRange = (self.cutFocusDistance >= self.player.minCutDistance and self.cutFocusDistance < self.player.maxCutDistance)
760 end
761 if not getVisibility(self.ringSelector) and inDetectionRange then
762 local x, y, z = getWorldTranslation(self.ringSelector)
763 if self:isCuttingAllowed(x, y, z) then
764 setVisibility(self.ringSelector, true)
765 else
766 setVisibility(self.ringSelector, false)
767 end
768 elseif getVisibility(self.ringSelector) and not inDetectionRange then
769 setVisibility(self.ringSelector, false)
770 end
771
772 if getVisibility(self.ringSelector) then
773 if inCutRange then
774 setShaderParameter(self.ringSelector, "colorScale", 0.395, 0.925, 0.115, 1, false)
775 else
776 setShaderParameter(self.ringSelector, "colorScale", 0.098, 0.450, 0.960, 1, false)
777 end
778
779 if self.curSplitShapeMinY ~= nil then
780 local scale = math.max(self.curSplitShapeMaxY - self.curSplitShapeMinY + self.ringSelectorScaleOffset, self.curSplitShapeMaxZ-self.curSplitShapeMinZ + self.ringSelectorScaleOffset)
781 setScale(self.ringSelector, 1, scale, scale)
782
783 local a,b,c = localToWorld(self.player.chainsawSplitShapeFocus, 0, (self.curSplitShapeMinY+self.curSplitShapeMaxY)*0.5, (self.curSplitShapeMinZ+self.curSplitShapeMaxZ)*0.5)
784 local x, y, z = worldToLocal(getParent(self.ringSelector), a,b,c)
785 setTranslation(self.ringSelector, x,y,z)
786 else
787 setScale(self.ringSelector, 1, 1, 1)
788 end
789 end
790 elseif getVisibility(self.ringSelector) then
791 setVisibility(self.ringSelector, false)
792 end
793 end
794end

setCutting

Description
Set cutting
Definition
setCutting(boolean isCutting, boolean isHorizontalCut, boolean hasBeenCut, boolean noEventSend)
Arguments
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cut
booleanhasBeenCut
booleannoEventSendno event send
Return Values
tablebrandthe brand object
Code
802function Chainsaw:setCutting(isCutting, isHorizontalCut, hasBeenCut, noEventSend)
803 ChainsawStateEvent.sendEvent(self.player, isCutting, isHorizontalCut, hasBeenCut, noEventSend)
804 self.isCutting = isCutting
805 self.isHorizontalCut = isHorizontalCut
806 self.hasBeenCut = hasBeenCut
807
808 if not self.player.isOwner then
809 self.player:setCuttingAnim(isCutting, isHorizontalCut)
810 end
811end

setOnDelimb

Description
Set on delimb
Definition
setOnDelimb(boolean state)
Arguments
booleanstatenew state
Return Values
integerbrandIndexthe brand index
Code
816function Chainsaw:setOnDelimb(state)
817 if state == true then
818 end
819end

setHandNode

Description
Set hand node
Definition
setHandNode(integer handNode)
Arguments
integerhandNodehand node id
Return Values
booleantrueif storeitem is a vehicle, else false
Code
824function Chainsaw:setHandNode(handNode)
825 Chainsaw:superClass().setHandNode(self, handNode)
826 if self.currentHandNode ~= handNode then
827 link(handNode, self.rootNode)
828 self.currentHandNode = handNode
829 setRotation(self.rootNode, unpack(self.handNodeRotation))
830 local x, y, z = getWorldTranslation(self.handNode)
831 x, y, z = worldToLocal(getParent(self.rootNode), x, y, z)
832 local a, b, c = getTranslation(self.rootNode)
833 setTranslation(self.rootNode, a - x, b - y, c - z)
834 end
835end

onActivate

Description
On activate
Definition
onActivate(boolean allowInput)
Arguments
booleanallowInputallow input
Return Values
booleantrueif storeitem is an animal, else false
Code
844function Chainsaw:onActivate(allowInput)
845 Chainsaw:superClass().onActivate(self)
846
847 self.rotationZ = 0.0
848 setRotation(self.rootNode, self.handNodeRotation[1], self.handNodeRotation[2], self.handNodeRotation[3])
849 setRotation(self.player.chainsawCameraFocus, 0, 0, self.rotationZ)
850
851 self.startTime = g_currentMission.time
852 if not self.player.isOwner then
853 self.player.visualInformation:setProtectiveUV(self.equipmentUVs)
854 self.player:setWoodWorkVisibility(true)
855 end
856
857 if self.isClient then
858 g_animationManager:startAnimations(self.chains)
859 end
860
861 self.cutTimer = 0.0
862 setTranslation(self.graphicsNode, 0, 0, 0)
863
864 self.soundFSM:changeState(Chainsaw.SOUND_STATES.START)
865end

onDeactivate

Description
On deactivate
Definition
onDeactivate(boolean allowInput)
Arguments
booleanallowInputallow input
Return Values
booleantrueif storeitem is a placeable, else false
Code
870function Chainsaw:onDeactivate(allowInput)
871 Chainsaw:superClass().onDeactivate(self)
872
873 self.speedFactor = 0
874 self.curSplitShape = nil
875 self.player:lockInput(false)
876 self.player.walkingIsLocked = false
877 self.player:setWoodWorkVisibility(false)
878 if self.isClient then
879 g_animationManager:stopAnimations(self.chains)
880 self.cutTimer = 0.0
881 setTranslation(self.graphicsNode, 0, 0, 0)
882 if self.particleSystems ~= nil then
883 for _, ps in pairs(self.particleSystems) do
884 ParticleUtil.resetNumOfEmittedParticles(ps)
885 ParticleUtil.setEmittingState(ps, false)
886 end
887 end
888 if getVisibility(self.ringSelector) then
889 setVisibility(self.ringSelector, false)
890 end
891 end
892 self.soundFSM:changeState(Chainsaw.SOUND_STATES.STOP)
893end

registerActionEvents

Description
Definition
registerActionEvents()
Return Values
booleantrueif storeitem is an object, else false
Code
897function Chainsaw:registerActionEvents()
898 Chainsaw:superClass().registerActionEvents(self, allowInput)
899 local eventId = ""
900 _, eventId = g_inputBinding:registerActionEvent(InputAction.AXIS_ROTATE_HANDTOOL, self, self.onInputRotate, false, false, true, true)
901 g_inputBinding:setActionEventText(eventId, g_i18n:getText("action_rotate"))
902 self.eventIdRotateHandtool = eventId
903end

onInputRotate

Description
Event function for chainsaw rotation bound to InputAction.AXIS_ROTATE_HANDTOOL.
Definition
onInputRotate()
Return Values
booleantrueif storeitem is a handtool, else false
Code
907function Chainsaw:onInputRotate(_, inputValue)
908 self.rotateInput = self.rotateInput + inputValue
909end

ChainsawSoundStates

Description

Start:new

Description
Creating instance of sound state.
Definition
Start:new()
Return Values
integersharedVramUsagethe shared vram usage
integerperInstanceVramUsagethe per instance vram usage
booleanignoreVramUsagetrue if vram usage should be ignored else false
Code
18function ChainsawSoundStateStart:new(id, owner, stateMachine, custom_mt)
19 local self = SimpleState:new(id, owner, stateMachine, ChainsawSoundStateStart_mt)
20 return self
21end

Start:activate

Description
Activate method
Definition
Start:activate()
Code
25function ChainsawSoundStateStart:activate(parms)
26 ChainsawSoundStateStart:superClass().activate(self, parms)
27 g_soundManager:playSample(self.owner.samples.start)
28 self.stateMachine:changeState(Chainsaw.SOUND_STATES.IDLE)
29end

Stop:new

Description
Creating instance of sound state.
Definition
Stop:new()
Code
41function ChainsawSoundStateStop:new(id, owner, stateMachine, custom_mt)
42 local self = SimpleState:new(id, owner, stateMachine, ChainsawSoundStateStop_mt)
43 return self
44end

Stop:activate

Description
Activate method
Definition
Stop:activate()
Return Values
tableconfigurationsa list of configurations
Code
48function ChainsawSoundStateStop:activate(parms)
49 ChainsawSoundStateStop:superClass().activate(self, parms)
50 g_soundManager:playSample(self.owner.samples.stop)
51end

Idle:new

Description
Creating instance of sound state.
Definition
Idle:new()
Return Values
tableconfigurationsets
Code
63function ChainsawSoundStateIdle:new(id, owner, stateMachine, custom_mt)
64 local self = SimpleState:new(id, owner, stateMachine, ChainsawSoundStateIdle_mt)
65 self.activeTimer = 0.0
66 return self
67end

Idle:deactivate

Description
Deactivate method
Definition
Idle:deactivate()
Return Values
tableinstanceinstance of object
Code
71function ChainsawSoundStateIdle:deactivate()
72 ChainsawSoundStateIdle:superClass().deactivate(self)
73 g_soundManager:stopSample(self.owner.samples.idle)
74 self.activeTimer = 0.0
75end

Idle:update

Description
update method
Definition
Idle:update(float dt)
Arguments
floatdtin ms
Return Values
booleantrueif loading was successful else false
Code
80function ChainsawSoundStateIdle:update(dt)
81 ChainsawSoundStateIdle:superClass().update(self, dt)
82
83 if not g_soundManager:getIsSamplePlaying(self.owner.samples.start) and not g_soundManager:getIsSamplePlaying(self.owner.samples.idle) then
84 g_soundManager:playSample(self.owner.samples.idle)
85 end
86
87 if self.owner.isCutting then
88 self.stateMachine:changeState(Chainsaw.SOUND_STATES.CUT)
89 elseif self.owner.activatePressed then
90 self.activeTimer = self.activeTimer + dt
91
92 if self.activeTimer > self.owner.quicktapThreshold then
93 self.stateMachine:changeState(Chainsaw.SOUND_STATES.ACTIVE)
94 end
95 else
96 if self.activeTimer > 0.0 and self.activeTimer < self.owner.quicktapThreshold then
97 self.stateMachine:changeState(Chainsaw.SOUND_STATES.QUICKTAP)
98 end
99 end
100end

Active:new

Description
Creating instance of sound state.
Definition
Active:new()
Return Values
booleantrueif adding was successful else false
Code
112function ChainsawSoundStateActive:new(id, owner, stateMachine, custom_mt)
113 local self = SimpleState:new(id, owner, stateMachine, ChainsawSoundStateActive_mt)
114 return self
115end

Active:activate

Description
Activate method
Definition
Active:activate()
Return Values
tablecategorythe category object
Code
119function ChainsawSoundStateActive:activate(parms)
120 ChainsawSoundStateActive:superClass().activate(self, parms)
121 local shouldInitiateStart = false
122 shouldInitiateStart = not (parms ~= nil and parms.alreadyActive)
123 if shouldInitiateStart then
124 g_soundManager:playSample(self.owner.samples.activeStart)
125 end
126end

Active:deactivate

Description
Deactivate method
Definition
Active:deactivate()
Return Values
tablespecTypesa list of spec types
Code
130function ChainsawSoundStateActive:deactivate()
131 ChainsawSoundStateActive:superClass().deactivate(self)
132 g_soundManager:stopSample(self.owner.samples.activeStart)
133 g_soundManager:stopSample(self.owner.samples.activeLoop)
134end

Active:update

Description
update method
Definition
Active:update(float dt)
Arguments
floatdtin ms
Return Values
tablespecTypethe corresponding spectype
Code
139function ChainsawSoundStateActive:update(dt)
140 ChainsawSoundStateActive:superClass().update(self, dt)
141 if self.owner.isCutting then
142 local parms = {}
143 parms.alreadyActive = not g_soundManager:getIsSamplePlaying(self.owner.samples.activeStart)
144 self.stateMachine:changeState(Chainsaw.SOUND_STATES.CUT, parms)
145 elseif self.owner.activatePressed then
146 if not g_soundManager:getIsSamplePlaying(self.owner.samples.activeStart) and not g_soundManager:getIsSamplePlaying(self.owner.samples.activeLoop) then
147 g_soundManager:playSample(self.owner.samples.activeLoop)
148 end
149 else
150 self.stateMachine:changeState(Chainsaw.SOUND_STATES.IDLE)
151 g_soundManager:playSample(self.owner.samples.activeStop)
152 end
153end

Cut:new

Description
Creating instance of sound state.
Definition
Cut:new()
Return Values
booleanwasSuccessfulltrue if added else false
Code
165function ChainsawSoundStateCut:new(id, owner, stateMachine, custom_mt)
166 local self = SimpleState:new(id, owner, stateMachine, ChainsawSoundStateCut_mt)
167 return self
168end

Cut:activate

Description
Activate method
Definition
Cut:activate()
Return Values
tableitemsa list of all store items
Code
172function ChainsawSoundStateCut:activate(parms)
173 ChainsawSoundStateCut:superClass().activate(self, parms)
174 local shouldInitiateStart = false
175 shouldInitiateStart = not (parms ~= nil and parms.alreadyActive)
176 if shouldInitiateStart then
177 g_soundManager:playSample(self.owner.samples.cutStart)
178 end
179end

Cut:deactivate

Description
Deactivate method
Definition
Cut:deactivate()
Return Values
tablestoreItemthe storeitem oject
Code
183function ChainsawSoundStateCut:deactivate()
184 ChainsawSoundStateCut:superClass().deactivate(self)
185 g_soundManager:stopSample(self.owner.samples.cutStart)
186 g_soundManager:stopSample(self.owner.samples.cutLoop)
187end

Cut:update

Description
update method
Definition
Cut:update(float dt)
Arguments
floatdtin ms
Return Values
tablestoreItemthe storeitem object
Code
192function ChainsawSoundStateCut:update(dt)
193 ChainsawSoundStateCut:superClass().update(self, dt)
194 if not self.owner.isCutting then
195 if self.owner.activatePressed then
196 local parms = {}
197 parms.alreadyActive = not g_soundManager:getIsSamplePlaying(self.owner.samples.cutStart) or g_soundManager:getIsSamplePlaying(self.owner.samples.cutLoop)
198 self.stateMachine:changeState(Chainsaw.SOUND_STATES.ACTIVE, parms)
199 g_soundManager:playSample(self.owner.samples.cutStop)
200 else
201 self.stateMachine:changeState(Chainsaw.SOUND_STATES.IDLE)
202 g_soundManager:playSample(self.owner.samples.cutStop)
203 end
204 else
205 if not g_soundManager:getIsSamplePlaying(self.owner.samples.cutStart) and not g_soundManager:getIsSamplePlaying(self.owner.samples.cutLoop) then
206 g_soundManager:playSample(self.owner.samples.cutLoop)
207 end
208 end
209end

Quicktap:new

Description
Creating instance of sound state.
Definition
Quicktap:new()
Return Values
tablestoreItemthe storeitem object
Code
221function ChainsawSoundStateQuicktap:new(id, owner, stateMachine, custom_mt)
222 local self = SimpleState:new(id, owner, stateMachine, ChainsawSoundStateQuicktap_mt)
223 return self
224end

Quicktap:activate

Description
Activate method
Definition
Quicktap:activate()
Return Values
tablestoreItemthe storeitem object
Code
228function ChainsawSoundStateQuicktap:activate(parms)
229 ChainsawSoundStateQuicktap:superClass().activate(self, parms)
230
231 if self.owner.samplesQuicktapCount > 0 then
232 local idx = math.floor(math.random(1, self.owner.samplesQuicktapCount))
233 local sample = self.owner.samplesQuicktap[idx]
234 g_soundManager:playSample(sample)
235 end
236 self.stateMachine:changeState(Chainsaw.SOUND_STATES.IDLE)
237end

HandTool

Description
Class for handtools

registerHandTool

Description
Register handtool type
Definition
registerHandTool(string typeName, table classObject)
Arguments
stringtypeNamename of new type
tableclassObjectclass object
Return Values
tablesamplesample object

new

Description
Creating handtool object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
boolTrueif the definition and parameters are valid
boolTrueif an external XML file is loaded in place of the given parameter, caller must delete the handle afterwards!
intXMLfile handle, either the one passed in as an argument or an alternate external sound file definition which must be released by the caller
stringSounddefinition parent element key which may have changed according to an alternate external sound file definition
intLinknode target for spatial sound samples
tableinstanceInstance of object
Code
30function HandTool:new(isServer, isClient, customMt)
31 local mt = customMt
32 if mt == nil then
33 mt = HandTool_mt
34 end
35
36 local self = Object:new(isServer, isClient, mt)
37 self.static = true
38 self.player = nil
39 self.owner = nil
40 self.price = 0
41 self.age = 0
42 self.activatePressed = false
43 return self
44end

load

Description
Load chainsaw from xml file
Definition
load(string xmlFilename, table player)
Arguments
stringxmlFilenamexml file name
tableplayerplayer
Return Values
booleansuccesssuccess
Code
51function HandTool:load(xmlFilename, player)
52 self.configFileName = xmlFilename
53
54 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename)
55
56 local xmlFile = loadXMLFile("TempXML", xmlFilename)
57 if xmlFile == 0 then
58 return false
59 end
60 local i3dFilename = getXMLString(xmlFile, "handTool.filename")
61 self.position = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.position#value"), "0 0 0"), 3)
62 self.rotation = StringUtil.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.rotation#value"), "0 0 0"), 3)
63
64 if i3dFilename == nil then
65 delete(xmlFile)
66 return false
67 end
68 self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory)
69
70 local node = g_i3DManager:loadSharedI3DFile(self.i3dFilename)
71 self.rootNode = getChildAt(node, 0)
72 self.player = player
73
74 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
75 if self.price == 0 or self.price == nil then
76 self.price = StoreItemUtil.getDefaultPrice(storeItem)
77 end
78
79 if g_currentMission ~= nil and storeItem.canBeSold then
80 g_currentMission.environment:addDayChangeListener(self)
81 end
82
83 self.targets = {}
84 IKUtil.loadIKChainTargets(xmlFile, "handTool.targets", self.rootNode, self.targets, nil)
85
86 link(player.toolsRootNode, self.rootNode)
87 setTranslation(self.rootNode, self.position[1], self.position[2], self.position[3])
88 setRotation(self.rootNode, self.rotation[1], self.rotation[2], self.rotation[3])
89
90 delete(node)
91 delete(xmlFile)
92 setVisibility(self.rootNode, false)
93
94 self.isActive = false
95
96 return true
97end

delete

Description
Deleting handtool
Definition
delete()
Code
104function HandTool:delete()
105 self:removeActionEvents()
106
107 if g_currentMission ~= nil then
108 g_currentMission.environment:removeDayChangeListener(self)
109 end
110 if self.player.isOwner then
111 local farmId = self.player.farmId
112 local farm = g_farmManager:getFarmById(farmId)
113 if farm ~= nil then -- only remove from farm if it still exists (not the case when leaving a game)
114 farm:removeHandTool(self)
115 end
116 end
117 if self.rootNode ~= nil and self.rootNode ~= 0 then
118 g_i3DManager:releaseSharedI3DFile(self.i3dFilename, nil, true)
119 delete(self.rootNode)
120 end
121 HandTool:superClass().delete(self)
122end

onActivate

Description
On activate
Definition
onActivate(boolean allowInput)
Arguments
booleanallowInputallow input
Code
133function HandTool:onActivate(allowInput)
134 setVisibility(self.rootNode, true)
135 self.isActive = true
136 self:raiseActive()
137
138 if self.player.isOwner then
139 self:registerActionEvents()
140 end
141end

onDeactivate

Description
On deactivate
Definition
onDeactivate(boolean allowInput)
Arguments
booleanallowInputallow input
Code
146function HandTool:onDeactivate(allowInput)
147 setVisibility(self.rootNode, false)
148 self.isActive = false
149 self:removeActionEvents()
150end

getDailyUpkeep

Description
Get daily up keep
Definition
getDailyUpkeep()
Return Values
tablesamplesample object
floatdailyUpkeepdaily up keep
Code
163function HandTool:getDailyUpkeep()
164 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
165 local multiplier = 1
166
167 if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then
168 local ageMultiplier = math.min(self.age / storeItem.lifetime, 1)
169 multiplier = EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * ageMultiplier
170 end
171
172 return StoreItemUtil.getDailyUpkeep(storeItem, nil) * multiplier
173end

getSellPrice

Description
Get sell price
Definition
getSellPrice()
Return Values
booleanisPlayingtrue if sample is playing else false
floatsellPricesell price
Code
178function HandTool:getSellPrice()
179 local priceMultiplier = 0.5
180 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
181 local maxVehicleAge = storeItem.lifetime
182
183 if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then
184 priceMultiplier = priceMultiplier * math.exp(-3.5 * math.min(self.age/maxVehicleAge, 1))
185 end
186
187 return math.floor(self.price * math.max(priceMultiplier, 0.05))
188end

dayChanged

Description
Called if day changed
Definition
dayChanged()
Return Values
booleanisIndoortrue if indoor mode is active else false
Code
192function HandTool:dayChanged()
193 self.age = self.age + 1
194end

registerActionEvents

Description
Definition
registerActionEvents()
Return Values
booleanisIndoortrue if inside building mode is active else false
Code
198function HandTool:registerActionEvents()
199end

removeActionEvents

Description
Definition
removeActionEvents()
Return Values
floatfactorthe modifier factor
Code
203function HandTool:removeActionEvents()
204 g_inputBinding:removeActionEventsByTarget(self)
205end

HighPressureWasherLance

Description
Class for high pressure washer lance

new

Description
Definition
new()
Return Values
tableinstanceinstance of object
integergroupaudio group
Code
16function HighPressureWasherLance:new(isServer, isClient, customMt)
17 local self = HighPressureWasherLance:superClass().new(self, isServer, isClient, customMt or HighPressureWasherLance_mt)
18
19 self.foundVehicle = nil
20 self.doWashing = false
21 self.washDistance = 10.0
22 self.washMultiplier = 1.0
23 self.pricePerSecond = 10
24 self.isHPWLance = true
25
26 return self
27end

load

Description
Definition
load()
Code
31function HighPressureWasherLance:load(xmlFilename, player)
32 if not HighPressureWasherLance:superClass().load(self, xmlFilename, player) then
33 return false
34 end
35
36 -- Lance model
37 local xmlFile = loadXMLFile("TempXML", xmlFilename)
38 self.lanceNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.highPressureWasherLance.lance#node"))
39
40 local lancePosition = {}
41 local lanceRotation = {}
42 if self.player == g_currentMission.player then
43 lancePosition = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.highPressureWasherLance.lance.firstPerson#position"), "0 0 0"), 3)
44 lanceRotation = StringUtil.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.highPressureWasherLance.lance.firstPerson#rotation"), "0 0 0"), 3)
45 else
46 lancePosition = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.highPressureWasherLance.lance.thirdPerson#position"), "0 0 0"), 3)
47 lanceRotation = StringUtil.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.highPressureWasherLance.lance.thirdPerson#rotation"), "0 0 0"), 3)
48 end
49 self.lanceRaycastNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.highPressureWasherLance.lance#raycastNode"))
50 self.washDistance = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#washDistance"), 10)
51 self.washMultiplier = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#washMultiplier"), 1)
52 self.pricePerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#pricePerMinute"), 10) / 1000
53
54 setTranslation(self.rootNode, unpack(lancePosition))
55 setRotation(self.rootNode, unpack(lanceRotation))
56
57 self.effects = g_effectManager:loadEffect(xmlFile, "handTool.highPressureWasherLance.effects", self.rootNode, self)
58 g_effectManager:setFillType(self.effects, FillType.WATER)
59
60 -- Sounds
61 self.washingSample = g_soundManager:loadSampleFromXML(xmlFile, "handTool.highPressureWasherLance.sounds", "washing", self.baseDirectory, self.rootNode, 0, AudioGroup.VEHICLE, nil, self)
62
63 return true
64end

delete

Description
Deleting
Definition
delete()
Return Values
tableinstanceinstance of object
integergroupaudio group
Code
68function HighPressureWasherLance:delete()
69 g_effectManager:deleteEffects(self.effects)
70 g_soundManager:deleteSample(self.washingSample)
71 HighPressureWasherLance:superClass().delete(self)
72end

onDeactivate

Description
Definition
onDeactivate()
Code
76function HighPressureWasherLance:onDeactivate()
77 self:setIsWashing(false, true, true)
78 HighPressureWasherLance:superClass().onDeactivate(self)
79end

update

Description
Definition
update()
Return Values
tablenewLandscaping instance
Code
83function HighPressureWasherLance:update(dt, allowInput)
84 HighPressureWasherLance:superClass().update(self, dt)
85
86 if allowInput then
87 self:setIsWashing(self.activatePressed, false, false)
88 end
89
90 if self.isServer then
91 if self.doWashing then
92 self.foundVehicle = nil
93 self:cleanVehicle(self.player.cameraNode, dt)
94 if self.lanceRaycastNode ~= nil then
95 self:cleanVehicle(self.lanceRaycastNode, dt)
96 end
97 if self.foundVehicle ~= nil then
98 local farmId = self.foundVehicle:getOwnerFarmId()
99 local price = self.pricePerSecond * (dt / 1000)
100 local stats = g_farmManager:getFarmById(self.player.farmId).stats
101 stats:updateStats("expenses", price)
102 g_currentMission:addMoney(-price, farmId, "vehicleRunningCost")
103 end
104 end
105 end
106 self.activatePressed = false
107 self:raiseActive()
108end

setIsWashing

Description
Set is washing
Definition
setIsWashing(boolean doWashing, boolean force, boolean noEventSend)
Arguments
booleandoWashingdo washing
booleanforceforce
booleannoEventSendno event send
Return Values
tableNewLandscapingSculptEvent instance
Code
115function HighPressureWasherLance:setIsWashing(doWashing, force, noEventSend)
116 HPWLanceStateEvent.sendEvent(self.player, doWashing, noEventSend)
117 if self.doWashing ~= doWashing then
118 if doWashing then
119 g_effectManager:setFillType(self.effects, FillType.WATER)
120 g_effectManager:startEffects(self.effects)
121 g_soundManager:playSample(self.washingSample)
122 else
123 if force then
124 g_effectManager:resetEffects(self.effects)
125 else
126 g_effectManager:stopEffects(self.effects)
127 end
128 g_soundManager:stopSample(self.washingSample)
129 end
130 self.doWashing = doWashing
131 end
132end

cleanVehicle

Description
Clean vehicle
Definition
cleanVehicle(integer node, float dt)
Arguments
integernodenode id
floatdttime since last call in ms
Return Values
tableinstanceinstance of object
integergroupaudio group
Code
138function HighPressureWasherLance:cleanVehicle(node, dt)
139 local x, y, z = getWorldTranslation(node)
140 local dx, dy, dz = localDirectionToWorld(node, 0, 0, -1)
141 local lastFoundVehicle = self.foundVehicle
142 raycastAll(x, y, z, dx, dy, dz, "washRaycastCallback", self.washDistance, self, 32+64+128+256+4096+8194)
143
144 if self.foundVehicle ~= nil and lastFoundVehicle ~= self.foundVehicle then
145 self.foundVehicle:addDirtAmount(-self.washMultiplier * dt / self.foundVehicle:getWashDuration())
146 end
147end

washRaycastCallback

Description
Wash raycast callback
Definition
washRaycastCallback(integer hitActorId, float x, float y, float z, float distance, float nx, float ny, float nz, integer subShapeIndex, integer hitShapeId)
Arguments
integerhitActorIdid of hit object actor
floatxx raycast position
floatyy raycast position
floatzz raycast position
floatdistancedistance to raycast position
floatnxx component of hit surface normal (unused)
floatnyy component of hit surface normal (unused)
floatnzz component of hit surface normal (unused)
integersubShapeIndexsub shape index of hit object
integerhitShapeIdid of hit object shape
Code
161function HighPressureWasherLance:washRaycastCallback(hitActorId, x, y, z, distance, nx, ny, nz, subShapeIndex, hitShapeId)
162 local vehicle = g_currentMission.nodeToObject[hitActorId]
163 if hitActorId ~= hitShapeId then
164 -- object is a compoundChild. Try to find the compound
165 local parentId = hitShapeId
166 while parentId ~= 0 do
167 if g_currentMission.nodeToObject[parentId] ~= nil then
168 -- found valid compound
169 vehicle = g_currentMission.nodeToObject[parentId]
170 break
171 end
172 parentId = getParent(parentId)
173 end
174 end
175
176 if vehicle ~= nil and vehicle.getAllowsWashingByType ~= nil and vehicle:getAllowsWashingByType(Washable.WASHTYPE_HIGH_PRESSURE_WASHER) then
177 self.foundVehicle = vehicle
178 return false
179 end
180 return true
181end

getIsActiveForInput

Description
Get is active for input
Definition
getIsActiveForInput()
Return Values
booleanisActivateableis activateable
booleanisActiveForInputis active for input
Code
187function HighPressureWasherLance:getIsActiveForInput()
188 if self.player == g_currentMission.player and not g_gui:getIsGuiVisible() then
189 return true
190 end
191 return false
192end

AIConveyorBeltSetAngleEvent

Description
Event for conveyor belt angle

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIConveyorBeltSetAngleEvent:emptyNew()
16 local self = Event:new(AIConveyorBeltSetAngleEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, integer currentAngle)
Arguments
tablevehiclevehicle
integercurrentAnglecurrent angle
Code
24function AIConveyorBeltSetAngleEvent:new(vehicle, currentAngle)
25 local self = AIConveyorBeltSetAngleEvent:emptyNew()
26 self.currentAngle = currentAngle;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function AIConveyorBeltSetAngleEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId);
37 self.currentAngle = streamReadInt8(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function AIConveyorBeltSetAngleEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle);
47 streamWriteInt8(streamId, self.currentAngle);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function AIConveyorBeltSetAngleEvent:run(connection)
54 self.vehicle:setAIConveyorBeltAngle(self.currentAngle, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(AIConveyorBeltSetAngleEvent:new(self.vehicle, self.currentAngle), nil, connection, self.vehicle);
57 end;
58end;

AIVehicleIsBlockedEvent

Description
Event for ai block

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIVehicleIsBlockedEvent:emptyNew()
16 local self = Event:new(AIVehicleIsBlockedEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isBlocked)
Arguments
tableobjectobject
booleanisBlockedis blocked
Code
24function AIVehicleIsBlockedEvent:new(object, isBlocked)
25 local self = AIVehicleIsBlockedEvent:emptyNew()
26 self.object = object
27 self.isBlocked = isBlocked
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function AIVehicleIsBlockedEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId)
37 self.isBlocked = streamReadBool(streamId)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function AIVehicleIsBlockedEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object)
47 streamWriteBool(streamId, self.isBlocked)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function AIVehicleIsBlockedEvent:run(connection)
54 if self.object ~= nil then
55 if self.isBlocked then
56 self.object:aiBlock()
57 else
58 self.object:aiContinue()
59 end
60 end
61end

AIVehicleSetStartedEvent

Description
Event for ai start

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AIVehicleSetStartedEvent:emptyNew()
16 local self = Event:new(AIVehicleSetStartedEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, integer reason, boolean isStarted, integer helper)
Arguments
tableobjectobject
integerreasonreason
booleanisStartedis started
integerhelperhelper id
Code
26function AIVehicleSetStartedEvent:new(object, reason, isStarted, helper, startedFarmId)
27 local self = AIVehicleSetStartedEvent:emptyNew()
28 self.object = object
29 self.isStarted = isStarted
30 self.reason = reason
31 self.startedFarmId = startedFarmId
32 if helper ~= nil then
33 self.helperIndex = helper.index
34 end
35 return self
36end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function AIVehicleSetStartedEvent:readStream(streamId, connection)
43 self.object = NetworkUtil.readNodeObject(streamId)
44 self.isStarted = streamReadBool(streamId)
45
46 if not self.isStarted then
47 self.reason = streamReadUIntN(streamId, AIVehicle.NUM_BITS_REASONS)
48 else
49 self.helperIndex = streamReadUInt8(streamId)
50 end
51
52 self.startedFarmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
53
54 self:run(connection)
55end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
61function AIVehicleSetStartedEvent:writeStream(streamId, connection)
62 NetworkUtil.writeNodeObject(streamId, self.object)
63 streamWriteBool(streamId, self.isStarted)
64
65 if not self.isStarted then
66 streamWriteUIntN(streamId, self.reason, AIVehicle.NUM_BITS_REASONS)
67 else
68 streamWriteUInt8(streamId, self.helperIndex)
69 end
70
71 streamWriteUIntN(streamId, self.startedFarmId, FarmManager.FARM_ID_SEND_NUM_BITS)
72end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
77function AIVehicleSetStartedEvent:run(connection)
78 if self.isStarted then
79 self.object:startAIVehicle(self.helperIndex, true, self.startedFarmId)
80 else
81 self.object:stopAIVehicle(self.reason, true)
82 end
83 if not connection:getIsServer() then
84 for _, v in pairs(g_server.clientConnections) do
85 if v ~= connection and not v:getIsLocal() then
86 v:sendEvent(AIVehicleSetStartedEvent:new(self.object, self.reason, self.isStarted, g_helperManager:getHelperByIndex(self.helperIndex), self.startedFarmId))
87 end
88 end
89 end
90end

AnimatedVehicleStartEvent

Description
Event for animation start

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AnimatedVehicleStartEvent:emptyNew()
16 local self = Event:new(AnimatedVehicleStartEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, string name, float speed, float animTime)
Arguments
tableobjectobject
stringnamename of animation
floatspeedspeed of animation
floatanimTimetime of animation
Code
26function AnimatedVehicleStartEvent:new(object, name, speed, animTime)
27 local self = AnimatedVehicleStartEvent:emptyNew()
28 self.name = name;
29 self.speed = speed;
30 self.animTime = animTime;
31 self.object = object;
32 return self;
33end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
39function AnimatedVehicleStartEvent:readStream(streamId, connection)
40 self.object = NetworkUtil.readNodeObject(streamId);
41 self.name = streamReadString(streamId);
42 self.speed = streamReadFloat32(streamId);
43 self.animTime = streamReadFloat32(streamId);
44
45 self.object:playAnimation(self.name, self.speed, self.animTime, true);
46 if not connection:getIsServer() then
47 g_server:broadcastEvent(AnimatedVehicleStartEvent:new(self.object, self.name, self.speed, self.animTime), nil, connection, self.object);
48 end;
49end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
55function AnimatedVehicleStartEvent:writeStream(streamId, connection)
56 NetworkUtil.writeNodeObject(streamId, self.object);
57 streamWriteString(streamId, self.name);
58 streamWriteFloat32(streamId, self.speed);
59 streamWriteFloat32(streamId, self.animTime);
60end;

AnimatedVehicleStopEvent

Description
Event for animation stop

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function AnimatedVehicleStopEvent:emptyNew()
16 local self = Event:new(AnimatedVehicleStopEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, string name)
Arguments
tableobjectobject
stringnamename
Code
24function AnimatedVehicleStopEvent:new(object, name)
25 local self = AnimatedVehicleStopEvent:emptyNew()
26 self.name = name;
27 self.object = object;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function AnimatedVehicleStopEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.name = streamReadString(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function AnimatedVehicleStopEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteString(streamId, self.name);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function AnimatedVehicleStopEvent:run(connection)
54 AnimatedVehicle.stopAnimation(self.object, self.name, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(AnimatedVehicleStopEvent:new(self.object, self.name), nil, connection, self.object);
57 end;
58end;

BaleLoaderStateEvent

Description
Event for bale loader state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function BaleLoaderStateEvent:emptyNew()
16 local self = Event:new(BaleLoaderStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer stateId, integer nearestBaleServerId)
Arguments
tableobjectobject
integerstateIdstateId
integernearestBaleServerIdnearestBaleServerId
Code
25function BaleLoaderStateEvent:new(object, stateId, nearestBaleServerId)
26 local self = BaleLoaderStateEvent:emptyNew()
27 self.object = object;
28 self.stateId = stateId;
29 assert(nearestBaleServerId ~= nil or self.stateId ~= BaleLoader.CHANGE_GRAB_BALE);
30 self.nearestBaleServerId = nearestBaleServerId;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function BaleLoaderStateEvent:readStream(streamId, connection)
39 self.object = NetworkUtil.readNodeObject(streamId);
40
41 self.stateId = streamReadInt8(streamId);
42 if self.stateId == BaleLoader.CHANGE_GRAB_BALE then
43 self.nearestBaleServerId = NetworkUtil.readNodeObjectId(streamId);
44 end;
45 self:run(connection);
46end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function BaleLoaderStateEvent:writeStream(streamId, connection)
53 NetworkUtil.writeNodeObject(streamId, self.object);
54 streamWriteInt8(streamId, self.stateId);
55 if self.stateId == BaleLoader.CHANGE_GRAB_BALE then
56 NetworkUtil.writeNodeObjectId(streamId, self.nearestBaleServerId);
57 end;
58end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function BaleLoaderStateEvent:run(connection)
64 self.object:doStateChange(self.stateId, self.nearestBaleServerId);
65end;

BalerCreateBaleEvent

Description

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function BalerCreateBaleEvent:emptyNew()
15 local self = Event:new(BalerCreateBaleEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table object, integer baleFillType, float baleTime)
Arguments
tableobjectobject
integerbaleFillTypebale fill type
floatbaleTimebale time
Code
24function BalerCreateBaleEvent:new(object, baleFillType, baleTime)
25 local self = BalerCreateBaleEvent:emptyNew()
26 self.baleFillType = baleFillType;
27 self.baleTime = baleTime;
28 self.object = object;
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function BalerCreateBaleEvent:readStream(streamId, connection)
37 self.object = NetworkUtil.readNodeObject(streamId);
38 self.baleTime = streamReadFloat32(streamId);
39 self.baleFillType = streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS);
40 self:run(connection);
41end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
47function BalerCreateBaleEvent:writeStream(streamId, connection)
48 NetworkUtil.writeNodeObject(streamId, self.object);
49 streamWriteFloat32(streamId, self.baleTime);
50 streamWriteUIntN(streamId, self.baleFillType, FillTypeManager.SEND_NUM_BITS);
51end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
56function BalerCreateBaleEvent:run(connection)
57 self.object:createBale(self.baleFillType);
58 self.object:setBaleTime(table.getn(self.object.spec_baler.bales), self.baleTime);
59end;

BalerSetBaleTimeEvent

Description

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function BalerSetBaleTimeEvent:emptyNew()
15 local self = Event:new(BalerSetBaleTimeEvent_mt);
16 return self;
17end;

BalerSetBaleTimeEvent:new

Description
Create new instance of event
Definition
BalerSetBaleTimeEvent:new(table object, integer bale, float baleTime)
Arguments
tableobjectobject
integerbalebale id
floatbaleTimebale time
Code
24function BalerSetBaleTimeEvent:new(object, bale, baleTime)
25 local self = BalerSetBaleTimeEvent:emptyNew()
26 self.object = object;
27 self.bale = bale;
28 self.baleTime = baleTime;
29 return self;
30end;

BalerSetBaleTimeEvent:readStream

Description
Called on client side on join
Definition
BalerSetBaleTimeEvent:readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function BalerSetBaleTimeEvent:readStream(streamId, connection)
37 self.object = NetworkUtil.readNodeObject(streamId);
38 self.bale = streamReadInt32(streamId);
39 self.baleTime = streamReadFloat32(streamId);
40 self:run(connection);
41end;

BalerSetBaleTimeEvent:writeStream

Description
Called on server side on join
Definition
BalerSetBaleTimeEvent:writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
47function BalerSetBaleTimeEvent:writeStream(streamId, connection)
48 NetworkUtil.writeNodeObject(streamId, self.object);
49 streamWriteInt32(streamId, self.bale);
50 streamWriteFloat32(streamId, self.baleTime);
51end;

BalerSetBaleTimeEvent:run

Description
Run action on receiving side
Definition
BalerSetBaleTimeEvent:run(integer connection)
Arguments
integerconnectionconnection
Code
56function BalerSetBaleTimeEvent:run(connection)
57 self.object:setBaleTime(self.bale, self.baleTime);
58end;

BalerSetIsUnloadingBaleEvent

Description
Event for baler is unloading state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function BalerSetIsUnloadingBaleEvent:emptyNew()
16 local self = Event:new(BalerSetIsUnloadingBaleEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isUnloadingBale)
Arguments
tableobjectobject
booleanisUnloadingBaleis unloading bale
Code
24function BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale)
25 local self = BalerSetIsUnloadingBaleEvent:emptyNew()
26 self.object = object;
27 self.isUnloadingBale = isUnloadingBale;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function BalerSetIsUnloadingBaleEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.isUnloadingBale = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function BalerSetIsUnloadingBaleEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isUnloadingBale);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function BalerSetIsUnloadingBaleEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:setIsUnloadingBale(self.isUnloadingBale, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isUnloadingBale, boolean noEventSend)
Arguments
tableobjectobject
booleanisUnloadingBaleisUnloadingBale
booleannoEventSendno event send
Code
65function BalerSetIsUnloadingBaleEvent.sendEvent(object, isUnloadingBale, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(BalerSetIsUnloadingBaleEvent:new(object, isUnloadingBale));
71 end;
72 end;
73end;

BaleWrapperStateEvent

Description
Event for bale wrapper state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function BaleWrapperStateEvent:emptyNew()
16 local self = Event:new(BaleWrapperStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer stateId, integer nearestBaleServerId)
Arguments
tableobjectobject
integerstateIdstate id
integernearestBaleServerIdserver id of nearest bale
Code
25function BaleWrapperStateEvent:new(object, stateId, nearestBaleServerId)
26 local self = BaleWrapperStateEvent:emptyNew()
27 self.object = object;
28 self.stateId = stateId;
29 assert(nearestBaleServerId ~= nil or self.stateId ~= BaleWrapper.CHANGE_GRAB_BALE);
30 self.nearestBaleServerId = nearestBaleServerId;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function BaleWrapperStateEvent:readStream(streamId, connection)
39 self.object = NetworkUtil.readNodeObject(streamId);
40 self.stateId = streamReadInt8(streamId);
41 if self.stateId == BaleWrapper.CHANGE_GRAB_BALE then
42 self.nearestBaleServerId = NetworkUtil.readNodeObjectId(streamId);
43 end;
44 self:run(connection);
45end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
51function BaleWrapperStateEvent:writeStream(streamId, connection)
52 NetworkUtil.writeNodeObject(streamId, self.object);
53 streamWriteInt8(streamId, self.stateId);
54 if self.stateId == BaleWrapper.CHANGE_GRAB_BALE then
55 NetworkUtil.writeNodeObjectId(streamId, self.nearestBaleServerId);
56 end;
57end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function BaleWrapperStateEvent:run(connection)
63 self.object:doStateChange(self.stateId, self.nearestBaleServerId);
64end;

BunkerSiloCloseEvent

Description
Event for bunker silo close

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableinstanceinstance of event
tableselfinstance of class event
Code
13function BunkerSiloCloseEvent:emptyNew()
14 local self = Event:new(BunkerSiloCloseEvent_mt);
15 return self;
16end;

new

Description
Create new instance of event
Definition
new(table bunkerSilo)
Arguments
tablebunkerSilobunkerSilo
Return Values
tableselfinstance of class event
tableinstanceinstance of event
Code
22function BunkerSiloCloseEvent:new(bunkerSilo)
23 local self = BunkerSiloCloseEvent:emptyNew()
24 self.bunkerSilo = bunkerSilo;
25 return self;
26end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tableinstanceinstance of event
Code
32function BunkerSiloCloseEvent:readStream(streamId, connection)
33 if not connection:getIsServer() then
34 self.bunkerSilo = NetworkUtil.readNodeObject(streamId);
35 end;
36 self:run(connection);
37end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tableselfinstance of class event
Code
43function BunkerSiloCloseEvent:writeStream(streamId, connection)
44 if connection:getIsServer() then
45 NetworkUtil.writeNodeObject(streamId, self.bunkerSilo);
46 end;
47end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Return Values
tableinstanceinstance of event
Code
52function BunkerSiloCloseEvent:run(connection)
53 if not connection:getIsServer() then
54 self.bunkerSilo:setState(BunkerSilo.STATE_CLOSED);
55 end;
56end;

BunkerSiloOpenEvent

Description
Event for bunker silo open

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
tableselfinstance of class event
Code
13function BunkerSiloOpenEvent:emptyNew()
14 local self = Event:new(BunkerSiloOpenEvent_mt);
15 return self;
16end;

new

Description
Create new instance of event
Definition
new(table bunkerSilo, float x, float y, float z)
Arguments
tablebunkerSilobunkerSilo
floatxx opening position
floatyy opening position
floatzz opening position
Return Values
tableinstanceinstance of event
tableinstanceinstance of event
Code
25function BunkerSiloOpenEvent:new(bunkerSilo, x,y,z)
26 local self = BunkerSiloOpenEvent:emptyNew()
27 self.bunkerSilo = bunkerSilo;
28 self.x = x;
29 self.y = y;
30 self.z = z;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tableselfinstance of class event
Code
38function BunkerSiloOpenEvent:readStream(streamId, connection)
39 if not connection:getIsServer() then
40 self.bunkerSilo = NetworkUtil.readNodeObject(streamId);
41 self.x = streamReadFloat32(streamId);
42 self.y = streamReadFloat32(streamId);
43 self.z = streamReadFloat32(streamId);
44 end;
45 self:run(connection);
46end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tableinstanceinstance of event
Code
52function BunkerSiloOpenEvent:writeStream(streamId, connection)
53 if connection:getIsServer() then
54 NetworkUtil.writeNodeObject(streamId, self.bunkerSilo);
55 streamWriteFloat32(streamId, self.x);
56 streamWriteFloat32(streamId, self.y);
57 streamWriteFloat32(streamId, self.z);
58 end;
59end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Return Values
tablemotorInstancemotor instance
Code
64function BunkerSiloOpenEvent:run(connection)
65 if not connection:getIsServer() then
66 self.bunkerSilo:openSilo(self.x, self.y, self.z);
67 end;
68end;

ChainsawCutEvent

Description
Event for cutting

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
booleantrueif storeitem is configurable, else false
tableselfinstance of class event
Code
14function ChainsawCutEvent:emptyNew()
15 local self = Event:new(ChainsawCutEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(integer splitShapeId, float x, float y, float z, float nx, float ny, float nz, float yx, float yy, float yz, float cutSizeY, float cutSizeZ)
Arguments
integersplitShapeIdid of split shape
floatxx
floatyy
floatzz
floatnxnx
floatnyny
floatnznz
floatyxyx
floatyyyy
floatyzyz
floatcutSizeYy cut size
floatcutSizeZz cut size
Return Values
booleantrueif storeitem is leaseable, else false
tableinstanceinstance of event
Code
34function ChainsawCutEvent:new(splitShapeId, x,y,z, nx,ny,nz, yx,yy,yz, cutSizeY, cutSizeZ, farmId)
35 local self = ChainsawCutEvent:emptyNew()
36 self.splitShapeId = splitShapeId;
37 self.x,self.y,self.z = x,y,z;
38 self.nx,self.ny,self.nz = nx,ny,nz;
39 self.yx,self.yy,self.yz = yx,yy,yz;
40 self.cutSizeY,self.cutSizeZ = cutSizeY,cutSizeZ;
41 self.farmId = farmId
42 return self;
43end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
integerconfigIdthe default config id
Code
49function ChainsawCutEvent:readStream(streamId, connection)
50 if not connection:getIsServer() then
51 local splitShapeId = readSplitShapeIdFromStream(streamId);
52 local x = streamReadFloat32(streamId);
53 local y = streamReadFloat32(streamId);
54 local z = streamReadFloat32(streamId);
55 local nx = streamReadFloat32(streamId);
56 local ny = streamReadFloat32(streamId);
57 local nz = streamReadFloat32(streamId);
58 local yx = streamReadFloat32(streamId);
59 local yy = streamReadFloat32(streamId);
60 local yz = streamReadFloat32(streamId);
61 local cutSizeY = streamReadFloat32(streamId);
62 local cutSizeZ = streamReadFloat32(streamId);
63 local farmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
64
65 if splitShapeId ~= 0 then
66 ChainsawUtil.cutSplitShape(splitShapeId, x,y,z, nx,ny,nz, yx,yy,yz, cutSizeY, cutSizeZ, farmId);
67 end
68 end
69end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
integerthedefault price
Code
75function ChainsawCutEvent:writeStream(streamId, connection)
76 if connection:getIsServer() then
77 writeSplitShapeIdToStream(streamId, self.splitShapeId);
78 streamWriteFloat32(streamId, self.x);
79 streamWriteFloat32(streamId, self.y);
80 streamWriteFloat32(streamId, self.z);
81 streamWriteFloat32(streamId, self.nx);
82 streamWriteFloat32(streamId, self.ny);
83 streamWriteFloat32(streamId, self.nz);
84 streamWriteFloat32(streamId, self.yx);
85 streamWriteFloat32(streamId, self.yy);
86 streamWriteFloat32(streamId, self.yz);
87 streamWriteFloat32(streamId, self.cutSizeY);
88 streamWriteFloat32(streamId, self.cutSizeZ);
89 streamWriteFloat32(streamId, self.farmId)
90 end
91end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Return Values
integerthedaily upkeep
Code
96function ChainsawCutEvent:run(connection)
97 print("Error: ChainsawCutEvent is not allowed to be executed on a local client");
98end;

ChainsawDelimbEvent

Description
Event for delimb

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
integercostof the storeitem
tableselfinstance of class event
Code
14function ChainsawDelimbEvent:emptyNew()
15 local self = Event:new(ChainsawDelimbEvent_mt);
16 return self;
17end;

new

Description
Create new instance of event
Definition
new(table player, float x, float y, float z, float nx, float ny, float nz, float yx, float yy, float yz, boolean onDelimb)
Arguments
tableplayerplayer
floatxx
floatyy
floatzz
floatnxnx
floatnyny
floatnznz
floatyxyx
floatyyyy
floatyzyz
booleanonDelimbon delimb
Return Values
tableconfigobject
tableinstanceinstance of event
Code
33function ChainsawDelimbEvent:new(player, x,y,z, nx,ny,nz, yx,yy,yz, onDelimb)
34 local self = ChainsawDelimbEvent:emptyNew()
35 self.player = player;
36 self.x, self.y, self.z = x, y, z;
37 self.nx, self.ny, self.nz = nx, ny, nz;
38 self.yx, self.yy, self.yz = yx, yy, yz;
39 self.onDelimb = onDelimb;
40 return self;
41end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tablefunctionslist of storeitem functions
Code
47function ChainsawDelimbEvent:readStream(streamId, connection)
48 if not connection:getIsServer() then -- server side
49 self.player = NetworkUtil.readNodeObject(streamId);
50 self.x = streamReadFloat32(streamId);
51 self.y = streamReadFloat32(streamId);
52 self.z = streamReadFloat32(streamId);
53 self.nx = streamReadFloat32(streamId);
54 self.ny = streamReadFloat32(streamId);
55 self.nz = streamReadFloat32(streamId);
56 self.yx = streamReadFloat32(streamId);
57 self.yy = streamReadFloat32(streamId);
58 self.yz = streamReadFloat32(streamId);
59 self.onDelimb = false;
60 if self.player ~= nil then
61 local chainsaw = self.player.currentTool;
62 if chainsaw ~= nil then
63 local ret = findAndRemoveSplitShapeAttachments(self.x,self.y,self.z, self.nx,self.ny,self.nz, self.yx,self.yy,self.yz, 0.7, chainsaw.cutSizeY, chainsaw.cutSizeZ);
64 if ret then
65 self.onDelimb = true;
66 connection:sendEvent(self);
67 end;
68 end;
69 end;
70 else -- client side
71 self.player = NetworkUtil.readNodeObject(streamId);
72 self.onDelimb = streamReadBool(streamId);
73 if self.player ~= nil and self.player.currentTool ~= nil then
74 if self.player.currentTool.setOnDelimb ~= nil then
75 self.player.currentTool:setOnDelimb(self.onDelimb);
76 end;
77 end;
78 end
79end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tablespecslist of storeitem specs
Code
85function ChainsawDelimbEvent:writeStream(streamId, connection)
86 if connection:getIsServer() then -- client
87 NetworkUtil.writeNodeObject(streamId, self.player);
88 streamWriteFloat32(streamId, self.x);
89 streamWriteFloat32(streamId, self.y);
90 streamWriteFloat32(streamId, self.z);
91 streamWriteFloat32(streamId, self.nx);
92 streamWriteFloat32(streamId, self.ny);
93 streamWriteFloat32(streamId, self.nz);
94 streamWriteFloat32(streamId, self.yx);
95 streamWriteFloat32(streamId, self.yy);
96 streamWriteFloat32(streamId, self.yz);
97 else
98 NetworkUtil.writeNodeObject(streamId, self.player);
99 streamWriteBool(streamId, self.onDelimb);
100 end
101end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Return Values
integerbrandIndexthe brandindex
Code
106function ChainsawDelimbEvent:run(connection)
107 print("Error: ChainsawDelimbEvent is not allowed to be executed on a local client");
108end;

ChainsawStateEvent

Description
Event for chainsaw state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableinstanceinstance of object
tableselfinstance of class event
Code
14function ChainsawStateEvent:emptyNew()
15 local self = Event:new(ChainsawStateEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table player, boolean isCutting, boolean isHorizontalCut)
Arguments
tableplayerplayer
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cutting
Return Values
booleantrueif loading was successful else false
tableinstanceinstance of event
Code
25function ChainsawStateEvent:new(player, isCutting, isHorizontalCut, hasBeencut)
26 local self = ChainsawStateEvent:emptyNew()
27 self.player = player
28 self.isCutting = isCutting
29 self.isHorizontalCut = isHorizontalCut
30 self.hasBeenCut = hasBeencut
31 return self
32end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tableinstanceinstance of object
Code
38function ChainsawStateEvent:readStream(streamId, connection)
39 self.player = NetworkUtil.readNodeObject(streamId)
40 self.isCutting = streamReadBool(streamId)
41 self.isHorizontalCut = streamReadBool(streamId)
42 self.hasBeenCut = streamReadBool(streamId)
43 self:run(connection)
44end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
booleantrueif loading was successful else false
Code
50function ChainsawStateEvent:writeStream(streamId, connection)
51 NetworkUtil.writeNodeObject(streamId, self.player)
52 streamWriteBool(streamId, self.isCutting)
53 streamWriteBool(streamId, self.isHorizontalCut)
54 streamWriteBool(streamId, self.hasBeenCut)
55end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Return Values
booleantrueif loading was successful else false
Code
60function ChainsawStateEvent:run(connection)
61 if not connection:getIsServer() then
62 g_server:broadcastEvent(self, false, connection, self.player)
63 end
64
65 local currentTool = self.player.baseInformation.currentHandtool
66 if currentTool ~= nil and currentTool.setCutting ~= nil then
67 currentTool:setCutting(self.isCutting, self.isHorizontalCut, self.hasBeenCut, true)
68 end
69end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table player, boolean isCutting, boolean isHorizontalCut, boolean noEventSend)
Arguments
tableplayerplayer
booleanisCuttingis cutting
booleanisHorizontalCutis horizontal cutting
booleannoEventSendno event send
Return Values
tablesamplesample object
Code
77function ChainsawStateEvent.sendEvent(player, isCutting, isHorizontalCut, hasBeenCut, noEventSend)
78 local currentTool = player.baseInformation.currentHandtool
79 if currentTool ~= nil and currentTool.setCutting ~= nil and (currentTool.isCutting ~= isCutting or currentTool.hasBeenCut ~= hasBeenCut) then
80 if noEventSend == nil or noEventSend == false then
81 if g_server ~= nil then
82 g_server:broadcastEvent(ChainsawStateEvent:new(player, isCutting, isHorizontalCut, hasBeenCut), nil, nil, player)
83 else
84 g_client:getServerConnection():sendEvent(ChainsawStateEvent:new(player, isCutting, isHorizontalCut, hasBeenCut))
85 end
86 end
87 end
88end

CombineStrawEnableEvent

Description
Event for straw enable state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function CombineStrawEnableEvent:emptyNew()
16 local self = Event:new(CombineStrawEnableEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isSwathActive)
Arguments
tablevehiclevehicle
booleanisSwathActiveis straw enabled
Code
24function CombineStrawEnableEvent:new(vehicle, isSwathActive)
25 local self = CombineStrawEnableEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.isSwathActive = isSwathActive;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function CombineStrawEnableEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId);
37 self.isSwathActive = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function CombineStrawEnableEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle);
47 streamWriteBool(streamId, self.isSwathActive);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function CombineStrawEnableEvent:run(connection)
54 self.vehicle:setIsSwathActive(self.isSwathActive, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(CombineStrawEnableEvent:new(self.vehicle, self.isSwathActive), nil, connection, self.vehicle);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isSwathActive, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisSwathActiveis straw enabled
booleannoEventSendno event send
Code
65function CombineStrawEnableEvent.sendEvent(vehicle, isSwathActive, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(CombineStrawEnableEvent:new(vehicle, isSwathActive), nil, nil, vehicle);
69 else
70 g_client:getServerConnection():sendEvent(CombineStrawEnableEvent:new(vehicle, isSwathActive));
71 end;
72 end;
73end;

CylinderedEasyControlChangeEvent

Description
Event for straw enable state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function CylinderedEasyControlChangeEvent:emptyNew()
16 local self = Event:new(CylinderedEasyControlChangeEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isEasyControlActive)
Arguments
tablevehiclevehicle
booleanisEasyControlActiveis easy control enabled
Code
24function CylinderedEasyControlChangeEvent:new(vehicle, isEasyControlActive)
25 local self = CylinderedEasyControlChangeEvent:emptyNew()
26 self.vehicle = vehicle
27 self.isEasyControlActive = isEasyControlActive
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function CylinderedEasyControlChangeEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId)
37 self.isEasyControlActive = streamReadBool(streamId)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function CylinderedEasyControlChangeEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle)
47 streamWriteBool(streamId, self.isEasyControlActive)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function CylinderedEasyControlChangeEvent:run(connection)
54 if self.vehicle ~= nil then
55 self.vehicle:setIsEasyControlActive(self.isEasyControlActive, true)
56 end
57 if not connection:getIsServer() then
58 g_server:broadcastEvent(CylinderedEasyControlChangeEvent:new(self.vehicle, self.isEasyControlActive), nil, connection, self.vehicle)
59 end
60end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isEasyControlActive, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisEasyControlActiveis easy control enabled
booleannoEventSendno event send
Code
67function CylinderedEasyControlChangeEvent.sendEvent(vehicle, isEasyControlActive, noEventSend)
68 if noEventSend == nil or noEventSend == false then
69 if g_server ~= nil then
70 g_server:broadcastEvent(CylinderedEasyControlChangeEvent:new(vehicle, isEasyControlActive), nil, nil, vehicle)
71 elseif g_client ~= nil then
72 g_client:getServerConnection():sendEvent(CylinderedEasyControlChangeEvent:new(vehicle, isEasyControlActive))
73 end
74 end
75end

DrivableToggleLowerAllEvent

Description
Event for toggle lower all

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function DrivableToggleLowerAllEvent:emptyNew()
16 local self = Event:new(DrivableToggleLowerAllEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle)
Arguments
tablevehiclevehicle
Code
23function DrivableToggleLowerAllEvent:new(vehicle)
24 local self = DrivableToggleLowerAllEvent:emptyNew()
25 self.vehicle = vehicle;
26 return self;
27end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function DrivableToggleLowerAllEvent:readStream(streamId, connection)
34 self.vehicle = NetworkUtil.readNodeObject(streamId);
35 self:run(connection);
36end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function DrivableToggleLowerAllEvent:writeStream(streamId, connection)
43 NetworkUtil.writeNodeObject(streamId, self.vehicle);
44end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
49function DrivableToggleLowerAllEvent:run(connection)
50 self.vehicle:toggleLowerAllImplements(true);
51 if not connection:getIsServer() then
52 g_server:broadcastEvent(DrivableToggleLowerAllEvent:new(self.vehicle), nil, connection, self.object);
53 end;
54end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean noEventSend)
Arguments
tablevehiclevehicle
booleannoEventSendno event send
Code
60function DrivableToggleLowerAllEvent.sendEvent(vehicle, noEventSend)
61 if noEventSend == nil or noEventSend == false then
62 if g_server ~= nil then
63 g_server:broadcastEvent(DrivableToggleLowerAllEvent:new(vehicle), nil, nil, vehicle);
64 else
65 g_client:getServerConnection():sendEvent(DrivableToggleLowerAllEvent:new(vehicle));
66 end;
67 end;
68end;

FillUnitUnloadEvent

Description
Event for turned on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function FillUnitUnloadEvent:emptyNew()
16 local self = Event:new(FillUnitUnloadEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object)
Arguments
tableobjectobject
Code
23function FillUnitUnloadEvent:new(object)
24 local self = FillUnitUnloadEvent:emptyNew()
25 self.object = object
26 return self
27end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function FillUnitUnloadEvent:readStream(streamId, connection)
39 if not connection:getIsServer() then
40 self.object = NetworkUtil.readNodeObject(streamId)
41 end
42 self:run(connection)
43end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
49function FillUnitUnloadEvent:writeStream(streamId, connection)
50 if connection:getIsServer() then
51 NetworkUtil.writeNodeObject(streamId, self.object)
52 end
53end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
58function FillUnitUnloadEvent:run(connection)
59 if not connection:getIsServer() then
60 if self.object ~= nil then
61 local success = self.object:unloadFillUnits(true)
62 if not success then
63 connection:sendEvent(FillUnitUnloadEvent:newServerToClient())
64 end
65 end
66 else
67 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_INFO, g_i18n:getText("fillUnit_unload_nospace"))
68 end
69end

FoldableSetFoldDirectionEvent

Description
Event for set folding direction

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function FoldableSetFoldDirectionEvent:emptyNew()
16 local self = Event:new(FoldableSetFoldDirectionEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer direction, boolean moveToMiddle)
Arguments
tableobjectobject
integerdirectiondirection
booleanmoveToMiddlemove to middle
Code
25function FoldableSetFoldDirectionEvent:new(object, direction, moveToMiddle)
26 local self = FoldableSetFoldDirectionEvent:emptyNew()
27 self.object = object;
28 self.direction = MathUtil.sign(direction);
29 self.moveToMiddle = moveToMiddle;
30 return self;
31end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function FoldableSetFoldDirectionEvent:readStream(streamId, connection)
38 self.object = NetworkUtil.readNodeObject(streamId);
39 self.direction = streamReadUIntN(streamId, 2)-1;
40 self.moveToMiddle = streamReadBool(streamId);
41 self:run(connection);
42end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function FoldableSetFoldDirectionEvent:writeStream(streamId, connection)
49 NetworkUtil.writeNodeObject(streamId, self.object);
50 streamWriteUIntN(streamId, self.direction+1, 2);
51 streamWriteBool(streamId, self.moveToMiddle);
52end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
57function FoldableSetFoldDirectionEvent:run(connection)
58 if self.object ~= nil then
59 self.object:setFoldState(self.direction, self.moveToMiddle, true);
60 end;
61 if not connection:getIsServer() then
62 g_server:broadcastEvent(FoldableSetFoldDirectionEvent:new(self.object, self.direction, self.moveToMiddle), nil, connection, self.object);
63 end;
64end;

GreenhouseSetIsWaterTankFillingEvent

Description
Event for greenhouse tank filling state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function GreenhouseSetIsWaterTankFillingEvent:emptyNew()
16 local self = Event:new(GreenhouseSetIsWaterTankFillingEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isFilling, table trailer)
Arguments
tableobjectobject
booleanisFillingis filling
tabletrailertrailer
Return Values
tableinstanceinstance of event
Code
26function GreenhouseSetIsWaterTankFillingEvent:new(object, isFilling, trailer)
27 local self = GreenhouseSetIsWaterTankFillingEvent:emptyNew()
28 self.object = object;
29 self.isFilling = isFilling;
30 self.trailer = trailer;
31 return self;
32end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function GreenhouseSetIsWaterTankFillingEvent:readStream(streamId, connection)
39 self.object = NetworkUtil.readNodeObject(streamId);
40 self.isFilling = streamReadBool(streamId);
41 if self.isFilling and not connection:getIsServer() then
42 self.trailer = NetworkUtil.readNodeObject(streamId);
43 end;
44 self:run(connection);
45end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
51function GreenhouseSetIsWaterTankFillingEvent:writeStream(streamId, connection)
52 NetworkUtil.writeNodeObject(streamId, self.object);
53 streamWriteBool(streamId, self.isFilling);
54 if self.isFilling and connection:getIsServer() then
55 NetworkUtil.writeNodeObject(streamId, self.trailer);
56 end;
57end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function GreenhouseSetIsWaterTankFillingEvent:run(connection)
63 if not connection:getIsServer() then
64 g_server:broadcastEvent(self, false, connection, self.object);
65 end;
66 self.object:setIsWaterTankFilling(self.isFilling, self.trailer, true);
67end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isFilling, table trailer, boolean noEventSend)
Arguments
tableobjectobject
booleanisFillingis filling
tabletrailertrailer
booleannoEventSendno event send
Code
75function GreenhouseSetIsWaterTankFillingEvent.sendEvent(object, isFilling, trailer, noEventSend)
76 if isFilling ~= object.isWaterTankFilling then
77 if noEventSend == nil or noEventSend == false then
78 if g_server ~= nil then
79 g_server:broadcastEvent(GreenhouseSetIsWaterTankFillingEvent:new(object, isFilling, trailer), nil, nil, object);
80 else
81 assert(not isFilling or (trailer ~= nil));
82 g_client:getServerConnection():sendEvent(GreenhouseSetIsWaterTankFillingEvent:new(object, isFilling, trailer));
83 end;
84 end;
85 end;
86end;

HonkEvent

Description
Event for honking

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function HonkEvent:emptyNew()
16 local self = Event:new(HonkEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isPlaying)
Arguments
tableobjectobject
booleanisPlayinghonk is playing
Code
24function HonkEvent:new(object, isPlaying)
25 local self = HonkEvent:emptyNew()
26 self.object = object;
27 self.isPlaying = isPlaying;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function HonkEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.isPlaying = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function HonkEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isPlaying);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function HonkEvent:run(connection)
54 self.object:playHonk(self.isPlaying, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(HonkEvent:new(self.object, self.isPlaying), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isPlaying, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisPlayinghonk is playing
booleannoEventSendno event send
Code
65function HonkEvent.sendEvent(vehicle, isPlaying, noEventSend)
66 if vehicle.spec_honk ~= nil and vehicle.spec_honk.isPlaying ~= isPlaying then
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(HonkEvent:new(vehicle, isPlaying), nil, nil, vehicle);
70 else
71 g_client:getServerConnection():sendEvent(HonkEvent:new(vehicle, isPlaying));
72 end;
73 end;
74 end;
75end;

HPWLanceStateEvent

Description
Event for hpw state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableinstanceinstance of object
integergroupaudio group
tableselfinstance of class event
Code
15function HPWLanceStateEvent:emptyNew()
16 local self = Event:new(HPWLanceStateEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean doWashing)
Arguments
tableobjectobject
booleandoWashingdo washing
Return Values
tableinstanceinstance of event
Code
25function HPWLanceStateEvent:new(player, doWashing)
26 local self = HPWLanceStateEvent:emptyNew()
27 self.player = player
28 self.doWashing = doWashing
29 return self
30end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
tableinstanceinstance of basket trigger object
Code
36function HPWLanceStateEvent:readStream(streamId, connection)
37 self.player = NetworkUtil.readNodeObject(streamId)
38 self.doWashing = streamReadBool(streamId)
39 self:run(connection)
40end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Return Values
booleansuccesssuccess
Code
46function HPWLanceStateEvent:writeStream(streamId, connection)
47 NetworkUtil.writeNodeObject(streamId, self.player)
48 streamWriteBool(streamId, self.doWashing)
49end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Return Values
tableselfreturns the instance
Code
54function HPWLanceStateEvent:run(connection)
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(self, false, connection, self.player)
57 end
58 local currentTool = self.player.baseInformation.currentHandtool
59 if currentTool ~= nil and currentTool.setIsWashing ~= nil then
60 currentTool:setIsWashing(self.doWashing, false, true)
61 end
62end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean doWashing, boolean noEventSend)
Arguments
tableobjectobject
booleandoWashingdo washing
booleannoEventSendno event send
Return Values
booltrueif level has changed
Code
69function HPWLanceStateEvent.sendEvent(player, doWashing, noEventSend)
70 local currentTool = player.baseInformation.currentHandtool
71 if currentTool ~= nil and currentTool.setIsWashing ~= nil and doWashing ~= currentTool.doWashing then
72 if noEventSend == nil or noEventSend == false then
73 if g_server ~= nil then
74 g_server:broadcastEvent(HPWLanceStateEvent:new(player, doWashing), nil, nil, player)
75 else
76 g_client:getServerConnection():sendEvent(HPWLanceStateEvent:new(player, doWashing))
77 end
78 end
79 end
80end

HPWPlaceableTurnOnEvent

Description
Event for hpw turn on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function HPWPlaceableTurnOnEvent:emptyNew()
16 local self = Event:new(HPWPlaceableTurnOnEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isTurnedOn, table player)
Arguments
tableobjectobject
booleanisTurnedOnis turned on
tableplayerplayer
Return Values
tableinstanceinstance of event
Code
26function HPWPlaceableTurnOnEvent:new(object, isTurnedOn, player)
27 local self = HPWPlaceableTurnOnEvent:emptyNew()
28 self.object = object
29 self.isTurnedOn = isTurnedOn
30 self.player = player
31
32 return self
33end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
39function HPWPlaceableTurnOnEvent:readStream(streamId, connection)
40 self.object = NetworkUtil.readNodeObject(streamId)
41 self.isTurnedOn = streamReadBool(streamId)
42 if self.isTurnedOn then
43 self.player = NetworkUtil.readNodeObject(streamId)
44 end
45 self:run(connection)
46end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function HPWPlaceableTurnOnEvent:writeStream(streamId, connection)
53 NetworkUtil.writeNodeObject(streamId, self.object)
54 streamWriteBool(streamId, self.isTurnedOn)
55 if self.isTurnedOn then
56 NetworkUtil.writeNodeObject(streamId, self.player)
57 end
58end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function HPWPlaceableTurnOnEvent:run(connection)
64 if not connection:getIsServer() then
65 g_server:broadcastEvent(self, false, connection, self.object)
66 end
67 self.object:setIsTurnedOn(self.isTurnedOn, self.player, true)
68end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isTurnedOn, table player, boolean noEventSend)
Arguments
tableobjectobject
booleanisTurnedOnis turned on
tableplayerplayer
booleannoEventSendno event send
Code
76function HPWPlaceableTurnOnEvent.sendEvent(object, isTurnedOn, player, noEventSend)
77 if isTurnedOn ~= object.isTurnedOn then
78 if noEventSend == nil or noEventSend == false then
79 if g_server ~= nil then
80 g_server:broadcastEvent(HPWPlaceableTurnOnEvent:new(object, isTurnedOn, player), nil, nil, object)
81 else
82 g_client:getServerConnection():sendEvent(HPWPlaceableTurnOnEvent:new(object, isTurnedOn, player))
83 end
84 end
85 end
86end

JumpEvent

Description
Event for honking

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function JumpEvent:emptyNew()
16 local self = Event:new(JumpEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isPlaying)
Arguments
tableobjectobject
booleanisPlayinghonk is playing
Code
24function JumpEvent:new(object)
25 local self = JumpEvent:emptyNew()
26 self.object = object
27 return self
28end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
34function JumpEvent:readStream(streamId, connection)
35 if not connection:getIsServer() then
36 self.object = NetworkUtil.readNodeObject(streamId)
37 self:run(connection)
38 end
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function JumpEvent:writeStream(streamId, connection)
46 if connection:getIsServer() then
47 NetworkUtil.writeNodeObject(streamId, self.object)
48 end
49end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function JumpEvent:run(connection)
55 self.object:jump(true)
56end

MixerWagonBaleNotAcceptedEvent

Description
Event for honking

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function MixerWagonBaleNotAcceptedEvent:emptyNew()
16 local self = Event:new(MixerWagonBaleNotAcceptedEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle)
Arguments
tablevehiclevehicle
Code
23function MixerWagonBaleNotAcceptedEvent:new(vehicle)
24 local self = MixerWagonBaleNotAcceptedEvent:emptyNew()
25 self.vehicle = vehicle
26 return self
27end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function MixerWagonBaleNotAcceptedEvent:readStream(streamId, connection)
34 self.vehicle = NetworkUtil.readNodeObject(streamId)
35 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_CRITICAL, g_i18n:getText("warning_baleNotSupported"))
36end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function MixerWagonBaleNotAcceptedEvent:writeStream(streamId, connection)
43 NetworkUtil.writeNodeObject(streamId, self.vehicle)
44end

MowerToggleWindrowDropEvent

Description
Event for mower toggle drop

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function MowerToggleWindrowDropEvent:emptyNew()
16 local self = Event:new(MowerToggleWindrowDropEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean useMowerWindrowDropAreas)
Arguments
tableobjectobject
booleanuseMowerWindrowDropAreasuse mower windrow drop areas
Code
24function MowerToggleWindrowDropEvent:new(object, useMowerWindrowDropAreas)
25 local self = MowerToggleWindrowDropEvent:emptyNew()
26 self.object = object;
27 self.useMowerWindrowDropAreas = useMowerWindrowDropAreas;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function MowerToggleWindrowDropEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.useMowerWindrowDropAreas = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function MowerToggleWindrowDropEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.useMowerWindrowDropAreas);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function MowerToggleWindrowDropEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setUseMowerWindrowDropAreas(self.useMowerWindrowDropAreas, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean useMowerWindrowDropAreas, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanuseMowerWindrowDropAreasuse mower windrow drop areas
booleannoEventSendno event send
Code
67function MowerToggleWindrowDropEvent.sendEvent(vehicle, useMowerWindrowDropAreas, noEventSend)
68 if useMowerWindrowDropAreas ~= vehicle.useMowerWindrowDropAreas then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(MowerToggleWindrowDropEvent:new(vehicle, useMowerWindrowDropAreas), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(MowerToggleWindrowDropEvent:new(vehicle, useMowerWindrowDropAreas));
74 end;
75 end;
76 end;
77end;

PickupSetStateEvent

Description
Event for lower and lift pickup

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PickupSetStateEvent:emptyNew()
16 local self = Event:new(PickupSetStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isPickupLowered)
Arguments
tableobjectobject
booleanisPickupLoweredis pickup lowered
Code
24function PickupSetStateEvent:new(object, isPickupLowered)
25 local self = PickupSetStateEvent:emptyNew()
26 self.object = object;
27 self.isPickupLowered = isPickupLowered;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PickupSetStateEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.isPickupLowered = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PickupSetStateEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isPickupLowered);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PickupSetStateEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setPickupState(self.isPickupLowered, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isPickupLowered, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisPickupLoweredis pickup lowered
booleannoEventSendno event send
Code
67function PickupSetStateEvent.sendEvent(vehicle, isPickupLowered, noEventSend)
68 if isPickupLowered ~= vehicle.spec_pickup.isLowered then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(PickupSetStateEvent:new(vehicle, isPickupLowered), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(PickupSetStateEvent:new(vehicle, isPickupLowered));
74 end;
75 end;
76 end;
77end;

PlantLimitToFieldEvent

Description
Event for limit to field state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PlantLimitToFieldEvent:emptyNew()
16 local self = Event:new(PlantLimitToFieldEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean plantLimitToField)
Arguments
tableobjectobject
booleanplantLimitToFieldplant is limited to field
Code
24function PlantLimitToFieldEvent:new(object, plantLimitToField)
25 local self = PlantLimitToFieldEvent:emptyNew()
26 self.object = object;
27 self.plantLimitToField = plantLimitToField;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PlantLimitToFieldEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.plantLimitToField = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PlantLimitToFieldEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.plantLimitToField);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PlantLimitToFieldEvent:run(connection)
54 self.object:setPlantLimitToField(self.plantLimitToField, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(PlantLimitToFieldEvent:new(self.object, self.plantLimitToField), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isPickupLowered, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisPickupLoweredis pickup lowered
booleannoEventSendno event send
Code
65function PlantLimitToFieldEvent.sendEvent(vehicle, plantLimitToField, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(PlantLimitToFieldEvent:new(vehicle, plantLimitToField), nil, nil, vehicle);
69 else
70 g_client:getServerConnection():sendEvent(PlantLimitToFieldEvent:new(vehicle, plantLimitToField));
71 end;
72 end;
73end;

PlayerPermissionsEvent

Description

sendEvent

Description
Create an instance
Definition
sendEvent(table player, integer farmId, bool noEventSend)
Arguments
tableplayerplayer instance
integerfarmIdfarm identification
boolnoEventSendif false will send the event
Code
88function PlayerPermissionsEvent.sendEvent(userId, permissions, isFarmManager, noEventSend)
89 if noEventSend == nil or noEventSend == false then
90 local event = PlayerPermissionsEvent:new(userId, permissions, isFarmManager)
91
92 if g_server ~= nil then
93 local farm = g_farmManager:getFarmByUserId(userId)
94 local player = farm.userIdToPlayer[userId]
95
96 g_server:broadcastEvent(event, nil, nil, player)
97 else
98 g_client:getServerConnection():sendEvent(event)
99 end
100 end
101end

PlowLimitToFieldEvent

Description
Event for limit to field state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PlowLimitToFieldEvent:emptyNew()
16 local self = Event:new(PlowLimitToFieldEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean plowLimitToField)
Arguments
tableobjectobject
booleanplowLimitToFieldplow is limited to field
Code
24function PlowLimitToFieldEvent:new(object, plowLimitToField)
25 local self = PlowLimitToFieldEvent:emptyNew()
26 self.object = object;
27 self.plowLimitToField = plowLimitToField;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PlowLimitToFieldEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.plowLimitToField = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PlowLimitToFieldEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.plowLimitToField);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PlowLimitToFieldEvent:run(connection)
54 self.object:setPlowLimitToField(self.plowLimitToField, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(PlowLimitToFieldEvent:new(self.object, self.plowLimitToField), nil, connection, self.object);
57 end;
58end;

PlowRotationEvent

Description
Event for plow rotation

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function PlowRotationEvent:emptyNew()
16 local self = Event:new(PlowRotationEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean rotationMax)
Arguments
tableobjectobject
booleanrotationMaxrotation max
Code
24function PlowRotationEvent:new(object, rotationMax)
25 local self = PlowRotationEvent:emptyNew()
26 self.object = object;
27 self.rotationMax = rotationMax;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function PlowRotationEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.rotationMax = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function PlowRotationEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.rotationMax);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function PlowRotationEvent:run(connection)
54 self.object:setRotationMax(self.rotationMax, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(PlowRotationEvent:new(self.object, self.rotationMax), nil, connection, self.object);
57 end;
58end;

ReceivingHopperSetCreateBoxesEvent

Description
Event for toggle box creation

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function ReceivingHopperSetCreateBoxesEvent:emptyNew()
16 local self = Event:new(ReceivingHopperSetCreateBoxesEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean state)
Arguments
tableobjectobject
booleanstatestate
Code
24function ReceivingHopperSetCreateBoxesEvent:new(object, state)
25 local self = ReceivingHopperSetCreateBoxesEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function ReceivingHopperSetCreateBoxesEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.state = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function ReceivingHopperSetCreateBoxesEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.state);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function ReceivingHopperSetCreateBoxesEvent:run(connection)
54 self.object:setCreateBoxes(self.state, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(ReceivingHopperSetCreateBoxesEvent:new(self.object, self.state), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean state, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanstatestate
booleannoEventSendno event send
Code
65function ReceivingHopperSetCreateBoxesEvent.sendEvent(vehicle, state, noEventSend)
66 if state ~= vehicle.state then
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(ReceivingHopperSetCreateBoxesEvent:new(vehicle, state), nil, nil, vehicle);
70 else
71 g_client:getServerConnection():sendEvent(ReceivingHopperSetCreateBoxesEvent:new(vehicle, state));
72 end;
73 end;
74 end;
75end;

ReverseDrivingSetStateEvent

Description
Event for reverse driving state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function ReverseDrivingSetStateEvent:emptyNew()
16 local self = Event:new(ReverseDrivingSetStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isReverseDriving)
Arguments
tablevehiclevehicle
booleanisReverseDrivingis reverse driving
Code
24function ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving)
25 local self = ReverseDrivingSetStateEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.isReverseDriving = isReverseDriving;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function ReverseDrivingSetStateEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId);
37 self.isReverseDriving = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function ReverseDrivingSetStateEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle);
47 streamWriteBool(streamId, self.isReverseDriving);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function ReverseDrivingSetStateEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.vehicle);
56 end;
57 if self.vehicle ~= nil then
58 self.vehicle:setIsReverseDriving(self.isReverseDriving, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isReverseDriving, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisReverseDrivingis reverse driving
booleannoEventSendno event send
Code
67function ReverseDrivingSetStateEvent.sendEvent(vehicle, isReverseDriving, noEventSend)
68 if isReverseDriving ~= vehicle.isReverseDriving then
69 if noEventSend == nil or noEventSend == false then
70 if g_server ~= nil then
71 g_server:broadcastEvent(ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving), nil, nil, vehicle);
72 else
73 g_client:getServerConnection():sendEvent(ReverseDrivingSetStateEvent:new(vehicle, isReverseDriving));
74 end;
75 end;
76 end;
77end;

RidgeMarkerSetStateEvent

Description
Event for ridge marker state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function RidgeMarkerSetStateEvent:emptyNew()
16 local self = Event:new(RidgeMarkerSetStateEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle, boolean state)
Arguments
tablevehiclevehicle
booleanstatestate
Code
24function RidgeMarkerSetStateEvent:new(vehicle, state)
25 local self = RidgeMarkerSetStateEvent:emptyNew()
26 self.vehicle = vehicle
27 self.state = state
28 assert(state >= 0 and state < RidgeMarker.MAX_NUM_RIDGEMARKERS)
29 return self
30end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function RidgeMarkerSetStateEvent:readStream(streamId, connection)
37 self.vehicle = NetworkUtil.readNodeObject(streamId)
38 self.state = streamReadUIntN(streamId, RidgeMarker.SEND_NUM_BITS)
39 self:run(connection)
40end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function RidgeMarkerSetStateEvent:writeStream(streamId, connection)
47 NetworkUtil.writeNodeObject(streamId, self.vehicle)
48 streamWriteUIntN(streamId, self.state, RidgeMarker.SEND_NUM_BITS)
49end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function RidgeMarkerSetStateEvent:run(connection)
55 self.vehicle:setRidgeMarkerState(self.state, true)
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(RidgeMarkerSetStateEvent:new(self.vehicle, self.state), nil, connection, self.vehicle)
58 end
59end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer state, boolean noEventSend)
Arguments
tablevehiclevehicle
integerstatedischarge state
booleannoEventSendno event send
Code
66function RidgeMarkerSetStateEvent.sendEvent(vehicle, state, noEventSend)
67 if noEventSend == nil or noEventSend == false then
68 if g_server ~= nil then
69 g_server:broadcastEvent(RidgeMarkerSetStateEvent:new(vehicle, state), nil, nil, self)
70 else
71 g_client:getServerConnection():sendEvent(RidgeMarkerSetStateEvent:new(vehicle, state))
72 end
73 end
74end

SetCoverStateEvent

Description
Event for cover state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCoverStateEvent:emptyNew()
16 return Event:new(SetCoverStateEvent_mt)
17end

new

Description
Create new instance of event
Definition
new(table vehicle, integer state)
Arguments
tablevehiclevehicle
integerstatecover state
Code
23function SetCoverStateEvent:new(vehicle, state)
24 local self = SetCoverStateEvent:emptyNew()
25
26 self.vehicle = vehicle
27 self.state = state
28
29 return self
30end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function SetCoverStateEvent:readStream(streamId, connection)
37 self.vehicle = NetworkUtil.readNodeObject(streamId)
38 self.state = streamReadUIntN(streamId, Cover.SEND_NUM_BITS)
39 self:run(connection)
40end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function SetCoverStateEvent:writeStream(streamId, connection)
47 NetworkUtil.writeNodeObject(streamId, self.vehicle)
48 streamWriteUIntN(streamId, self.state, Cover.SEND_NUM_BITS)
49end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function SetCoverStateEvent:run(connection)
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(self, false, connection, self.vehicle)
57 end
58 if self.vehicle ~= nil then
59 self.vehicle:setCoverState(self.state, true)
60 end
61end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer state, boolean noEventSend)
Arguments
tablevehiclevehicle
integerstatecover state
booleannoEventSendno event send
Code
68function SetCoverStateEvent.sendEvent(vehicle, state, noEventSend)
69 if vehicle.spec_cover.state ~= state then
70 if noEventSend == nil or noEventSend == false then
71 if g_server ~= nil then
72 g_server:broadcastEvent(SetCoverStateEvent:new(vehicle, state), nil, nil, vehicle)
73 else
74 g_client:getServerConnection():sendEvent(SetCoverStateEvent:new(vehicle, state))
75 end
76 end
77 end
78end

SetCrabSteeringEvent

Description
Event for steering mode

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCrabSteeringEvent:emptyNew()
16 local self = Event:new(SetCrabSteeringEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer state)
Arguments
tableobjectobject
integerstatestate
Code
24function SetCrabSteeringEvent:new(vehicle, state)
25 local self = SetCrabSteeringEvent:emptyNew()
26 self.vehicle = vehicle;
27 self.state = state;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCrabSteeringEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId);
37 self.state = streamReadUIntN(streamId, CrabSteering.STEERING_SEND_NUM_BITS);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCrabSteeringEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle);
47 streamWriteUIntN(streamId, self.state, CrabSteering.STEERING_SEND_NUM_BITS);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCrabSteeringEvent:run(connection)
54 self.vehicle:setCrabSteering(self.state, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(SetCrabSteeringEvent:new(self.vehicle, self.state), nil, connection, self.object);
57 end;
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer state, boolean noEventSend)
Arguments
tablevehiclevehicle
integerstatestate
booleannoEventSendno event send
Code
65function SetCrabSteeringEvent.sendEvent(vehicle, state, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(SetCrabSteeringEvent:new(vehicle, state), nil, nil, vehicle);
69 else
70 g_client:getServerConnection():sendEvent(SetCrabSteeringEvent:new(vehicle, state));
71 end;
72 end;
73end;

SetCruiseControlSpeedEvent

Description
Event for cruise control speed

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCruiseControlSpeedEvent:emptyNew()
16 local self = Event:new(SetCruiseControlSpeedEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, float speed)
Arguments
tablevehiclevehicle
floatspeedspeed
Code
24function SetCruiseControlSpeedEvent:new(vehicle, speed)
25 local self = SetCruiseControlSpeedEvent:emptyNew()
26 self.speed = speed;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCruiseControlSpeedEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId);
37 self.speed = streamReadUInt8(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCruiseControlSpeedEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle);
47 streamWriteUInt8(streamId, self.speed);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCruiseControlSpeedEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.vehicle);
56 end;
57 self.vehicle:setCruiseControlMaxSpeed(self.speed);
58end;

SetCruiseControlStateEvent

Description
Event for cruise control state event

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetCruiseControlStateEvent:emptyNew()
16 local self = Event:new(SetCruiseControlStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table vehicle, integer state)
Arguments
tablevehiclevehicle
integerstatestate
Code
24function SetCruiseControlStateEvent:new(vehicle, state)
25 local self = SetCruiseControlStateEvent:emptyNew()
26 self.state = state;
27 self.vehicle = vehicle;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetCruiseControlStateEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId);
37 self.state = streamReadUIntN(streamId, 2);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetCruiseControlStateEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle);
47 streamWriteUIntN(streamId, self.state, 2);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetCruiseControlStateEvent:run(connection)
54 self.vehicle:setCruiseControlState(self.state, true);
55end;

SetDischargeStateEvent

Description
Event for dicharge state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetDischargeStateEvent:emptyNew()
16 local self = Event:new(SetDischargeStateEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle, integer state)
Arguments
tablevehiclevehicle
integerstatedischarge state
Code
24function SetDischargeStateEvent:new(vehicle, state)
25 local self = SetDischargeStateEvent:emptyNew()
26 self.vehicle = vehicle
27 self.state = state
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetDischargeStateEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId)
37 self.state = streamReadUIntN(streamId, 2)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetDischargeStateEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle)
47 streamWriteUIntN(streamId, self.state, 2)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetDischargeStateEvent:run(connection)
54 self.vehicle:setDischargeState(self.state, true)
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(SetDischargeStateEvent:new(self.vehicle, self.state), nil, connection, self.vehicle)
57 end
58end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer state, boolean noEventSend)
Arguments
tablevehiclevehicle
integerstatedischarge state
booleannoEventSendno event send
Code
65function SetDischargeStateEvent.sendEvent(vehicle, state, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(SetDischargeStateEvent:new(vehicle, state), nil, nil, vehicle)
69 else
70 g_client:getServerConnection():sendEvent(SetDischargeStateEvent:new(vehicle, state))
71 end
72 end
73end

SetFillUnitIsFillingEvent

Description
Event for toggle filling

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetFillUnitIsFillingEvent:emptyNew()
16 local self = Event:new(SetFillUnitIsFillingEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isFilling)
Arguments
tablevehiclevehicle
booleanisFillingis filling state
Code
24function SetFillUnitIsFillingEvent:new(vehicle, isFilling)
25 local self = SetFillUnitIsFillingEvent:emptyNew()
26 self.vehicle = vehicle
27 self.isFilling = isFilling
28 return self
29end

readStream

Description
Called on client side
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetFillUnitIsFillingEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId)
37 self.isFilling = streamReadBool(streamId)
38 self:run(connection)
39end

writeStream

Description
Called on server side
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetFillUnitIsFillingEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle)
47 streamWriteBool(streamId, self.isFilling)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetFillUnitIsFillingEvent:run(connection)
54 self.vehicle:setFillUnitIsFilling(self.isFilling, true)
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(SetFillUnitIsFillingEvent:new(self.vehicle, self.isFilling), nil, connection, self.vehicle)
57 end
58end

SetMotorTurnedOnEvent

Description
Event for motor turned on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetMotorTurnedOnEvent:emptyNew()
16 local self = Event:new(SetMotorTurnedOnEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean turnedOn)
Arguments
tableobjectobject
booleanturnedOnis turned on
Code
24function SetMotorTurnedOnEvent:new(object, turnedOn)
25 local self = SetMotorTurnedOnEvent:emptyNew()
26 self.object = object;
27 self.turnedOn = turnedOn;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetMotorTurnedOnEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.turnedOn = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetMotorTurnedOnEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.turnedOn);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetMotorTurnedOnEvent:run(connection)
54 if self.turnedOn then
55 self.object:startMotor(true);
56 else
57 self.object:stopMotor(true);
58 end;
59 if not connection:getIsServer() then
60 g_server:broadcastEvent(SetMotorTurnedOnEvent:new(self.object, self.turnedOn), nil, connection, self.object);
61 end;
62end;

SetPipeStateEvent

Description
Event for pipe state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetPipeStateEvent:emptyNew()
16 local self = Event:new(SetPipeStateEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer pipeState)
Arguments
tableobjectobject
integerpipeStatepipe state
Code
24function SetPipeStateEvent:new(object, pipeState)
25 local self = SetPipeStateEvent:emptyNew()
26 self.object = object;
27 self.pipeState = pipeState;
28 assert(self.pipeState >= 0 and self.pipeState < 8);
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function SetPipeStateEvent:readStream(streamId, connection)
37 self.object = NetworkUtil.readNodeObject(streamId);
38 self.pipeState = streamReadUIntN(streamId, 3);
39 self:run(connection);
40end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function SetPipeStateEvent:writeStream(streamId, connection)
47 NetworkUtil.writeNodeObject(streamId, self.object);
48 streamWriteUIntN(streamId, self.pipeState, 3);
49end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function SetPipeStateEvent:run(connection)
55 self.object:setPipeState(self.pipeState, true);
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(SetPipeStateEvent:new(self.object, self.pipeState), nil, connection, self.object);
58 end;
59end;

SetSeedIndexEvent

Description
Set seed index event

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetSeedIndexEvent:emptyNew()
16 local self = Event:new(SetSeedIndexEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, integer seedIndex)
Arguments
tableobjectobject
integerseedIndexindex of seed
Code
24function SetSeedIndexEvent:new(object, seedIndex)
25 local self = SetSeedIndexEvent:emptyNew()
26 self.object = object
27 self.seedIndex = seedIndex
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetSeedIndexEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId)
37 self.seedIndex = streamReadUInt8(streamId)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetSeedIndexEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object)
47 streamWriteUInt8(streamId, self.seedIndex)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetSeedIndexEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object)
56 end
57 self.object:setSeedIndex(self.seedIndex, true)
58end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, integer seedIndex, boolean noEventSend)
Arguments
tableobjectobject
integerseedIndexindex of seed
booleannoEventSendno event send
Code
65function SetSeedIndexEvent.sendEvent(object, seedIndex, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(SetSeedIndexEvent:new(object, seedIndex), nil, nil, object)
69 else
70 g_client:getServerConnection():sendEvent(SetSeedIndexEvent:new(object, seedIndex))
71 end
72 end
73end

SetTurnedOnEvent

Description
Event for turned on state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetTurnedOnEvent:emptyNew()
16 local self = Event:new(SetTurnedOnEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isTurnedOn)
Arguments
tableobjectobject
booleanisTurnedOnis turned on state
Code
24function SetTurnedOnEvent:new(object, isTurnedOn)
25 local self = SetTurnedOnEvent:emptyNew()
26 self.object = object;
27 self.isTurnedOn = isTurnedOn;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetTurnedOnEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.isTurnedOn = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetTurnedOnEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.isTurnedOn);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetTurnedOnEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 if self.object ~= nil then
58 self.object:setIsTurnedOn(self.isTurnedOn, true);
59 end;
60end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, boolean isTurnedOn, boolean noEventSend)
Arguments
tableobjectobject
booleanisTurnedOnis turned on state
booleannoEventSendno event send
Code
67function SetTurnedOnEvent.sendEvent(vehicle, isTurnedOn, noEventSend)
68 if noEventSend == nil or noEventSend == false then
69 if g_server ~= nil then
70 g_server:broadcastEvent(SetTurnedOnEvent:new(vehicle, isTurnedOn), nil, nil, vehicle);
71 else
72 g_client:getServerConnection():sendEvent(SetTurnedOnEvent:new(vehicle, isTurnedOn));
73 end;
74 end;
75end;

SetWorkModeEvent

Description
Event for work modes

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function SetWorkModeEvent:emptyNew()
16 local self = Event:new(SetWorkModeEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, integer state)
Arguments
tableobjectobject
integerstatestate
Code
24function SetWorkModeEvent:new(vehicle, state)
25 local self = SetWorkModeEvent:emptyNew()
26 self.vehicle = vehicle
27 self.state = state
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function SetWorkModeEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId)
37 self.state = streamReadUIntN(streamId, WorkMode.WORKMODE_SEND_NUM_BITS)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function SetWorkModeEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle)
47 streamWriteUIntN(streamId, self.state, WorkMode.WORKMODE_SEND_NUM_BITS)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function SetWorkModeEvent:run(connection)
54 self.vehicle:setWorkMode(self.state, true)
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(SetWorkModeEvent:new(self.vehicle, self.state), nil, connection, self.object)
57 end
58end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer state, boolean noEventSend)
Arguments
tablevehiclevehicle
integerstatestate
booleannoEventSendno event send
Code
65function SetWorkModeEvent.sendEvent(vehicle, state, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(SetWorkModeEvent:new(vehicle, state), nil, nil, vehicle)
69 else
70 g_client:getServerConnection():sendEvent(SetWorkModeEvent:new(vehicle, state))
71 end
72 end
73end

TensionBeltsEvent

Description
Event for tension belts state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TensionBeltsEvent:emptyNew()
16 local self = Event:new(TensionBeltsEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isActive, integer beltId)
Arguments
tableobjectobject
booleanisActivebelt is active
integerbeltIdid of belt
Code
25function TensionBeltsEvent:new(object, isActive, beltId)
26 local self = TensionBeltsEvent:emptyNew()
27 self.object = object
28 self.isActive = isActive
29 self.beltId = beltId
30 return self
31end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function TensionBeltsEvent:readStream(streamId, connection)
38 self.object = NetworkUtil.readNodeObject(streamId);
39 if not streamReadBool(streamId) then
40 self.beltId = streamReadUIntN(streamId, TensionBelts.NUM_SEND_BITS)+1
41 end
42 self.isActive = streamReadBool(streamId)
43 self:run(connection)
44end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
50function TensionBeltsEvent:writeStream(streamId, connection)
51 NetworkUtil.writeNodeObject(streamId, self.object)
52 streamWriteBool(streamId, self.beltId == nil)
53 if self.beltId ~= nil then
54 streamWriteUIntN(streamId, self.beltId-1, TensionBelts.NUM_SEND_BITS)
55 end
56 streamWriteBool(streamId, self.isActive)
57end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function TensionBeltsEvent:run(connection)
63 if not connection:getIsServer() then
64 g_server:broadcastEvent(self, false, connection, self.object)
65 end
66 self.object:setTensionBeltsActive(self.isActive, self.beltId, true)
67end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isActive, integer beltId, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisActivebelt is active
integerbeltIdid of belt
booleannoEventSendno event send
Code
75function TensionBeltsEvent.sendEvent(vehicle, isActive, beltId, noEventSend)
76 if noEventSend == nil or noEventSend == false then
77 if g_server ~= nil then
78 g_server:broadcastEvent(TensionBeltsEvent:new(vehicle, isActive, beltId), nil, nil, vehicle)
79 else
80 g_client:getServerConnection():sendEvent(TensionBeltsEvent:new(vehicle, isActive, beltId))
81 end
82 end
83end

TensionBeltsRefreshEvent

Description
Event for tension belts state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TensionBeltsRefreshEvent:emptyNew()
16 local self = Event:new(TensionBeltsRefreshEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, boolean isActive, integer beltId)
Arguments
tableobjectobject
booleanisActivebelt is active
integerbeltIdid of belt
Code
25function TensionBeltsRefreshEvent:new(object)
26 local self = TensionBeltsRefreshEvent:emptyNew()
27 self.object = object
28 return self
29end

readStream

Description
Called on client side
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function TensionBeltsRefreshEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self:run(connection)
38end

writeStream

Description
Called on server side
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
44function TensionBeltsRefreshEvent:writeStream(streamId, connection)
45 NetworkUtil.writeNodeObject(streamId, self.object)
46end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
51function TensionBeltsRefreshEvent:run(connection)
52 if not connection:getIsServer() then
53 g_server:broadcastEvent(self, false, connection, self.object)
54 end
55 self.object:refreshTensionBelts()
56end

TrailerToggleTipEvent

Description
Event for toggle trailer tipping

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TrailerToggleTipEvent:emptyNew()
16 local self = Event:new(TrailerToggleTipEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean isStart, table tipTrigger, integer tipSideIndex)
Arguments
tableobjectobject
booleanisStartis start
tabletipTriggertip trigger
integertipSideIndexindex of tip side
Code
26function TrailerToggleTipEvent:new(object, isStart, tipSideIndex)
27 local self = TrailerToggleTipEvent:emptyNew()
28 self.isStart = isStart;
29 self.tipSideIndex = Utils.getNoNil(tipSideIndex, 1);
30 assert(self.tipSideIndex <= 15);
31 self.object = object;
32 return self;
33end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
39function TrailerToggleTipEvent:readStream(streamId, connection)
40 self.object = NetworkUtil.readNodeObject(streamId);
41 self.isStart = streamReadBool(streamId);
42 if self.isStart then
43 self.tipSideIndex = streamReadUIntN(streamId, 4);
44 end;
45 self:run(connection);
46end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function TrailerToggleTipEvent:writeStream(streamId, connection)
53 NetworkUtil.writeNodeObject(streamId, self.object);
54 streamWriteBool(streamId, self.isStart);
55 if self.isStart then
56 streamWriteUIntN(streamId, self.tipSideIndex, 4);
57 end;
58end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function TrailerToggleTipEvent:run(connection)
64 if not connection:getIsServer() then
65 g_server:broadcastEvent(self, false, connection, self.object);
66 end;
67
68 if self.isStart then
69 self.object:startTipping(self.tipSideIndex, true);
70 else
71 self.object:stopTipping(true);
72 end;
73end;

TreePlanterLoadPalletEvent

Description
Event for loading of pallet on tree planter

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function TreePlanterLoadPalletEvent:emptyNew()
16 local self = Event:new(TreePlanterLoadPalletEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer palletObjectId)
Arguments
tableobjectobject
integerpalletObjectIdobject id of pallet
Code
24function TreePlanterLoadPalletEvent:new(object, palletObjectId)
25 local self = TreePlanterLoadPalletEvent:emptyNew()
26 self.object = object;
27 self.palletObjectId = palletObjectId;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function TreePlanterLoadPalletEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.palletObjectId = NetworkUtil.readNodeObjectId(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function TreePlanterLoadPalletEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 NetworkUtil.writeNodeObjectId(streamId, self.palletObjectId);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function TreePlanterLoadPalletEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.object);
56 end;
57 self.object:loadPallet(self.palletObjectId, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, integer palletObjectId, boolean noEventSend)
Arguments
tableobjectobject
integerpalletObjectIdobject id of pallet
booleannoEventSendno event send
Code
65function TreePlanterLoadPalletEvent.sendEvent(object, palletObjectId, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(TreePlanterLoadPalletEvent:new(object, palletObjectId), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(TreePlanterLoadPalletEvent:new(object, palletObjectId));
71 end;
72 end;
73end;

VehicleAttachEvent

Description
Event for attaching

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleAttachEvent:emptyNew()
15 local self = Event:new(VehicleAttachEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table vehicle, table implement, integer inputJointIndex, integer jointIndex, boolean startLowered)
Arguments
tablevehiclevehicle
tableimplementimplement
integerinputJointIndexindex of input attacher joint
integerjointIndexindex of attacher joint
booleanstartLoweredstart in lowered state
Return Values
tableinstanceinstance of event
Code
27function VehicleAttachEvent:new(vehicle, implement, inputJointIndex, jointIndex, startLowered)
28 local self = VehicleAttachEvent:emptyNew()
29 self.jointIndex = jointIndex
30 self.inputJointIndex = inputJointIndex
31 self.vehicle = vehicle
32 self.implement = implement
33 self.startLowered = startLowered
34 assert(self.jointIndex >= 0 and self.jointIndex < 127)
35 return self
36end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function VehicleAttachEvent:readStream(streamId, connection)
43 self.vehicle = NetworkUtil.readNodeObject(streamId)
44 self.implement = NetworkUtil.readNodeObject(streamId)
45 self.jointIndex = streamReadUIntN(streamId, 7)
46 self.inputJointIndex = streamReadUIntN(streamId, 7)
47 self.startLowered = streamReadBool(streamId)
48 self:run(connection)
49end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
55function VehicleAttachEvent:writeStream(streamId, connection)
56 NetworkUtil.writeNodeObject(streamId, self.vehicle)
57 NetworkUtil.writeNodeObject(streamId, self.implement)
58 streamWriteUIntN(streamId, self.jointIndex, 7)
59 streamWriteUIntN(streamId, self.inputJointIndex, 7)
60 streamWriteBool(streamId, self.startLowered)
61end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
66function VehicleAttachEvent:run(connection)
67 self.vehicle:attachImplement(self.implement, self.inputJointIndex, self.jointIndex, true, nil, self.startLowered)
68 if not connection:getIsServer() then
69 g_server:broadcastEvent(self, nil, connection, self.object)
70 end
71end

VehicleBrokenEvent

Description
Event for enter request

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleBrokenEvent:emptyNew()
15 local self = Event:new(VehicleBrokenEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table object, table playerStyle)
Arguments
tableobjectobject
tableplayerStyleinfo
Return Values
tableinstanceinstance of event
Code
24function VehicleBrokenEvent:new(object)
25 local self = VehicleBrokenEvent:emptyNew()
26 self.object = object
27 return self
28end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
34function VehicleBrokenEvent:readStream(streamId, connection)
35 self.object = NetworkUtil.readNodeObject(streamId)
36 self:run(connection)
37end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
43function VehicleBrokenEvent:writeStream(streamId, connection)
44 NetworkUtil.writeNodeObject(streamId, self.object)
45end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
50function VehicleBrokenEvent:run(connection)
51 if self.object ~= nil then
52 self.object:setBroken()
53 end
54end

VehicleBundleAttachEvent

Description
Event for bundle attaching

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleBundleAttachEvent:emptyNew()
15 local self = Event:new(VehicleBundleAttachEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table bundles)
Arguments
tablebundlesbundles
Return Values
tableinstanceinstance of event
Code
23function VehicleBundleAttachEvent:new(bundles)
24 local self = VehicleBundleAttachEvent:emptyNew()
25 self.bundles = bundles
26 return self
27end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function VehicleBundleAttachEvent:readStream(streamId, connection)
34 local numBundles = streamReadUInt8(streamId)
35 for i=1, numBundles do
36 local v1 = NetworkUtil.readNodeObjectId(streamId)
37 local v2 = NetworkUtil.readNodeObjectId(streamId)
38 local inputJointIndex = streamReadUIntN(streamId, 7)
39 local jointIndex = streamReadUIntN(streamId, 7)
40 table.insert(g_currentMission.vehiclesToAttach, {v1id=v1, v2id=v2, inputJointIndex=inputJointIndex, jointIndex=jointIndex})
41 end
42end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function VehicleBundleAttachEvent:writeStream(streamId, connection)
49 streamWriteUInt8(streamId, #self.bundles)
50 for i=1, #self.bundles do
51 local bundle = self.bundles[i]
52 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bundle.v1))
53 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bundle.v2))
54 streamWriteUIntN(streamId, bundle.input, 7)
55 streamWriteUIntN(streamId, bundle.attacher, 7)
56 end
57end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
62function VehicleBundleAttachEvent:run(connection)
63 self.vehicle:attachImplement(self.implement, self.inputJointIndex, self.jointIndex, true, nil, self.startLowered)
64 if not connection:getIsServer() then
65 g_server:broadcastEvent(self, nil, connection, self.object)
66 end
67end

VehicleDetachEvent

Description
Event for detaching

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleDetachEvent:emptyNew()
15 local self = Event:new(VehicleDetachEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table vehicle, table implement)
Arguments
tablevehiclevehicle
tableimplementimplement
Return Values
tableinstanceinstance of event
Code
24function VehicleDetachEvent:new(vehicle, implement)
25 local self = VehicleDetachEvent:emptyNew()
26 self.implement = implement
27 self.vehicle = vehicle
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function VehicleDetachEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId)
37 self.implement = NetworkUtil.readNodeObject(streamId)
38 if connection:getIsServer() then
39 self.vehicle:detachImplementByObject(self.implement, true)
40 else
41 self.vehicle:detachImplementByObject(self.implement)
42 end
43end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
49function VehicleDetachEvent:writeStream(streamId, connection)
50 NetworkUtil.writeNodeObject(streamId, self.vehicle)
51 NetworkUtil.writeNodeObject(streamId, self.implement)
52end

VehicleEnterRequestEvent

Description
Event for enter request

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleEnterRequestEvent:emptyNew()
15 local self = Event:new(VehicleEnterRequestEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table object, table playerStyle)
Arguments
tableobjectobject
tableplayerStyleinfo
Return Values
tableinstanceinstance of event
Code
24function VehicleEnterRequestEvent:new(object, playerStyle, farmId)
25 local self = VehicleEnterRequestEvent:emptyNew()
26 self.object = object
27 self.objectId = NetworkUtil.getObjectId(self.object)
28 self.farmId = farmId
29 self.playerStyle = playerStyle
30 return self
31end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function VehicleEnterRequestEvent:readStream(streamId, connection)
38 self.objectId = NetworkUtil.readNodeObjectId(streamId)
39 self.farmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
40 if self.playerStyle == nil then
41 self.playerStyle = PlayerStyle:new()
42 end
43 self.playerStyle:readStream(streamId, connection)
44 self.object = NetworkUtil.getObject(self.objectId)
45 self:run(connection)
46end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
52function VehicleEnterRequestEvent:writeStream(streamId, connection)
53 NetworkUtil.writeNodeObjectId(streamId, self.objectId)
54 streamWriteUIntN(streamId, self.farmId, FarmManager.FARM_ID_SEND_NUM_BITS)
55 self.playerStyle:writeStream(streamId, connection)
56end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
61function VehicleEnterRequestEvent:run(connection)
62 --if self.object.isControlled == false then
63 local enterableSpec = self.object.spec_enterable
64 if self.object ~= nil and enterableSpec ~= nil and enterableSpec.isControlled == false then
65 self.object:setOwner(connection)
66 self.object.controllerFarmId = self.farmId
67 g_server:broadcastEvent(VehicleEnterResponseEvent:new(self.objectId, false, self.playerStyle, self.farmId), true, connection, self.object)
68 connection:sendEvent(VehicleEnterResponseEvent:new(self.objectId, true, self.playerStyle, self.farmId))
69 end
70end

VehicleEnterResponseEvent

Description
Event for enter response

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleEnterResponseEvent:emptyNew()
15 local self = Event:new(VehicleEnterResponseEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table id, boolean isOwner, table playerStyle)
Arguments
tableidid
booleanisOwneris owner
tableplayerStyle
Return Values
tableinstanceinstance of event
Code
25function VehicleEnterResponseEvent:new(id, isOwner, playerStyle, farmId)
26 local self = VehicleEnterResponseEvent:emptyNew()
27 self.id = id
28 self.isOwner = isOwner
29 self.playerStyle = playerStyle
30 self.farmId = farmId
31 return self
32end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
38function VehicleEnterResponseEvent:readStream(streamId, connection)
39 self.id = NetworkUtil.readNodeObjectId(streamId)
40 self.isOwner = streamReadBool(streamId)
41 if self.playerStyle == nil then
42 self.playerStyle = PlayerStyle:new()
43 end
44 self.playerStyle:readStream(streamId, connection)
45 self.farmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
46 self:run(connection)
47end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
53function VehicleEnterResponseEvent:writeStream(streamId, connection)
54 NetworkUtil.writeNodeObjectId(streamId, self.id)
55 streamWriteBool(streamId, self.isOwner)
56 self.playerStyle:writeStream(streamId, connection)
57 streamWriteUIntN(streamId, self.farmId, FarmManager.FARM_ID_SEND_NUM_BITS)
58end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
63function VehicleEnterResponseEvent:run(connection)
64 local object = NetworkUtil.getObject(self.id)
65 if self.isOwner then
66 g_currentMission:onEnterVehicle(object, self.playerStyle, self.farmId)
67 else
68 local enterableSpec = object.spec_enterable
69 if enterableSpec ~= nil then
70 if not enterableSpec.isEntered then
71 object:enterVehicle(false, self.playerStyle, self.farmId)
72 end
73 end
74 end
75end

VehicleLeaveEvent

Description
Event for leaving

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleLeaveEvent:emptyNew()
15 local self = Event:new(VehicleLeaveEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table object)
Arguments
tableobjectobject
Return Values
tableinstanceinstance of event
Code
23function VehicleLeaveEvent:new(object)
24 local self = VehicleLeaveEvent:emptyNew()
25 self.object = object
26 return self
27end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
33function VehicleLeaveEvent:readStream(streamId, connection)
34 self.object = NetworkUtil.readNodeObject(streamId)
35 self:run(connection)
36end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
42function VehicleLeaveEvent:writeStream(streamId, connection)
43 NetworkUtil.writeNodeObject(streamId, self.object)
44end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
49function VehicleLeaveEvent:run(connection)
50 if not connection:getIsServer() then
51 if self.object.owner ~= nil then
52 self.object:setOwner(nil)
53 self.object.controllerFarmId = nil
54 end
55 g_server:broadcastEvent(VehicleLeaveEvent:new(self.object), nil, connection, self.object)
56 end
57 self.object:leaveVehicle()
58end

VehicleLowerImplementEvent

Description
Event for lowering implement

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
14function VehicleLowerImplementEvent:emptyNew()
15 local self = Event:new(VehicleLowerImplementEvent_mt)
16 return self
17end

new

Description
Create new instance of event
Definition
new(table vehicle, integer jointIndex, boolean moveDown)
Arguments
tablevehiclevehicle
integerjointIndexindex of joint
booleanmoveDownmove down
Return Values
tableinstanceinstance of event
Code
25function VehicleLowerImplementEvent:new(vehicle, jointIndex, moveDown)
26 local self = VehicleLowerImplementEvent:emptyNew()
27 self.jointIndex = jointIndex
28 self.vehicle = vehicle
29 self.moveDown = moveDown
30 return self
31end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
37function VehicleLowerImplementEvent:readStream(streamId, connection)
38 self.vehicle = NetworkUtil.readNodeObject(streamId)
39 self.jointIndex = streamReadInt8(streamId)
40 self.moveDown = streamReadBool(streamId)
41 self:run(connection)
42end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
48function VehicleLowerImplementEvent:writeStream(streamId, connection)
49 NetworkUtil.writeNodeObject(streamId, self.vehicle)
50 streamWriteInt8(streamId, self.jointIndex)
51 streamWriteBool(streamId, self.moveDown)
52end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
57function VehicleLowerImplementEvent:run(connection)
58 self.vehicle:setJointMoveDown(self.jointIndex, self.moveDown, true)
59 if not connection:getIsServer() then
60 g_server:broadcastEvent(VehicleLowerImplementEvent:new(self.vehicle, self.jointIndex, self.moveDown), nil, connection, self.object)
61 end
62end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, integer jointIndex, boolean moveDown, boolean noEventSend)
Arguments
tablevehiclevehicle
integerjointIndexindex of joint
booleanmoveDownmove down
booleannoEventSendno event send
Code
70function VehicleLowerImplementEvent.sendEvent(vehicle, jointIndex, moveDown, noEventSend)
71 if noEventSend == nil or noEventSend == false then
72 if g_server ~= nil then
73 g_server:broadcastEvent(VehicleLowerImplementEvent:new(vehicle, jointIndex, moveDown), nil, nil, vehicle)
74 else
75 g_client:getServerConnection():sendEvent(VehicleLowerImplementEvent:new(vehicle, jointIndex, moveDown))
76 end
77 end
78end

VehicleSetBeaconLightEvent

Description
Event for beacon light state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function VehicleSetBeaconLightEvent:emptyNew()
16 local self = Event:new(VehicleSetBeaconLightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean active)
Arguments
tableobjectobject
booleanactiveactive
Code
24function VehicleSetBeaconLightEvent:new(object, active)
25 local self = VehicleSetBeaconLightEvent:emptyNew()
26 self.active = active;
27 self.object = object;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function VehicleSetBeaconLightEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.active = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function VehicleSetBeaconLightEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.active);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function VehicleSetBeaconLightEvent:run(connection)
54 self.object:setBeaconLightsVisibility(self.active, true, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(VehicleSetBeaconLightEvent:new(self.object, self.active), nil, connection, self.object);
57 end;
58end;

VehicleSetLightEvent

Description
Event for light state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function VehicleSetLightEvent:emptyNew()
16 local self = Event:new(VehicleSetLightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer lightsTypesMask)
Arguments
tableobjectobject
integerlightsTypesMasklight types mask
Code
24function VehicleSetLightEvent:new(object, lightsTypesMask)
25 local self = VehicleSetLightEvent:emptyNew()
26 self.lightsTypesMask = lightsTypesMask;
27 self.object = object;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function VehicleSetLightEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.lightsTypesMask = streamReadInt32(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function VehicleSetLightEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteInt32(streamId, self.lightsTypesMask);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function VehicleSetLightEvent:run(connection)
54 self.object:setLightsTypesMask(self.lightsTypesMask, true, true);
55 if not connection:getIsServer() then
56 g_server:broadcastEvent(VehicleSetLightEvent:new(self.object, self.lightsTypesMask), nil, connection, self.object);
57 end;
58end;

VehicleSetTurnLightEvent

Description
Event for turn light state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function VehicleSetTurnLightEvent:emptyNew()
16 local self = Event:new(VehicleSetTurnLightEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, integer state)
Arguments
tableobjectobject
integerstatestate
Code
24function VehicleSetTurnLightEvent:new(object, state)
25 local self = VehicleSetTurnLightEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 assert(state >= 0 and state <= Lights.TURNLIGHT_HAZARD);
29 return self;
30end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
36function VehicleSetTurnLightEvent:readStream(streamId, connection)
37 self.object = NetworkUtil.readNodeObject(streamId);
38 self.state = streamReadUIntN(streamId, Lights.turnLightSendNumBits);
39 self:run(connection);
40end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
46function VehicleSetTurnLightEvent:writeStream(streamId, connection)
47 NetworkUtil.writeNodeObject(streamId, self.object);
48 streamWriteUIntN(streamId, self.state, Lights.turnLightSendNumBits);
49end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
54function VehicleSetTurnLightEvent:run(connection)
55 self.object:setTurnLightState(self.state, true, true);
56 if not connection:getIsServer() then
57 g_server:broadcastEvent(VehicleSetTurnLightEvent:new(self.object, self.state), nil, connection, self.object);
58 end;
59end;

WaterTrailerSetIsFillingEvent

Description
Event for water trailer filling

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WaterTrailerSetIsFillingEvent:emptyNew()
16 local self = Event:new(WaterTrailerSetIsFillingEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle, boolean isFilling)
Arguments
tablevehiclevehicle
booleanisFillingis filling
Code
24function WaterTrailerSetIsFillingEvent:new(vehicle, isFilling)
25 local self = WaterTrailerSetIsFillingEvent:emptyNew()
26 self.vehicle = vehicle
27 self.isFilling = isFilling
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WaterTrailerSetIsFillingEvent:readStream(streamId, connection)
36 self.vehicle = NetworkUtil.readNodeObject(streamId)
37 self.isFilling = streamReadBool(streamId)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WaterTrailerSetIsFillingEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.vehicle)
47 streamWriteBool(streamId, self.isFilling)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WaterTrailerSetIsFillingEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(self, false, connection, self.vehicle)
56 end
57 self.vehicle:setIsWaterTrailerFilling(self.isFilling, true)
58end

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table vehicle, boolean isFilling, boolean noEventSend)
Arguments
tablevehiclevehicle
booleanisFillingis filling
booleannoEventSendno event send
Code
65function WaterTrailerSetIsFillingEvent.sendEvent(vehicle, isFilling, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(WaterTrailerSetIsFillingEvent:new(vehicle, isFilling), nil, nil, vehicle)
69 else
70 g_client:getServerConnection():sendEvent(WaterTrailerSetIsFillingEvent:new(vehicle, isFilling))
71 end
72 end
73end

WearableRepairEvent

Description
Event for repairing

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WearableRepairEvent:emptyNew()
16 local self = Event:new(WearableRepairEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table vehicle)
Arguments
tablevehiclevehicle
Code
23function WearableRepairEvent:new(vehicle, atSellingPoint)
24 local self = WearableRepairEvent:emptyNew()
25 self.vehicle = vehicle
26 self.atSellingPoint = atSellingPoint
27 return self
28end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
34function WearableRepairEvent:readStream(streamId, connection)
35 self.vehicle = NetworkUtil.readNodeObject(streamId)
36 self.atSellingPoint = streamReadBool(streamId)
37 self:run(connection)
38end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
44function WearableRepairEvent:writeStream(streamId, connection)
45 NetworkUtil.writeNodeObject(streamId, self.vehicle)
46 streamWriteBool(streamId, self.atSellingPoint)
47end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
52function WearableRepairEvent:run(connection)
53 if not connection:getIsServer() then
54 if self.vehicle.repairVehicle ~= nil then
55 self.vehicle:repairVehicle(self.atSellingPoint)
56
57 g_server:broadcastEvent(self) -- broadcast for UI updates
58 g_messageCenter:publish(MessageType.VEHICLE_REPAIRED, {self.vehicle, self.atSellingPoint})
59 end
60 else
61 g_messageCenter:publish(MessageType.VEHICLE_REPAIRED, {self.vehicle, self.atSellingPoint})
62 end
63end

WoodHarvesterCutTreeEvent

Description
Event for cut tree

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WoodHarvesterCutTreeEvent:emptyNew()
16 local self = Event:new(WoodHarvesterCutTreeEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, float length)
Arguments
tableobjectobject
floatlengthlength
Code
24function WoodHarvesterCutTreeEvent:new(object, length)
25 local self = WoodHarvesterCutTreeEvent:emptyNew()
26 self.object = object;
27 self.length = length;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WoodHarvesterCutTreeEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.length = streamReadFloat32(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WoodHarvesterCutTreeEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteFloat32(streamId, self.length);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WoodHarvesterCutTreeEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(WoodHarvesterCutTreeEvent:new(self.object, self.length), nil, connection, self.object);
56 end;
57 self.object:cutTree(self.length, true);
58end;

sendEvent

Description
Broadcast event from server to all clients, if called on client call function on server and broadcast it to all clients
Definition
sendEvent(table object, float length, boolean noEventSend)
Arguments
tableobjectobject
floatlengthlength
booleannoEventSendno event send
Code
65function WoodHarvesterCutTreeEvent.sendEvent(object, length, noEventSend)
66 if noEventSend == nil or noEventSend == false then
67 if g_server ~= nil then
68 g_server:broadcastEvent(WoodHarvesterCutTreeEvent:new(object, length), nil, nil, object);
69 else
70 g_client:getServerConnection():sendEvent(WoodHarvesterCutTreeEvent:new(object, length));
71 end;
72 end;
73end;

WoodHarvesterOnCutTreeEvent

Description
Event for on cut tree

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WoodHarvesterOnCutTreeEvent:emptyNew()
16 local self = Event:new(WoodHarvesterOnCutTreeEvent_mt)
17 return self
18end

new

Description
Create new instance of event
Definition
new(table object, float radius)
Arguments
tableobjectobject
floatradiusradius
Code
24function WoodHarvesterOnCutTreeEvent:new(object, radius)
25 local self = WoodHarvesterOnCutTreeEvent:emptyNew()
26 self.object = object
27 self.radius = radius
28 return self
29end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WoodHarvesterOnCutTreeEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId)
37 self.radius = streamReadFloat32(streamId)
38 self:run(connection)
39end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WoodHarvesterOnCutTreeEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object)
47 streamWriteFloat32(streamId, self.radius)
48end

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WoodHarvesterOnCutTreeEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(WoodHarvesterOnCutTreeEvent:new(self.object, self.radius), nil, connection, self.object)
56 end
57 SpecializationUtil.raiseEvent(self.object, "onCutTree", self.radius)
58end

WoodHarvesterOnDelimbTreeEvent

Description
Event for delimb tree state

emptyNew

Description
Create instance of Event class
Definition
emptyNew()
Return Values
tableselfinstance of class event
Code
15function WoodHarvesterOnDelimbTreeEvent:emptyNew()
16 local self = Event:new(WoodHarvesterOnDelimbTreeEvent_mt);
17 return self;
18end;

new

Description
Create new instance of event
Definition
new(table object, boolean state)
Arguments
tableobjectobject
booleanstatestate
Code
24function WoodHarvesterOnDelimbTreeEvent:new(object, state)
25 local self = WoodHarvesterOnDelimbTreeEvent:emptyNew()
26 self.object = object;
27 self.state = state;
28 return self;
29end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
35function WoodHarvesterOnDelimbTreeEvent:readStream(streamId, connection)
36 self.object = NetworkUtil.readNodeObject(streamId);
37 self.state = streamReadBool(streamId);
38 self:run(connection);
39end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
45function WoodHarvesterOnDelimbTreeEvent:writeStream(streamId, connection)
46 NetworkUtil.writeNodeObject(streamId, self.object);
47 streamWriteBool(streamId, self.state);
48end;

run

Description
Run action on receiving side
Definition
run(integer connection)
Arguments
integerconnectionconnection
Code
53function WoodHarvesterOnDelimbTreeEvent:run(connection)
54 if not connection:getIsServer() then
55 g_server:broadcastEvent(WoodHarvesterOnDelimbTreeEvent:new(self.object, self.state), nil, connection, self.object);
56 end;
57 self.object:onDelimbTree(self.state);
58end;

AnimatedMapObject

Description
Class for animated map objects
Parent
AnimatedObject

onCreate

Description
Creating animated object
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
booleansuccesssuccess
Code
17function AnimatedMapObject:onCreate(id)
18 local object = AnimatedMapObject:new(g_server ~= nil, g_client ~= nil)
19 if object:load(id) then
20 g_currentMission:addOnCreateLoadedObject(object)
21 g_currentMission:addOnCreateLoadedObjectToSave(object)
22 object:register(true)
23 else
24 object:delete()
25 end
26end

new

Description
Creating new instance of animated object class
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
booleanisActivespeed rotating part is active
tableselfnew instance of object
Code
34function AnimatedMapObject:new(isServer, isClient, customMt)
35 local self = AnimatedObject:new(isServer, isClient, customMt or AnimatedObject_mt)
36 return self
37end

load

Description
Load animated object attributes from object
Definition
load(integer nodeId)
Arguments
integernodeIdid of object to load from
Return Values
integerdirectiondirection
booleansuccesssuccess
Code
49function AnimatedMapObject:load(nodeId)
50 local xmlFilename = getUserAttribute(nodeId, "xmlFilename")
51
52 if xmlFilename == nil then
53 print("Error: Missing 'xmlFilename' user attribute for AnimatedMapObject node '"..getName(nodeId).."'!")
54 return false
55 end
56
57 local baseDir = g_currentMission.loadingMapBaseDirectory
58 if baseDir == "" then
59 baseDir = Utils.getNoNil(self.baseDirectory, baseDir)
60 end
61 xmlFilename = Utils.getFilename(xmlFilename, baseDir)
62
63 local index = getUserAttribute(nodeId, "index")
64 if index == nil then
65 print("Error: Missing 'index' user attribute for AnimatedMapObject node '"..getName(nodeId).."'!")
66 return false
67 end
68
69 local xmlFile = loadXMLFile("AnimatedObject", xmlFilename)
70 if xmlFile == 0 then
71 return false
72 end
73
74 -- Find the index in the XML
75 local key
76 local i = 0
77 while true do
78 local objectKey = string.format("animatedObjects.animatedObject(%d)", i)
79 if not hasXMLProperty(xmlFile, objectKey) then
80 break
81 end
82
83 local configIndex = getXMLString(xmlFile, objectKey.."#index")
84 if configIndex == index then
85 key = objectKey
86 break
87 end
88 i = i + 1
89 end
90
91 if key == nil then
92 print("Error: index '"..index.."' not found in AnimatedObject xml '"..xmlFilename.."'!")
93 return false
94 end
95
96 local result = AnimatedMapObject:superClass().load(self, nodeId, xmlFilename, index)
97
98 delete(xmlFile)
99
100 return result
101end

AnimatedObject

Description
Class for animated objects

onCreate

Description
Creating animated object
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
19function AnimatedObject:onCreate(id)
20 local object = AnimatedObject:new(g_server ~= nil, g_client ~= nil)
21 if object:load(id) then
22 g_currentMission:addOnCreateLoadedObject(object)
23 g_currentMission:addOnCreateLoadedObjectToSave(object)
24 object:register(true)
25 else
26 object:delete()
27 end
28end

new

Description
Creating new instance of animated object class
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
tableselfnew instance of object
Code
36function AnimatedObject:new(isServer, isClient, customMt)
37 local self = Object:new(isServer, isClient, customMt or AnimatedObject_mt)
38 self.nodeId = 0
39 self.isMoving = false
40 self.wasPressed = false
41 self.baseDirectory = nil
42 self.customEnvironment = g_currentMission.loadingMapModName
43
44 -- input controls fields:
45 self.controls = {}
46 self.controls.active = false
47 self.controls.posAction = nil
48 self.controls.negAction = nil
49 self.controls.posText = nil
50 self.controls.negText = nil
51 self.controls.posActionEventId = nil
52 self.controls.negActionEventId = nil
53
54 return self
55end

load

Description
Load animated object from object with given configuration file
Definition
load(integer nodeId, xmlFilename string, index integer)
Arguments
integernodeIdid of object
xmlFilenamestringPath of the xml configuration
indexintegerConfiguration index within the xml file
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
booleansuccesssuccess
Code
63function AnimatedObject:load(nodeId, xmlFile, key)
64 self.nodeId = nodeId
65
66 self.samples = {}
67
68 local success = true
69 self.saveId = getXMLString(xmlFile, key.."#saveId")
70 if self.saveId == nil then
71 self.saveId = "AnimatedObject_"..getName(nodeId)
72 end
73
74 local animKey = key .. ".animation"
75
76 self.animation = {}
77 self.animation.parts = {}
78 self.animation.duration = Utils.getNoNil(getXMLFloat(xmlFile, animKey.."#duration"), 3) * 1000
79 if self.animation.duration == 0 then
80 self.animation.duration = 1000
81 end
82 self.animation.time = 0
83 self.animation.direction = 0
84
85 self.animation.targetTime = 0
86 self.animation.lastTime = 0
87 self.animation.timeIsDirty = false
88
89 self.interpolationDuration = 50+30
90 self.interpolationAlpha = 0
91
92
93 local i = 0
94 while true do
95 local partKey = string.format("%s.part(%d)", animKey, i)
96 if not hasXMLProperty(xmlFile, partKey) then
97 break
98 end
99
100 local node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, partKey.."#node"))
101 if node ~= nil then
102 local part = {}
103 part.node = node
104 part.animCurve = AnimCurve:new(linearInterpolatorN)
105 local hasFrames = false
106 local j = 0
107 while true do
108 local frameKey = string.format("%s.keyFrame(%d)", partKey, j)
109 if not hasXMLProperty(xmlFile, frameKey) then
110 break
111 end
112
113 local keyTime = getXMLFloat(xmlFile, frameKey.."#time")
114 local keyframe = {self:loadFrameValues(xmlFile, frameKey, node)}
115 keyframe.time = keyTime
116 part.animCurve:addKeyframe(keyframe)
117 hasFrames = true
118
119 j = j + 1
120 end
121
122 if hasFrames then
123 table.insert(self.animation.parts, part)
124 end
125 end
126 i = i + 1
127 end
128
129 local initialTime = Utils.getNoNil(getXMLFloat(xmlFile, animKey.."#initialTime"), 0)*1000
130 self:setAnimTime(initialTime / self.animation.duration, true)
131
132 local startTime = getXMLFloat(xmlFile, key..".openingHours#startTime")
133 local endTime = getXMLFloat(xmlFile, key..".openingHours#endTime")
134 if startTime ~= nil and endTime ~= nil then
135 local disableIfClosed = Utils.getNoNil(getXMLBool(xmlFile, key..".openingHours#disableIfClosed"), false)
136 local closedText = getXMLString(xmlFile, key..".openingHours#closedText")
137 if closedText ~= nil then
138 if g_i18n:hasText(closedText, self.customEnvironment) then
139 closedText = g_i18n:getText(closedText, self.customEnvironment)
140 end
141 end
142 self.openingHours = {startTime=startTime, endTime=endTime, disableIfClosed=disableIfClosed, closedText=closedText}
143 g_currentMission.environment:addHourChangeListener(self)
144 end
145
146 self.isEnabled = true
147
148
149 local triggerId = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, key..".controls#triggerNode"))
150 if triggerId ~= nil then
151 self.controls.triggerId = triggerId
152
153 addTrigger(self.controls.triggerId, "triggerCallback", self)
154 for i=0, getNumOfChildren(self.controls.triggerId)-1 do
155 addTrigger(getChildAt(self.controls.triggerId, i), "triggerCallback", self)
156 end
157
158 local posAction = getXMLString(xmlFile, key..".controls#posAction")
159 if posAction ~= nil then
160 if InputAction[posAction] then
161 self.controls.posAction = posAction
162
163 local posText = getXMLString(xmlFile, key..".controls#posText")
164 if posText ~= nil then
165 if g_i18n:hasText(posText, self.customEnvironment) then
166 posText = g_i18n:getText(posText, self.customEnvironment)
167 end
168 self.controls.posActionText = posText
169 end
170
171 local negText = getXMLString(xmlFile, key..".controls#negText")
172 if negText ~= nil then
173 if g_i18n:hasText(negText, self.customEnvironment) then
174 negText = g_i18n:getText(negText, self.customEnvironment)
175 end
176 self.controls.negActionText = negText
177 end
178
179 local negAction = getXMLString(xmlFile, key..".controls#negAction")
180 if negAction ~= nil then
181 if InputAction[negAction] then
182 self.controls.negAction = negAction
183 else
184 print("Warning: Negative direction action '"..negAction.."' not defined!")
185 end
186 end
187 else
188 print("Warning: Positive direction action '"..posAction.."' not defined!")
189 end
190 end
191 end
192
193 if g_client ~= nil then
194 local soundsKey = key .. ".sounds"
195 self.sampleMoving = g_soundManager:loadSampleFromXML(xmlFile, soundsKey, "moving", self.baseDirectory, self.nodeId, 1, AudioGroup.ENVIRONMENT, nil, nil)
196 self.samplePosEnd = g_soundManager:loadSampleFromXML(xmlFile, soundsKey, "posEnd", self.baseDirectory, self.nodeId, 1, AudioGroup.ENVIRONMENT, nil, nil)
197 self.sampleNegEnd = g_soundManager:loadSampleFromXML(xmlFile, soundsKey, "negEnd", self.baseDirectory, self.nodeId, 1, AudioGroup.ENVIRONMENT, nil, nil)
198 end
199
200 self.animatedObjectDirtyFlag = self:getNextDirtyFlag()
201
202 return success
203end

loadFrameValues

Description
Load frame values from xml
Definition
loadFrameValues(integer fileId, string key, integer node)
Arguments
integerfileIdxml file id
stringkeykey
integernodenode id
Return Values
floatdirtMultipliercurrent dirt multiplier
floatxx translation
floatyy translation
floatzz translation
floatrxx rotation
floatryy rotation
floatrzz rotation
floatsxx scale
floatsyy scale
floatszz scale
integervisibilityvisibility
Code
220function AnimatedObject:loadFrameValues(xmlFile, key, node)
221 local rx,ry,rz = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotation"))
222 local x,y,z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#translation"))
223 local sx,sy,sz = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#scale"))
224 local isVisible = Utils.getNoNil(getXMLBool(xmlFile, key.."#visibility"), true)
225
226 local drx,dry,drz = getRotation(node)
227 rx = Utils.getNoNilRad(rx, drx)
228 ry = Utils.getNoNilRad(ry, dry)
229 rz = Utils.getNoNilRad(rz, drz)
230 local dx,dy,dz = getTranslation(node)
231 x = Utils.getNoNil(x, dx)
232 y = Utils.getNoNil(y, dy)
233 z = Utils.getNoNil(z, dz)
234 local dsx,dsy,dsz = getScale(node)
235 sx = Utils.getNoNil(sx, dsx)
236 sy = Utils.getNoNil(sy, dsy)
237 sz = Utils.getNoNil(sz, dsz)
238
239 local visibility = 1
240 if not isVisible then
241 visibility = 0
242 end
243
244 return x, y, z, rx, ry, rz, sx, sy, sz, visibility
245end

delete

Description
Delete animated object
Definition
delete()
Return Values
floatwearMultipliercurrent wear multiplier
Code
249function AnimatedObject:delete()
250 if self.controls.triggerId ~= nil then
251 removeTrigger(self.controls.triggerId)
252 for i=0, getNumOfChildren(self.controls.triggerId)-1 do
253 removeTrigger(getChildAt(self.controls.triggerId, i))
254 end
255 self.controls.triggerId = nil
256 end
257
258 if self.sampleMoving ~= nil then
259 g_soundManager:deleteSample(self.sampleMoving)
260 self.sampleMoving = nil
261 end
262 if self.samplePosEnd ~= nil then
263 g_soundManager:deleteSample(self.samplePosEnd)
264 self.samplePosEnd = nil
265 end
266 if self.sampleNegEnd ~= nil then
267 g_soundManager:deleteSample(self.sampleNegEnd)
268 self.sampleNegEnd = nil
269 end
270
271 g_currentMission.environment:removeHourChangeListener(self)
272
273 AnimatedObject:superClass().delete(self)
274end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
tableobjectsInTensionBeltRangeobject in belt range
integernumObjectsIntensionBeltRangenumber of objects in belt range
Code
280function AnimatedObject:readStream(streamId, connection)
281 AnimatedObject:superClass().readStream(self, streamId, connection)
282 if connection:getIsServer() then
283 local animTime = streamReadFloat32(streamId)
284 self:setAnimTime(animTime, true)
285 end
286end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
292function AnimatedObject:writeStream(streamId, connection)
293 AnimatedObject:superClass().writeStream(self, streamId, connection)
294 if not connection:getIsServer() then
295 streamWriteFloat32(streamId, self.animation.time)
296 end
297end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Return Values
tableobjectIdsToUnmounttable with object ids to unmount
integernumObjectsnumber of objects to unmount
Code
304function AnimatedObject:readUpdateStream(streamId, timestamp, connection)
305 AnimatedObject:superClass().readUpdateStream(self, streamId, timestamp, connection)
306 if connection:getIsServer() then
307 local isDirty = streamReadBool(streamId)
308 if isDirty then
309 local animTime = streamReadFloat32(streamId)
310 --self:setAnimTime(animTime)
311
312 self.animation.targetTime = animTime
313 self.animation.lastTime = self.animation.time
314
315 local deltaTime = g_client.tickDuration
316 if self.lastPhysicsNetworkTime ~= nil then
317 deltaTime = math.min(g_packetPhysicsNetworkTime - self.lastPhysicsNetworkTime, 3*g_client.tickDuration)
318 end
319 self.lastPhysicsNetworkTime = g_packetPhysicsNetworkTime
320
321 -- interpTimeLeft is the time we would've continued interpolating. This should always be about g_clientInterpDelay.
322 -- If we extrapolated, reset to the full delay
323 local interpTimeLeft = g_clientInterpDelay
324 if self.animation.timeIsDirty and self.interpolationAlpha < 1 then
325 interpTimeLeft = (1-self.interpolationAlpha) * self.interpolationDuration
326 interpTimeLeft = interpTimeLeft * 0.95 + g_clientInterpDelay * 0.05 -- slighly blend towards the expected delay
327 interpTimeLeft = math.min(interpTimeLeft, 3*g_clientInterpDelay) -- clamp to some reasonable maximum
328 end
329 self.interpolationDuration = interpTimeLeft + deltaTime
330 self.interpolationAlpha = 0
331
332 self.animation.timeIsDirty = true
333 end
334 end
335end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
342function AnimatedObject:writeUpdateStream(streamId, connection, dirtyMask)
343 AnimatedObject:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
344 if not connection:getIsServer() then
345 if streamWriteBool(streamId, bitAND(dirtyMask, self.animatedObjectDirtyFlag) ~= 0) then
346 streamWriteFloat32(streamId, self.animation.time)
347 end
348 end
349end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
booleaninRangeplayer is in range
tablebeltnearest belt
booleansuccesssuccess
Code
356function AnimatedObject:loadFromXMLFile(xmlFile, key)
357 local animTime = getXMLFloat(xmlFile, key .. "#time")
358 if animTime ~= nil then
359 self.animation.direction = Utils.getNoNil(getXMLInt(xmlFile, key.."#direction"), 0)
360 self:setAnimTime(animTime, true)
361 end
362
363 AnimatedObject.hourChanged(self)
364
365 return true
366end

registerActionEventsWhenInRange

Description
Register action events when the player is in range.
Definition
registerActionEventsWhenInRange()

removeActionEvents

Description
Remove action events.
Call as early as possible to avoid input conflicts.
Definition
removeActionEvents()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded

onAnimationInputToggle

Description
Event function for animation toggle (e.g. open/close door with one input).
Definition
onAnimationInputToggle()
Return Values
floatdirtMultipliercurrent dirt multiplier

onAnimationInputContinuous

Description
Event function for continuous animation (e.g. keep button pressed to raise/lower something).
Definition
onAnimationInputContinuous()
Return Values
floatdirtMultipliercurrent wear multiplier

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Return Values
booleanisActivespeed rotating part is active
Code
483function AnimatedObject:update(dt)
484 AnimatedObject:superClass().update(self, dt)
485
486 -- Update availability of the input actions
487 local deactivateInput = false
488 if self.playerInRange then
489 if self.isEnabled then
490 if not self.controls.active then
491 self:registerActionEventsWhenInRange()
492 end
493 self:updateActionEventTexts()
494 else
495 deactivateInput = true
496 if self.openingHours ~= nil and self.openingHours.closedText ~= nil then
497 g_currentMission:addExtraPrintText(self.openingHours.closedText)
498 end
499 end
500 else
501 deactivateInput = true
502 end
503
504 if deactivateInput and self.controls.active then
505 self:removeActionEvents()
506 end
507
508 local finishedAnimation = false
509
510 -- former updateTick()
511 if self.isServer then
512 if self.animation.direction ~= 0 then
513 local newAnimTime = MathUtil.clamp(self.animation.time + (self.animation.direction*dt)/self.animation.duration, 0, 1)
514
515 self:setAnimTime(newAnimTime)
516 if newAnimTime == 0 or newAnimTime == 1 then
517 self.animation.direction = 0
518 finishedAnimation = true
519 end
520 end
521
522 if self.animation.time ~= self.animation.timeSend then
523 self.animation.timeSend = self.animation.time
524 self:raiseDirtyFlags(self.animatedObjectDirtyFlag)
525 end
526 end
527
528 if not self.isServer and self.animation.timeIsDirty then
529 local maxIntrpAlpha = 1.2
530 local interpolationAlpha = self.interpolationAlpha + g_physicsDtUnclamped / self.interpolationDuration
531
532 if interpolationAlpha >= maxIntrpAlpha then
533 interpolationAlpha = maxIntrpAlpha
534 self.animation.timeIsDirty = false
535 end
536
537 self.interpolationAlpha = interpolationAlpha
538 local animTime = self.animation.lastTime + (interpolationAlpha * (self.animation.targetTime - self.animation.lastTime))
539 self:setAnimTime(animTime)
540 end
541
542 if self.sampleMoving ~= nil then
543 if self.isMoving and self.animation.direction ~= 0 then
544 if not self.sampleMoving.isPlaying then
545 g_soundManager:playSample(self.sampleMoving)
546 self.sampleMoving.isPlaying = true
547 end
548 else
549 if self.sampleMoving.isPlaying then
550 g_soundManager:stopSample(self.sampleMoving)
551 self.sampleMoving.isPlaying = false
552 end
553 end
554 end
555
556 if finishedAnimation and self.animation.direction == 0 then
557 if self.samplePosEnd ~= nil and self.animation.time == 1 then
558 g_soundManager:playSample(self.samplePosEnd)
559 elseif self.sampleNegEnd ~= nil and self.animation.time == 0 then
560 g_soundManager:playSample(self.sampleNegEnd)
561 end
562 end
563
564 self.isMoving = false
565
566 if self.animation.direction ~= 0 then
567 self:raiseActive()
568 end
569end

updateTick

Description
Called on update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Return Values
booleancheckSpeedlimitcheck speed limit
Code
574function AnimatedObject:updateTick(dt)
575 AnimatedObject:superClass().updateTick(self, dt)
576end

setAnimTime

Description
Set animation time
Definition
setAnimTime(float t)
Arguments
floatttime
Return Values
floatspeedLimitspeed limit
Code
581function AnimatedObject:setAnimTime(t, omitSound)
582 t = MathUtil.clamp(t, 0, 1)
583
584 for _, part in pairs(self.animation.parts) do
585 local v = part.animCurve:get(t)
586 self:setFrameValues(part.node, v)
587 end
588
589 self.animation.time = t
590 self.isMoving = true
591end

setFrameValues

Description
Set frame values
Definition
setFrameValues(integer node, table v)
Arguments
integernodenode id
tablevvalues
Return Values
tableobjectobject of sapling pallet
Code
597function AnimatedObject:setFrameValues(node, v)
598 setTranslation(node, v[1], v[2], v[3])
599 setRotation(node, v[4], v[5], v[6])
600 setScale(node, v[7], v[8], v[9])
601 setVisibility(node, v[10] == 1)
602end

hourChanged

Description
Called on hour change
Definition
hourChanged()
Return Values
tableselfnew instance
Code
606function AnimatedObject:hourChanged()
607 if self.isServer then
608 local currentHour = g_currentMission.environment.currentHour
609 if self.openingHours ~= nil then
610 if currentHour >= self.openingHours.startTime and currentHour < self.openingHours.endTime then
611 if not self.openingHours.isOpen then
612 if self.isServer then
613 self.animation.direction = 1
614 end
615 self.openingHours.isOpen = true
616 end
617 if self.openingHours.disableIfClosed then
618 self.isEnabled = true
619 end
620 else
621 if self.openingHours.isOpen then
622 if self.isServer then
623 self.animation.direction = -1
624 end
625 self.openingHours.isOpen = false
626 end
627 if self.openingHours.disableIfClosed then
628 self.isEnabled = false
629 end
630 end
631 end
632 end
633end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of object that calls callback
booleanonEntercalled on enter
booleanonLeavecalled on leave
booleanonStaycalled on stay
Return Values
booleanisActivateableis activateable
Code
642function AnimatedObject:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
643 if g_currentMission.missionInfo:isa(FSCareerMissionInfo) then
644 if onEnter or onLeave then
645 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
646 if onEnter then
647 self.playerInRange = g_currentMission.player
648 else
649 self.playerInRange = nil
650 end
651 self:raiseActive()
652 end
653 end
654 end
655end

Bale

Description
Class for bales

new

Description
Creating bale object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
tableinstanceInstance of object
Code
18function Bale:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = Bale_mt;
22 end;
23
24 local self = MountableObject:new(isServer, isClient, mt);
25
26 self.forcedClipDistance = 150;
27 registerObjectClassName(self, "Bale");
28
29 self.fillType = FillType.STRAW;
30 self.fillLevel = 0;
31 self.wrappingState = 0;
32 self.baleValueScale = 1;
33 self.canBeSold = true
34
35 g_currentMission:addLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self);
36
37 return self;
38end;

delete

Description
Deleting bale object
Definition
delete()
Return Values
booleanisTurnedOnvehicle is turned on
Code
42function Bale:delete()
43 if self.i3dFilename ~= nil then
44 g_i3DManager:releaseSharedI3DFile(self.i3dFilename, nil, true);
45 end
46 g_currentMission:removeLimitedObject(FSBaseMission.LIMITED_OBJECT_TYPE_BALE, self);
47 unregisterObjectClassName(self);
48 g_currentMission:removeItemToSave(self);
49 Bale:superClass().delete(self);
50end;

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Return Values
booleancanBeTurnedOnvehicle can be turned on
Code
57function Bale:readUpdateStream(streamId, timestamp, connection)
58 if connection:getIsServer() then
59 if self.supportsWrapping then
60 self:setWrappingState(streamReadUInt8(streamId)/255);
61 end
62 end
63 Bale:superClass().readUpdateStream(self, streamId, timestamp, connection);
64end;

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Return Values
booleanallowallow turn on
Code
71function Bale:writeUpdateStream(streamId, connection, dirtyMask)
72 if not connection:getIsServer() then
73 if self.supportsWrapping then
74 streamWriteUInt8(streamId, MathUtil.clamp(self.wrappingState*255, 0, 255));
75 end
76 end
77 Bale:superClass().writeUpdateStream(self, streamId, connection, dirtyMask);
78end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
stringwarningTextturn on not allowed warning text
Code
84function Bale:readStream(streamId, connection)
85 local i3dFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId));
86 if self.nodeId == 0 then
87 self:createNode(i3dFilename);
88 end;
89 self.fillLevel = streamReadFloat32(streamId);
90 Bale:superClass().readStream(self, streamId, connection);
91 g_currentMission:addItemToSave(self);
92
93 self.baleValueScale = streamReadFloat32(streamId);
94 if self.supportsWrapping then
95 self:setWrappingState(streamReadUInt8(streamId)/255);
96 setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false);
97
98 local r = streamReadFloat32(streamId);
99 local g = streamReadFloat32(streamId);
100 local b = streamReadFloat32(streamId);
101 local a = streamReadFloat32(streamId);
102 self:setColor(r, g, b, a);
103 end;
104end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
booleanisActivework area is active
Code
110function Bale:writeStream(streamId, connection)
111 streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.i3dFilename));
112 streamWriteFloat32(streamId, self.fillLevel);
113 Bale:superClass().writeStream(self, streamId, connection);
114
115 streamWriteFloat32(streamId, self.baleValueScale);
116
117 if self.supportsWrapping then
118 streamWriteUInt8(streamId, MathUtil.clamp(self.wrappingState*255, 0, 255));
119
120 streamWriteFloat32(streamId, self.wrappingColor[1]);
121 streamWriteFloat32(streamId, self.wrappingColor[2]);
122 streamWriteFloat32(streamId, self.wrappingColor[3]);
123 streamWriteFloat32(streamId, self.wrappingColor[4]);
124 end
125end;

mount

Description
Mount bale to object
Definition
mount(table object, integer node, float x, float y, float z, float rx, float ry, float rz)
Arguments
tableobjecttarget object
integernodetarget node id
floatxx position
floatyz position
floatzz position
floatrxrx rotation
floatryry rotation
floatrzrz rotation
Return Values
booleanisReadyis ready for ai work
Code
137function Bale:mount(object, node, x,y,z, rx,ry,rz)
138 g_currentMission:removeItemToSave(self);
139 Bale:superClass().mount(self, object, node, x,y,z, rx,ry,rz);
140end;

unmount

Description
Unmount bale
Definition
unmount()
Return Values
booleanisOperatingis operating
Code
144function Bale:unmount()
145 if Bale:superClass().unmount(self) then
146 g_currentMission:addItemToSave(self);
147 return true;
148 end
149 return false;
150end;

setNodeId

Description
Set node id
Definition
setNodeId(integer nodeId)
Arguments
integernodeIdnode Id
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
155function Bale:setNodeId(nodeId)
156 Bale:superClass().setNodeId(self, nodeId);
157
158 local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false);
159 local defaultFillLevel = 2100*2;
160 if isRoundbale then
161 defaultFillLevel = 2000*2;
162 end
163 if getUserAttribute(nodeId, "baleValue") ~= nil then
164 print("Warning: bale 'baleValue' is not supported anymore. Use 'baleValueScale' instead and adjust the creating vehicles.");
165 end
166 local meshIndex = Utils.getNoNil(getUserAttribute(nodeId, "baleMeshIndex"), "1|0");
167 self.meshNode = I3DUtil.indexToObject(nodeId, meshIndex);
168
169 self.meshNodes = {self.meshNode}
170
171 self.supportsWrapping = Utils.getNoNil(getUserAttribute(nodeId, "supportsWrapping"), false);
172 if self.supportsWrapping then
173 self.wrappingColor = {1,1,1,1};
174 end
175
176 self.fillLevel = defaultFillLevel
177 self.baleValueScale = Utils.getNoNil(tonumber(getUserAttribute(nodeId, "baleValueScale")), 1);
178
179 self.fillType = FillType.STRAW;
180 local fillTypeStr = getUserAttribute(nodeId, "fillType");
181 if fillTypeStr ~= nil then
182 local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr)
183 if fillTypeIndex ~= nil then
184 self.fillType = fillTypeIndex;
185 end
186 elseif Utils.getNoNil(getUserAttribute(nodeId, "isHaybale"), false) then
187 self.fillType = FillType.DRYGRASS_WINDROW;
188 end
189
190 local baleWidth = tonumber(getUserAttribute(nodeId, "baleWidth"));
191 local baleHeight = tonumber(getUserAttribute(nodeId, "baleHeight"));
192 local baleLength = tonumber(getUserAttribute(nodeId, "baleLength"));
193 local baleDiameter = tonumber(getUserAttribute(nodeId, "baleDiameter"));
194 if baleDiameter ~= nil and baleWidth ~= nil then
195 self.baleDiameter = baleDiameter;
196 self.baleWidth = baleWidth;
197 elseif baleHeight ~= nil and baleWidth ~= nil and baleLength ~= nil then
198 self.baleHeight = baleHeight;
199 self.baleWidth = baleWidth;
200 self.baleLength = baleLength;
201 else
202 local isRoundbale = Utils.getNoNil(getUserAttribute(nodeId, "isRoundbale"), false);
203 if isRoundbale then
204 self.baleDiameter = 1.8;
205 self.baleWidth = 1.2;
206 else
207 self.baleHeight = 0.8;
208 self.baleWidth = 1.2;
209 self.baleLength = 2.4;
210 end
211 end
212end;

createNode

Description
Load node from i3d file
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
217function Bale:createNode(i3dFilename)
218 self.i3dFilename = i3dFilename;
219 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename);
220 local baleRoot = g_i3DManager:loadSharedI3DFile(i3dFilename);
221
222 local baleId = getChildAt(baleRoot, 0);
223 link(getRootNode(), baleId);
224 delete(baleRoot);
225
226 self:setNodeId(baleId);
227end;

load

Description
Load bale
Definition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz, integer fillLevel)
Arguments
stringi3dFilenamei3d file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
integerfillLevelfill level
Return Values
booleansuccesssuccess
Code
239function Bale:load(i3dFilename, x,y,z, rx,ry,rz, fillLevel)
240 self.i3dFilename = i3dFilename;
241 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename);
242 self:createNode(i3dFilename);
243 setTranslation(self.nodeId, x, y, z);
244 setRotation(self.nodeId, rx, ry, rz);
245 if fillLevel ~= nil then
246 self.fillLevel = fillLevel;
247 end
248 g_currentMission:addItemToSave(self);
249end;

loadFromMemory

Description
Setting node id and i3d file name
Definition
loadFromMemory(integer nodeId, string i3dFilename)
Arguments
integernodeIdnode id
stringi3dFilenamei3d file name
Return Values
booleanisActivework area is active
Code
255function Bale:loadFromMemory(nodeId, i3dFilename)
256 self.i3dFilename = i3dFilename;
257 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename);
258 self:setNodeId(nodeId);
259end;

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleancheckSpeedlimitcheck speed limit
booleansuccesssuccess
Code
267function Bale:loadFromXMLFile(xmlFile, key, resetVehicles)
268
269 local x,y,z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#position"));
270 local xRot,yRot,zRot = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotation"));
271 if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then
272 return false;
273 end;
274 xRot = math.rad(xRot)
275 yRot = math.rad(yRot)
276 zRot = math.rad(zRot)
277
278 local filename = getXMLString(xmlFile, key.."#filename");
279 if filename == nil then
280 return false;
281 end;
282 filename = NetworkUtil.convertFromNetworkFilename(filename);
283 local rootNode = g_i3DManager:loadSharedI3DFile(filename);
284 if rootNode == 0 then
285 return false;
286 end;
287
288 local ret = false;
289 local node = getChildAt(rootNode, 0);
290 if node ~= nil and node ~= 0 then
291 setTranslation(node, x,y,z);
292 setRotation(node, xRot,yRot,zRot);
293 link(getRootNode(), node);
294 ret = true;
295 end;
296 delete(rootNode);
297 if not ret then
298 return false;
299 end;
300
301 self:setOwnerFarmId(Utils.getNoNil(getXMLInt(xmlFile, key .. "#farmId"), AccessHandler.EVERYONE), true)
302
303 self:loadFromMemory(node, filename);
304
305
306 local fillLevel = getXMLFloat(xmlFile, key.."#fillLevel");
307 if fillLevel ~= nil then
308 self.fillLevel = fillLevel;
309 end;
310
311 local attributes = {}
312 self:loadExtraAttributesFromXMLFile(attributes, xmlFile, key, resetVehicles)
313 self:applyExtraAttributes(attributes)
314
315 return true;
316end;

getValue

Description
Get price value of bale
Definition
getValue()
Return Values
floatdirtMultipliercurrent dirt multiplier
Code
357function Bale:getValue()
358 local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType);
359 return self.fillLevel * pricePerLiter * self.baleValueScale;
360end;

getFillType

Description
Get fill type of bale
Definition
getFillType()
Return Values
floatdirtMultipliercurrent wear multiplier
integerfillTypecurrent fill type id
Code
365function Bale:getFillType()
366 return self.fillType;
367end;

getFillLevel

Description
Get fill level of bale
Definition
getFillLevel()
Return Values
booleansuccesssuccess
integerfillLevelcurrent fill level
Code
372function Bale:getFillLevel()
373 return self.fillLevel;
374end;

setFillLevel

Description
Set fill level of bale
Definition
setFillLevel(integer fillLevel)
Arguments
integerfillLevelfill level
Return Values
floatspeedLimitspeed limit
Code
379function Bale:setFillLevel(fillLevel)
380 self.fillLevel = fillLevel;
381end;

setCanBeSold

Description
Set if bale can be sold
Definition
setCanBeSold(boolean canBeSold)
Arguments
booleancanBeSoldbale can be sold
Return Values
floattotalMasstotal mass
Code
386function Bale:setCanBeSold(canBeSold)
387 self.canBeSold = canBeSold
388end

getCanBeSold

Description
Returns if bale can be sold
Definition
getCanBeSold()
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
booleancanBeSoldbale can be sold
Code
393function Bale:getCanBeSold()
394 return self.canBeSold
395end

setWrappingState

Description
Set wrapping state of bale
Definition
setWrappingState(boolean wrappingState)
Arguments
booleanwrappingStatenew wrapping state
Return Values
booleanallowallow turn on
Code
400function Bale:setWrappingState(wrappingState)
401 if self.supportsWrapping then
402 if self.wrappingState ~= wrappingState then
403 self:raiseDirtyFlags(self.physicsObjectDirtyFlag);
404 end
405 self.wrappingState = wrappingState;
406 setShaderParameter(self.meshNode, "wrappingState", self.wrappingState, 0, 0, 0, false);
407 end
408end

setColor

Description
Set color of bale
Definition
setColor(float r, float g, float b, float a)
Arguments
floatrred channel value
floatggreen channel value
floatbblue channel value
floataalpha channel value
Return Values
floatdirtMultipliercurrent dirt multiplier
Code
416function Bale:setColor(r, g, b, a)
417 r, g, b, a = Utils.getNoNil(r, 1), Utils.getNoNil(g, 1), Utils.getNoNil(b, 1), Utils.getNoNil(a, 1);
418 self.wrappingColor = {r, g, b, a};
419
420 if getHasShaderParameter(self.meshNode, "colorScale") then
421 setShaderParameter(self.meshNode, "colorScale", r, g, b, a, false);
422 end;
423end;

getMeshNodes

Description
Set wrapping state of bale
Definition
getMeshNodes()
Return Values
floatdirtMultipliercurrent wear multiplier
tablemeshNodesmesh nodes
Code
428function Bale:getMeshNodes()
429 return self.meshNodes
430end

Basketball

Description
Class for basketballs
Parent
PhysicsObject

onCreate

Description
Creating basketball
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
booleansuccesssuccess
Code
15function Basketball:onCreate(id)
16 local basketball = Basketball:new(g_server ~= nil, g_client ~= nil)
17 local x, y, z = getWorldTranslation(id)
18 local rx, ry, rz = getWorldRotation(id)
19 local filename = Utils.getNoNil(getUserAttribute(id, "filename"), "$data/objects/basketball/basketball.i3d")
20 filename = Utils.getFilename(filename, g_currentMission.loadingMapBaseDirectory);
21
22 if basketball:load(filename, x, y, z, rx, ry, rz) then
23 g_currentMission:addOnCreateLoadedObject(basketball)
24 basketball:register(true)
25 else
26 basketball:delete()
27 end
28end

new

Description
Creating basketball object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
tableinstanceInstance of object
Code
36function Basketball:new(isServer, isClient, customMt)
37 local mt = customMt
38 if mt == nil then
39 mt = Basketball_mt
40 end
41
42 local self = PhysicsObject:new(isServer, isClient, mt)
43
44 self.forcedClipDistance = 150
45 registerObjectClassName(self, "Basketball")
46
47 return self
48end

delete

Description
Deleting basketball object
Definition
delete()
Return Values
booleanisAllowedis allowed
Code
52function Basketball:delete()
53 if self.i3dFilename ~= nil then
54 g_i3DManager:releaseSharedI3DFile(self.i3dFilename, nil, true)
55 end
56 unregisterObjectClassName(self)
57 Basketball:superClass().delete(self)
58end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
stringattributesattributes
Code
64function Basketball:readStream(streamId, connection)
65 if connection:getIsServer() then
66 local i3dFilename = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId))
67 if self.nodeId == 0 then
68 self:createNode(i3dFilename)
69 end
70 Basketball:superClass().readStream(self, streamId, connection)
71 end
72end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
booleansuccesssuccess
Code
78function Basketball:writeStream(streamId, connection)
79 if not connection:getIsServer() then
80 streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.i3dFilename))
81 Basketball:superClass().writeStream(self, streamId, connection)
82 end
83end

createNode

Description
Load node from i3d file
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
floatsellPricesell price
Code
88function Basketball:createNode(i3dFilename)
89 self.i3dFilename = i3dFilename
90 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename)
91 local basketballRoot = g_i3DManager:loadSharedI3DFile(i3dFilename)
92
93 local basketballId = getChildAt(basketballRoot, 0)
94 link(getRootNode(), basketballId)
95 delete(basketballRoot)
96
97 self:setNodeId(basketballId)
98end

load

Description
Load Basketball
Definition
load(string i3dFilename, float x, float y, float z, float rx, float ry, float rz)
Arguments
stringi3dFilenamei3d file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
Return Values
booleanisOnFieldis on field
Code
109function Basketball:load(i3dFilename, x,y,z, rx,ry,rz)
110 self.i3dFilename = i3dFilename
111 self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(i3dFilename)
112 self:createNode(i3dFilename)
113 setTranslation(self.nodeId, x, y, z)
114 setRotation(self.nodeId, rx, ry, rz)
115
116 return true
117end;

Bga

Description
Class for bga

onCreate

Description
Creating bga object
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
integerparentComponentid of parent component node
Code
15function Bga:onCreate(id)
16 g_logManager:error("BGA onCreate is deprecated!")
17end

new

Description
Creating bga object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
floatlastSpeedlast speed
tableinstanceInstance of object
Code
25function Bga:new(isServer, isClient, customMt)
26 local self = Object:new(isServer, isClient, customMt or Bga_mt)
27
28 self.nodeId = 0
29
30 self.digestateSilo = {}
31
32 self.bunker = {}
33 self.bunker.updateTimer = 0
34 self.bunker.money = 0
35
36 self.bgaDirtyFlag = self:getNextDirtyFlag()
37
38 return self
39end

load

Description
Load bga
Definition
load(integer nodeId)
Arguments
integernodeIdnode id
Return Values
tableownerowner
booleansuccesssuccess
Code
45function Bga:load(id, xmlFile, key)
46
47 self.nodeId = id
48
49 local siloKey = key..".digestateSilo"
50
51 local loadingNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, siloKey..".loadingStation#node"))
52 if loadingNode ~= nil then
53 local loadingStation = LoadingStation:new(self.isServer, self.isClient)
54 if loadingStation:load(loadingNode, xmlFile, siloKey..".loadingStation") then
55 self.digestateSilo.loadingStation = loadingStation
56 end
57 end
58
59 if self.digestateSilo.loadingStation == nil then
60 g_logManager:warning("Could not load loading station for '%s.loadingStation'!", siloKey)
61 return false
62 end
63
64 local storages = {}
65 local i = 0
66 while true do
67 local storageKey = string.format("%s.storages.storage(%d)", siloKey, i)
68 if not hasXMLProperty(xmlFile, storageKey) then
69 break
70 end
71
72 local storageNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, storageKey.."#node"))
73 if storageNode ~= nil then
74 local storage = Storage:new(self.isServer, self.isClient)
75 if storage:load(storageNode, xmlFile, storageKey) then
76 table.insert(storages, storage)
77 storage:setOwnerFarmId(self:getOwnerFarmId(), true)
78 else
79 g_logManager:warning("Could not load storage for '%s'!", storageKey)
80 end
81 else
82 g_logManager:warning("Missing 'node' for storage '%s'!", storageKey)
83 end
84
85 i = i + 1
86 end
87
88 if #storages == 0 then
89 g_logManager:warning("Missing digestate silo storages for bga!")
90 return false
91 end
92
93 self.digestateSilo.storages = storages
94
95
96 local bunkerKey = "placeable.bga.bunker"
97 local unloadingNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, bunkerKey..".unloadingStation#node"))
98 if unloadingNode ~= nil then
99 local unloadingStation = BgaSellStation:new(self.isServer, self.isClient, self)
100 if unloadingStation:load(unloadingNode, xmlFile, bunkerKey..".unloadingStation") then
101 self.bunker.unloadingStation = unloadingStation
102 unloadingStation:addTargetStorage(self)
103 end
104 end
105
106 if self.bunker.unloadingStation == nil then
107 g_logManager:warning("Could not load unloading station for '%s.unloadingStation'!", bunkerKey)
108 return false
109 end
110
111 self.bunker.slots = {}
112 self.bunker.fillTypeToSlot = {}
113 local i = 0
114 while true do
115 local slotKey = string.format("%s.slot(%d)", bunkerKey, i)
116 if not hasXMLProperty(xmlFile, slotKey) then
117 break
118 end
119
120 local slot = {}
121 slot.capacity = getXMLInt(xmlFile, slotKey.."#capacity") or 40000
122 slot.litersPerSecond = getXMLFloat(xmlFile, slotKey.."#litersPerSecond") or 1
123 slot.fillTypes = {}
124 slot.fillLevel = 0
125
126 slot.display = DigitalDisplay:new()
127 if not slot.display:load(self.nodeId, xmlFile, slotKey..".display") then
128 slot.display = nil
129 else
130 slot.display:setValue(0)
131 end
132
133
134 local found = false
135 local j = 0
136 while true do
137 local fillTypeKey = string.format("%s.fillType(%d)", slotKey, j)
138 if not hasXMLProperty(xmlFile, fillTypeKey) then
139 break
140 end
141
142 local fillTypeCategories = getXMLString(xmlFile, fillTypeKey .. "#fillTypeCategories")
143 local fillTypeNames = getXMLString(xmlFile, fillTypeKey .. "#fillTypes")
144 local fillTypes
145
146 if fillTypeCategories ~= nil and fillTypeNames == nil then
147 fillTypes = g_fillTypeManager:getFillTypesByCategoryNames(fillTypeCategories, "Warning: '"..tostring(key).. "' has invalid fillTypeCategory '%s'.")
148 elseif fillTypeCategories == nil and fillTypeNames ~= nil then
149 fillTypes = g_fillTypeManager:getFillTypesByNames(fillTypeNames, "Warning: '"..tostring(key).. "' has invalid fillType '%s'.")
150 else
151 g_logManager:warning("Missing fillTypeCategories or fillTypes attribute for bga slot '%s'!", slotKey)
152 end
153
154 for _,fillTypeIndex in pairs(fillTypes) do
155 if self.bunker.fillTypeToSlot[fillTypeIndex] == nil then
156 self.bunker.fillTypeToSlot[fillTypeIndex] = slot
157
158 if slot.fillTypes[fillTypeIndex] == nil then
159 found = true
160 slot.fillTypes[fillTypeIndex] = {}
161 slot.fillTypes[fillTypeIndex].fillLevel = 0
162 slot.fillTypes[fillTypeIndex].scale = getXMLFloat(xmlFile, fillTypeKey.."#scale") or 1
163 slot.fillTypes[fillTypeIndex].pricePerLiter = getXMLFloat(xmlFile, fillTypeKey.."#pricePerLiter") or 1
164 else
165 g_logManager:warning("'%s' already used for '%s'!", g_fillTypeManager:getFillTypeNameByIndex(fillTypeIndex), fillTypeKey)
166 end
167 else
168 g_logManager:warning("'%s' already used by another slot for '%s'!", g_fillTypeManager:getFillTypeNameByIndex(fillTypeIndex), slotKey)
169 end
170 end
171
172 j = j + 1
173 end
174
175 if found then
176 table.insert(self.bunker.slots, slot)
177 else
178 g_logManager:warning("No fillTypes defined for slot '%s'!", slotKey)
179 end
180
181 i = i + 1
182 end
183
184 self.samples = {}
185 if self.isClient then
186 self.samples.work = g_soundManager:loadSampleFromXML(xmlFile, "placeable.bga.sounds", "work", self.baseDirectory, self.nodeId, 0, AudioGroup.ENVIRONMENT, nil, nil)
187 end
188
189 g_currentMission.environment:addDayChangeListener(self)
190
191 return true
192end

delete

Description
Deleting bga object
Definition
delete()
Return Values
integer
Code
212function Bga:delete()
213 if self.digestateSilo.loadingStation ~= nil then
214 self.digestateSilo.loadingStation:delete()
215 end
216
217 for _, storage in ipairs(self.digestateSilo.storages) do
218 g_currentMission:removeStorage(storage)
219 storage:delete()
220 end
221
222 if self.bunker.unloadingStation ~= nil then
223 g_currentMission:removeUnloadingStation(self.bunker.unloadingStation)
224 self.bunker.unloadingStation:delete()
225 end
226
227 if self.isClient then
228 for _,sample in pairs(self.samples) do
229 g_soundManager:deleteSample(sample)
230 end
231 end
232
233 g_currentMission.environment:removeDayChangeListener(self)
234 g_messageCenter:unsubscribeAll(self)
235
236 Bga:superClass().delete(self)
237end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
booleanisFromVehicleis from vehicle
Code
289function Bga:readStream(streamId, connection)
290 if connection:getIsServer() then
291 local loadingStationId = NetworkUtil.readNodeObjectId(streamId)
292 self.digestateSilo.loadingStation:readStream(streamId, connection)
293 g_client:finishRegisterObject(self.digestateSilo.loadingStation, loadingStationId)
294
295 for _, storage in ipairs(self.digestateSilo.storages) do
296 local storageId = NetworkUtil.readNodeObjectId(streamId)
297 storage:readStream(streamId, connection)
298 g_client:finishRegisterObject(storage, storageId)
299 end
300
301 local unloadingStationId = NetworkUtil.readNodeObjectId(streamId)
302 self.bunker.unloadingStation:readStream(streamId, connection)
303 g_client:finishRegisterObject(self.bunker.unloadingStation, unloadingStationId)
304
305 for _, slot in ipairs(self.bunker.slots) do
306 slot.fillLevel = streamReadInt32(streamId)
307 if slot.display ~= nil then
308 slot.display:setValue(slot.fillLevel)
309 end
310 end
311 end
312end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
booleanisOperatingis operating
Code
318function Bga:writeStream(streamId, connection)
319 if not connection:getIsServer() then
320 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.digestateSilo.loadingStation))
321 self.digestateSilo.loadingStation:writeStream(streamId, connection)
322 g_server:registerObjectInStream(connection, self.digestateSilo.loadingStation)
323
324 for _, storage in ipairs(self.digestateSilo.storages) do
325 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(storage))
326 storage:writeStream(streamId, connection)
327 g_server:registerObjectInStream(connection, storage)
328 end
329
330 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.bunker.unloadingStation))
331 self.bunker.unloadingStation:writeStream(streamId, connection)
332 g_server:registerObjectInStream(connection, self.bunker.unloadingStation)
333
334 for _, slot in ipairs(self.bunker.slots) do
335 streamWriteInt32(streamId, slot.fillLevel)
336 end
337 end
338end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Return Values
floattotalMasstotal mass
Code
345function Bga:readUpdateStream(streamId, timestamp, connection)
346 if connection:getIsServer() then
347 local fillLevel = 0
348 for _, slot in ipairs(self.bunker.slots) do
349 slot.fillLevel = streamReadInt32(streamId)
350 fillLevel = fillLevel + slot.fillLevel
351 if slot.display ~= nil then
352 slot.display:setValue(slot.fillLevel)
353 end
354 end
355
356 if self.isClient then
357 if fillLevel > 0 then
358 if not g_soundManager:getIsSamplePlaying(self.samples.work) then
359 g_soundManager:playSample(self.samples.work)
360 end
361 else
362 if g_soundManager:getIsSamplePlaying(self.samples.work) then
363 g_soundManager:stopSample(self.samples.work)
364 end
365 end
366 end
367 end
368end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Return Values
booleansuccesssuccess
Code
375function Bga:writeUpdateStream(streamId, connection, dirtyMask)
376 if not connection:getIsServer() then
377 for _, slot in ipairs(self.bunker.slots) do
378 streamWriteInt32(streamId, slot.fillLevel)
379 end
380 end
381end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
booleansuccesssuccess
Code
389function Bga:loadFromXMLFile(xmlFile, key)
390 self.bunker.money = getXMLFloat(xmlFile, key.."#money") or 0
391
392 if not self.digestateSilo.loadingStation:loadFromXMLFile(xmlFile, key..".digestateSilo.loadingStation") then
393 return false
394 end
395
396 local i = 0
397 while true do
398 local storageKey = string.format("%s.digestateSilo.storage(%d)", key, i)
399 if not hasXMLProperty(xmlFile, storageKey) then
400 break
401 end
402
403 local index = getXMLInt(xmlFile, storageKey.."#index")
404 if index ~= nil then
405 if self.digestateSilo.storages[index] ~= nil then
406 if not self.digestateSilo.storages[index]:loadFromXMLFile(xmlFile, storageKey) then
407 return false
408 end
409 else
410 g_logManager:warning("Could not load digestateSilo storage. Given 'index' '%d' is not defined!", index)
411 end
412 end
413
414 i = i + 1
415 end
416
417 local i = 0
418 while true do
419 local slotKey = string.format("%s.slot(%d)", key, i)
420 if not hasXMLProperty(xmlFile, slotKey) then
421 break
422 end
423
424 local index = getXMLInt(xmlFile, slotKey.."#index")
425 if index ~= nil then
426 local slot = self.bunker.slots[index]
427 if slot ~= nil then
428 local j = 0
429 while true do
430 local fillTypeKey = string.format("%s.fillType(%d)", slotKey, j)
431 if not hasXMLProperty(xmlFile, fillTypeKey) then
432 break
433 end
434
435 local fillTypeName = getXMLString(xmlFile, fillTypeKey.."#fillType")
436 local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName)
437 if fillTypeIndex ~= nil and slot.fillTypes[fillTypeIndex] ~= nil then
438 slot.fillTypes[fillTypeIndex].fillLevel = getXMLFloat(xmlFile, fillTypeKey.."#fillLevel") or 0
439 slot.fillLevel = slot.fillLevel + slot.fillTypes[fillTypeIndex].fillLevel
440 end
441
442 j = j + 1
443 end
444 end
445
446 if slot.fillLevel > 0 then
447 self.bunker.isFilled = true
448 self:raiseActive()
449
450 if slot.display ~= nil then
451 slot.display:setValue(slot.fillLevel)
452 end
453 end
454 end
455
456 i = i + 1
457 end
458
459 return true
460end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Return Values
booleansuccesssuccess
Code
489function Bga:update(dt)
490 if self.bunker.isFilled then
491 self:raiseActive()
492 end
493
494 if self.isClient then
495 if self.bunker.isFilled then
496 if not g_soundManager:getIsSamplePlaying(self.samples.work) then
497 g_soundManager:playSample(self.samples.work)
498 end
499 else
500 if g_soundManager:getIsSamplePlaying(self.samples.work) then
501 g_soundManager:stopSample(self.samples.work)
502 end
503 end
504 end
505end

updateTick

Description
UpdateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Return Values
stringSchemaoverlay name which was modified if necessary
Code
510function Bga:updateTick(dt)
511 if self.isServer and self.bunker.isFilled then
512 self.bunker.updateTimer = self.bunker.updateTimer + dt
513
514 if self.bunker.updateTimer > 1000 then
515 self.bunker.isFilled = false
516
517 for _, slot in ipairs(self.bunker.slots) do
518 slot.fillLevel = 0
519
520 for _, data in pairs(slot.fillTypes) do
521 if data.fillLevel > 0 then
522 local deltaLiters = math.min(slot.litersPerSecond*g_currentMission.missionInfo.timeScale, data.fillLevel)
523 data.fillLevel = data.fillLevel - deltaLiters
524
525 local converted = deltaLiters * data.scale
526 if converted > 0 then
527 self:addDigestate( converted)
528 end
529
530 if deltaLiters > 0 then
531 self:raiseDirtyFlags(self.bgaDirtyFlag)
532 end
533 end
534
535 slot.fillLevel = slot.fillLevel + data.fillLevel
536 end
537
538 if slot.fillLevel > 0 then
539 self.bunker.isFilled = true
540 end
541
542 if slot.display ~= nil then
543 slot.display:setValue(slot.fillLevel)
544 end
545 end
546
547 self.bunker.updateTimer = 0
548 end
549 end
550end

BunkerSilo

Description
Class for bunker silo

onCreate

Description
Creating bunker silo object
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
floatlimitlimit
booleandoCheckSpeedLimitdo check speed limit
Code
23function BunkerSilo:onCreate(id)
24 g_logManager:error("BunkerSilo.onCreate is deprecated!")
25end

new

Description
Creating bunker silo object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
tableinstanceInstance of object
Code
33function BunkerSilo:new(isServer, isClient, customMt)
34
35 local self = Object:new(isServer, isClient, customMt or BunkerSilo_mt)
36
37 self.nodeId = 0
38 self.interactionTriggerNode = nil
39
40 self.bunkerSiloArea = {}
41 self.bunkerSiloArea.offsetFront = 0
42 self.bunkerSiloArea.offsetBack = 0
43
44 self.acceptedFillTypes = {}
45
46 self.inputFillType = FillType.CHAFF
47 self.outputFillType = FillType.SILAGE
48 self.fermentingFillType = FillType.TARP
49
50 self.isOpenedAtFront = false
51 self.isOpenedAtBack = false
52 self.distanceToCompactedFillLevel = 100
53
54 self.fermentingTime = 0
55 self.fermentingDuration = 6*60*60*1000 -- 6hours (ingame)
56 self.fermentingPercent = 0
57
58 self.fillLevel = 0
59 self.compactedFillLevel = 0
60 self.compactedPercent = 0
61 self.emptyThreshold = 100
62
63 self.playerInRange = false
64 self.vehiclesInRange = {}
65 self.numVehiclesInRange = 0
66
67 self.siloIsFullWarningTimer = 0
68 self.siloIsFullWarningDuration = 2000
69
70 self.updateTimer = 0
71
72 self.activatable = BunkerSiloActivatable:new(self)
73
74 self.state = BunkerSilo.STATE_FILL
75
76 self.bunkerSiloDirtyFlag = self:getNextDirtyFlag()
77
78 return self
79end

load

Description
Load bunker silo
Definition
load(integer nodeId)
Arguments
integernodeIdnode id
Return Values
floatdailyUpkeepdaily up keep
booleansuccesssuccess
Code
85function BunkerSilo:load(id, xmlFile, key)
86
87 self.nodeId = id
88
89 self.bunkerSiloArea.start = I3DUtil.indexToObject(id, getXMLString(xmlFile, key..".area#startNode"))
90 self.bunkerSiloArea.width = I3DUtil.indexToObject(id, getXMLString(xmlFile, key..".area#widthNode"))
91 self.bunkerSiloArea.height = I3DUtil.indexToObject(id, getXMLString(xmlFile, key..".area#heightNode"))
92
93 self.bunkerSiloArea.sx, self.bunkerSiloArea.sy, self.bunkerSiloArea.sz = getWorldTranslation(self.bunkerSiloArea.start)
94 self.bunkerSiloArea.wx, self.bunkerSiloArea.wy, self.bunkerSiloArea.wz = getWorldTranslation(self.bunkerSiloArea.width)
95 self.bunkerSiloArea.hx, self.bunkerSiloArea.hy, self.bunkerSiloArea.hz = getWorldTranslation(self.bunkerSiloArea.height)
96
97 self.bunkerSiloArea.dhx = self.bunkerSiloArea.hx - self.bunkerSiloArea.sx
98 self.bunkerSiloArea.dhy = self.bunkerSiloArea.hy - self.bunkerSiloArea.sy
99 self.bunkerSiloArea.dhz = self.bunkerSiloArea.hz - self.bunkerSiloArea.sz
100 self.bunkerSiloArea.dhx_norm, self.bunkerSiloArea.dhy_norm, self.bunkerSiloArea.dhz_norm = MathUtil.vector3Normalize(self.bunkerSiloArea.dhx, self.bunkerSiloArea.dhy, self.bunkerSiloArea.dhz)
101
102 self.bunkerSiloArea.dwx = self.bunkerSiloArea.wx - self.bunkerSiloArea.sx
103 self.bunkerSiloArea.dwy = self.bunkerSiloArea.wy - self.bunkerSiloArea.sy
104 self.bunkerSiloArea.dwz = self.bunkerSiloArea.wz - self.bunkerSiloArea.sz
105 self.bunkerSiloArea.dwx_norm, self.bunkerSiloArea.dwy_norm, self.bunkerSiloArea.dwz_norm = MathUtil.vector3Normalize(self.bunkerSiloArea.dwx, self.bunkerSiloArea.dwy, self.bunkerSiloArea.dwz)
106
107 self.interactionTriggerNode = I3DUtil.indexToObject(id, getXMLString(xmlFile, key..".interactionTrigger#node"))
108 if self.interactionTriggerNode ~= nil then
109 addTrigger(self.interactionTriggerNode, "interactionTriggerCallback", self)
110 end
111
112 self.acceptedFillTypes = {}
113 local data = StringUtil.splitString(" ", getXMLString(xmlFile, key.."#acceptedFillTypes") or "chaff grass_windrow dryGrass_windrow")
114 for i=1, table.getn(data) do
115 local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(data[i])
116 if fillTypeIndex ~= nil then
117 self.acceptedFillTypes[fillTypeIndex] = true
118 else
119 g_logManager:warning("'%s' is an invalid fillType for bunkerSilo '%s'!", tostring(data[i]), key.."#acceptedFillTypes")
120 end
121 end
122
123 local inputFillTypeName = getXMLString(xmlFile, key.."#inputFillType") or "chaff"
124 local inputFillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(inputFillTypeName)
125 if inputFillTypeIndex ~= nil then
126 self.inputFillType = inputFillTypeIndex
127 else
128 g_logManager:warning("'%s' is an invalid input fillType for bunkerSilo '%s'!", tostring(inputFillTypeName), key.."#inputFillType")
129 end
130
131 local outputFillTypeName = getXMLString(xmlFile, key.."#outputFillType") or "silage"
132 local outputFillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(outputFillTypeName)
133 if outputFillTypeIndex ~= nil then
134 self.outputFillType = outputFillTypeIndex
135 else
136 g_logManager:warning("'%s' is an invalid output fillType for bunkerSilo '%s'!", tostring(outputFillTypeName), key.."#outputFillType")
137 end
138
139 if self.isServer then
140 g_densityMapHeightManager:setConvertingFillTypeAreas(self.bunkerSiloArea, self.acceptedFillTypes, self.inputFillType)
141 end
142
143 self.distanceToCompactedFillLevel = getXMLFloat(xmlFile, key.."#distanceToCompactedFillLevel") or self.distanceToCompactedFillLevel
144 self.fermentingDuration = (getXMLFloat(xmlFile, key.."#fermentingHours") or 6) * 1000 * 60 * 60
145 self.openingLength = getXMLFloat(xmlFile, key.."#openingLength") or 5
146
147 self.fillLevel = 0
148
149 -- adjust timings to difficulty
150 local difficultyMultiplier = g_currentMission.missionInfo.difficulty
151 self.fermentingDuration = self.fermentingDuration*difficultyMultiplier
152 self.distanceToCompactedFillLevel = self.distanceToCompactedFillLevel/difficultyMultiplier
153
154 -- just for tutorial 12 (feeder)
155 self.isTutorialSilo = Utils.getNoNil(getXMLBool(xmlFile, key.."#isTutorialSilo"), false )
156
157 self:setState(BunkerSilo.STATE_FILL)
158
159 return true
160end

delete

Description
Deleting bunker silo object
Definition
delete()
Return Values
stringxmlxml
Code
164function BunkerSilo:delete()
165 g_currentMission:removeOnCreateLoadedObjectToSave(self)
166 if self.interactionTriggerNode ~= nil then
167 removeTrigger(self.interactionTriggerNode)
168 end
169
170 g_densityMapHeightManager:removeFixedFillTypesArea(self.bunkerSiloArea)
171 g_densityMapHeightManager:removeConvertingFillTypeAreas(self.bunkerSiloArea)
172
173 g_currentMission:removeActivatableObject(self.activatable)
174 BunkerSilo:superClass().delete(self)
175end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
tableselfinstance of class event
Code
181function BunkerSilo:readStream(streamId, connection)
182 BunkerSilo:superClass().readStream(self, streamId, connection)
183 if connection:getIsServer() then
184 local state = streamReadUIntN(streamId, 3)
185 self:setState(state)
186 self.isOpenedAtFront = streamReadBool(streamId)
187 self.isOpenedAtBack = streamReadBool(streamId)
188 self.fillLevel = streamReadFloat32(streamId)
189 self.compactedPercent = math.floor( (streamReadUIntN(streamId, 8) / 2.55) + 0.5)
190 self.fermentingPercent = math.floor( (streamReadUIntN(streamId, 8) / 2.55) + 0.5)
191 end
192end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
tableinstanceinstance of event
Code
198function BunkerSilo:writeStream(streamId, connection)
199 BunkerSilo:superClass().writeStream(self, streamId, connection)
200 if not connection:getIsServer() then
201 streamWriteUIntN(streamId, self.state, 3)
202 streamWriteBool(streamId, self.isOpenedAtFront)
203 streamWriteBool(streamId, self.isOpenedAtBack)
204 streamWriteFloat32(streamId, self.fillLevel)
205 streamWriteUIntN(streamId, 2.55*self.compactedPercent, 8)
206 streamWriteUIntN(streamId, 2.55*self.fermentingPercent, 8)
207 end
208end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Return Values
tableselfinstance of class event
Code
215function BunkerSilo:readUpdateStream(streamId, timestamp, connection)
216 BunkerSilo:superClass().readUpdateStream(self, streamId, timestamp, connection)
217 if connection:getIsServer() then
218 if streamReadBool(streamId) then
219 local state = streamReadUIntN(streamId, 3)
220 if state ~= self.state then
221 self:setState(state, true)
222 end
223
224 self.fillLevel = streamReadFloat32(streamId)
225 self.isOpenedAtFront = streamReadBool(streamId)
226 self.isOpenedAtBack = streamReadBool(streamId)
227
228 if self.state == BunkerSilo.STATE_FILL then
229 self.compactedPercent = math.floor( (streamReadUIntN(streamId, 8) / 2.55) + 0.5)
230 elseif self.state == BunkerSilo.STATE_CLOSED or self.state == BunkerSilo.STATE_FERMENTED then
231 self.fermentingPercent = math.floor( (streamReadUIntN(streamId, 8) / 2.55) + 0.5)
232 end
233 end
234 end
235end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Return Values
tableinstanceinstance of event
Code
242function BunkerSilo:writeUpdateStream(streamId, connection, dirtyMask)
243 BunkerSilo:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
244 if not connection:getIsServer() then
245 if streamWriteBool(streamId, bitAND(dirtyMask, self.bunkerSiloDirtyFlag) ~= 0) then
246 streamWriteUIntN(streamId, self.state, 3)
247
248 streamWriteFloat32(streamId, self.fillLevel)
249 streamWriteBool(streamId, self.isOpenedAtFront)
250 streamWriteBool(streamId, self.isOpenedAtBack)
251
252 if self.state == BunkerSilo.STATE_FILL then
253 streamWriteUIntN(streamId, 2.55*self.compactedPercent, 8)
254 elseif self.state == BunkerSilo.STATE_CLOSED or self.state == BunkerSilo.STATE_FERMENTED then
255 streamWriteUIntN(streamId, 2.55*self.fermentingPercent, 8)
256 end
257 end
258 end
259end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
tableselfinstance of class event
booleansuccesssuccess
Code
267function BunkerSilo:loadFromXMLFile(xmlFile, key)
268
269 local state = getXMLInt(xmlFile, key.."#state")
270 if state ~= nil then
271 if state >= 0 and state < BunkerSilo.NUM_STATES then
272 self:setState(state)
273 end
274 end
275
276 local fillLevel = getXMLFloat(xmlFile, key.."#fillLevel")
277 if fillLevel ~= nil then
278 self.fillLevel = fillLevel
279 end
280 local compactedFillLevel = getXMLFloat(xmlFile, key.."#compactedFillLevel")
281 if compactedFillLevel ~= nil then
282 self.compactedFillLevel = MathUtil.clamp(compactedFillLevel, 0, self.fillLevel)
283 end
284 self.compactedPercent = MathUtil.getFlooredPercent(math.min(self.compactedFillLevel, self.fillLevel), self.fillLevel)
285
286 local fermentingTime = getXMLFloat(xmlFile, key.."#fermentingTime")
287 if fermentingTime ~= nil then
288 self.fermentingTime = MathUtil.clamp(fermentingTime, 0, self.fermentingDuration)
289 self.fermentingPercent = MathUtil.getFlooredPercent(self.fermentingTime, self.fermentingDuration)
290 end
291
292 self.isOpenedAtFront = Utils.getNoNil(getXMLBool(xmlFile, key.."#openedAtFront"), false)
293 self.isOpenedAtBack = Utils.getNoNil(getXMLBool(xmlFile, key.."#openedAtBack"), false)
294
295 if self.isOpenedAtFront then
296 self.bunkerSiloArea.offsetFront = self:getBunkerAreaOffset(true, 0, self.outputFillType)
297 else
298 self.bunkerSiloArea.offsetFront = self:getBunkerAreaOffset(true, 0, self.fermentingFillType)
299 end
300 if self.isOpenedAtBack then
301 self.bunkerSiloArea.offsetBack = self:getBunkerAreaOffset(false, 0, self.outputFillType)
302 else
303 self.bunkerSiloArea.offsetBack = self:getBunkerAreaOffset(false, 0, self.fermentingFillType)
304 end
305
306 if self.fillLevel > 0 and self.state == BunkerSilo.STATE_DRAIN then
307 local area = self.bunkerSiloArea
308 local offWx = area.wx - area.sx
309 local offWz = area.wz - area.sz
310 local offW = math.sqrt(offWx*offWx + offWz*offWz)
311
312 local offHx = area.hx - area.sx
313 local offHz = area.hz - area.sz
314 local offH = math.sqrt(offHx*offHx + offHz*offHz)
315
316 if offW > 0.001 and offH > 0.001 then
317 -- offset by 0.9m in each direction (and max 45%)
318 local offWScale = math.min(0.45, 0.9 / offW)
319 offWx = offWx * offWScale
320 offWz = offWz * offWScale
321
322 local offHScale = math.min(0.45, 0.9 / offH)
323 offHx = offHx * offHScale
324 offHz = offHz * offHScale
325
326 local innerFillLevel1 = DensityMapHeightUtil.getFillLevelAtArea(self.fermentingFillType, area.sx+offWx+offHx,area.sz+offWz+offHz, area.wx-offWx+offHx,area.wz-offWz+offHz, area.hx+offWx-offHx,area.hz+offWz-offHz)
327 local innerFillLevel2 = DensityMapHeightUtil.getFillLevelAtArea(self.outputFillType, area.sx+offWx+offHx,area.sz+offWz+offHz, area.wx-offWx+offHx,area.wz-offWz+offHz, area.hx+offWx-offHx,area.hz+offWz-offHz)
328 local innerFillLevel = innerFillLevel1 + innerFillLevel2
329 if innerFillLevel < self.emptyThreshold*0.5 then
330 DensityMapHeightUtil.removeFromGroundByArea(area.sx,area.sz, area.wx,area.wz, area.hx,area.hz, self.fermentingFillType)
331 DensityMapHeightUtil.removeFromGroundByArea(area.sx,area.sz, area.wx,area.wz, area.hx,area.hz, self.outputFillType)
332 self:setState(BunkerSilo.STATE_FILL, false)
333 end
334 end
335 elseif self.state == BunkerSilo.STATE_FILL then
336 local area = self.bunkerSiloArea
337 local fermentingFillLevel, fermentingPixels, totalFermentingPixels = DensityMapHeightUtil.getFillLevelAtArea(self.fermentingFillType, area.sx,area.sz, area.wx,area.wz, area.hx,area.hz)
338 -- Set to fermented state if more than 50% of the area is filled with fermenting fill type
339 if fermentingFillLevel > self.emptyThreshold and fermentingPixels > 0.5 * totalFermentingPixels then
340 local inputFillLevel, inputPixels, totalInputPixels = DensityMapHeightUtil.getFillLevelAtArea(self.inputFillType, area.sx,area.sz, area.wx,area.wz, area.hx,area.hz)
341 -- Only change if less than 10% is filled with input type (chaff) (ie. the silo is not being filled)
342 if inputPixels < 0.1*totalInputPixels then
343 self:setState(BunkerSilo.STATE_FERMENTED, false)
344 end
345 end
346 end
347
348 return true
349end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Return Values
tableinstanceinstance of event
Code
363function BunkerSilo:update(dt)
364
365 if self:getCanInteract(true) then
366 local fillTypeIndex = self.inputFillType
367 if self.state == BunkerSilo.STATE_CLOSED or self.state == BunkerSilo.STATE_FERMENTED or self.state == BunkerSilo.STATE_DRAIN then
368 fillTypeIndex = self.outputFillType
369 end
370 local fillTypeName = ""
371 local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex)
372 if fillType ~= nil then
373 fillTypeName = fillType.title
374 end
375 if self.state == BunkerSilo.STATE_FILL then
376 g_currentMission:addExtraPrintText(g_i18n:getText("info_fillLevel")..string.format(" %s: %d", fillTypeName, self.fillLevel))
377 g_currentMission:addExtraPrintText(g_i18n:getText("info_compacting")..string.format(" %d%%", self.compactedPercent))
378 elseif self.state == BunkerSilo.STATE_CLOSED or self.state == BunkerSilo.STATE_FERMENTED then
379 g_currentMission:addExtraPrintText(g_i18n:getText("info_fermenting")..string.format(" %s: %d%%", fillTypeName, self.fermentingPercent))
380 elseif self.state == BunkerSilo.STATE_DRAIN then
381 g_currentMission:addExtraPrintText(g_i18n:getText("info_fillLevel")..string.format(" %s: %d", fillTypeName, self.fillLevel))
382 end
383 end
384
385 if self.state == BunkerSilo.STATE_CLOSED then
386 if self.isServer then
387 self.fermentingTime = math.min(self.fermentingDuration, self.fermentingTime + dt*g_currentMission.missionInfo.timeScale)
388 local fermentingPercent = MathUtil.getFlooredPercent(self.fermentingTime, self.fermentingDuration)
389 if fermentingPercent ~= self.fermentingPercent then
390 self.fermentingPercent = fermentingPercent
391 self:raiseDirtyFlags(self.bunkerSiloDirtyFlag)
392 end
393 if self.fermentingTime >= self.fermentingDuration then
394 self:setState(BunkerSilo.STATE_FERMENTED, true)
395 end
396 end
397 end
398
399 if self.isServer then
400 if self.state == BunkerSilo.STATE_FILL then
401 for vehicle,state in pairs(self.vehiclesInRange) do
402 if state then
403 if vehicle:getIsActive() then
404 local distance = vehicle.lastMovedDistance
405 if distance > 0 then
406 local mass = vehicle:getTotalMass(false)
407
408 local refNode = vehicle.components[1].node
409 local scale = (mass / BunkerSilo.COMPACTING_BASE_MASS)
410
411 local bunkerSiloCompacter
412 if vehicle.getBunkerSiloCompacter ~= nil then
413 bunkerSiloCompacter = vehicle:getBunkerSiloCompacter()
414 end
415 if bunkerSiloCompacter ~= nil then
416 if bunkerSiloCompacter.refNode ~= nil then
417 refNode = bunkerSiloCompacter.refNode
418 end
419 if bunkerSiloCompacter.scale ~= nil then
420 scale = (mass / BunkerSilo.COMPACTING_BASE_MASS) * bunkerSiloCompacter.scale
421 end
422 end
423
424 local deltaCompact = distance*scale*self.distanceToCompactedFillLevel
425
426 local wheels = vehicle:getWheels()
427 local numWheels = #wheels
428 if numWheels > 0 then
429 local wheelsOnSilo = 0
430 local wheelsInAir = 0
431 for _, wheel in ipairs(wheels) do
432 if wheel.contact == Wheels.WHEEL_GROUND_HEIGHT_CONTACT then
433 wheelsOnSilo = wheelsOnSilo + 1
434 elseif wheel.contact == Wheels.WHEEL_NO_CONTACT then
435 wheelsInAir = wheelsInAir + 1
436 end
437 end
438 if wheelsOnSilo > 0 then
439 deltaCompact = deltaCompact * ((wheelsOnSilo + wheelsInAir) / numWheels)
440 else
441 deltaCompact = 0
442 end
443 end
444
445 if deltaCompact > 0 then
446 local compactedFillLevel = math.min(self.compactedFillLevel + deltaCompact, self.fillLevel)
447 if compactedFillLevel ~= self.compactedFillLevel then
448 self.compactedFillLevel = compactedFillLevel
449 self.compactedPercent = MathUtil.getFlooredPercent(math.min(self.compactedFillLevel, self.fillLevel), self.fillLevel)
450 self:raiseDirtyFlags(self.bunkerSiloDirtyFlag)
451 end
452 end
453 end
454 end
455 end
456 end
457 end
458 end
459
460 -- for chaff tutorial: always take the highest fill level of all bunker silos
461 if g_currentMission ~= nil and g_currentMission.bunkerScore ~= nil then
462 if g_currentMission.bunkerScore < self.fillLevel then
463 g_currentMission.bunkerScore = self.fillLevel
464 end
465 end
466
467 self:raiseActive()
468end

updateTick

Description
UpdateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Return Values
tableinstanceInstance of object
Code
473function BunkerSilo:updateTick(dt)
474 if self.isServer then
475 self.updateTimer = self.updateTimer - dt
476 if self.updateTimer <= 0 then
477 self.updateTimer = 200 + math.random()*100 -- update every 200 to 300ms
478
479 local oldFillLevel = self.fillLevel
480 self:updateFillLevel()
481 if oldFillLevel ~= self.fillLevel then
482 self:raiseDirtyFlags(self.bunkerSiloDirtyFlag)
483 end
484 end
485 end
486 if not self.adjustedOpeningLength then
487 self.adjustedOpeningLength = true
488 self.openingLength = math.max(self.openingLength, DensityMapHeightUtil.getDefaultMaxRadius(self.outputFillType)+1)
489 end
490end

setState

Description
Set state
Definition
setState(boolean state, boolean showNotification)
Arguments
booleanstatenew state
booleanshowNotificationshow notification
Return Values
booleansuccesssuccess
Code
524function BunkerSilo:setState(state, showNotification)
525
526 if state ~= self.state then
527
528 if state == BunkerSilo.STATE_FILL then
529
530 self.fermentingTime = 0
531 self.fermentingPercent = 0
532 self.compactedFillLevel = 0
533 self.isOpenedAtFront = false
534 self.isOpenedAtBack = false
535 self.bunkerSiloArea.offsetFront = 0
536 self.bunkerSiloArea.offsetBack = 0
537
538 if showNotification then
539 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_INFO, g_i18n:getText("ingameNotification_bunkerSiloIsEmpty"))
540 end
541
542 if self.isServer then
543 g_densityMapHeightManager:removeFixedFillTypesArea(self.bunkerSiloArea)
544 g_densityMapHeightManager:setConvertingFillTypeAreas(self.bunkerSiloArea, self.acceptedFillTypes, self.inputFillType)
545 end
546
547 elseif state == BunkerSilo.STATE_CLOSED then
548
549 if self.isServer then
550 -- change fillType
551 local area = self.bunkerSiloArea
552 local offsetFront = self:getBunkerAreaOffset(true, 0, self.inputFillType)
553 local offsetBack = self:getBunkerAreaOffset(false, 0, self.inputFillType)
554
555 local x0 = area.sx + (offsetFront * area.dhx_norm)
556 local z0 = area.sz + (offsetFront * area.dhz_norm)
557 local x1 = x0 + area.dwx
558 local z1 = z0 + area.dwz
559 local x2 = area.sx + area.dhx - (offsetBack * area.dhx_norm)
560 local z2 = area.sz + area.dhz - (offsetBack * area.dhz_norm)
561
562 local changed = DensityMapHeightUtil.changeFillTypeAtArea(x0,z0, x1,z1, x2,z2, self.inputFillType, self.fermentingFillType)
563
564 g_densityMapHeightManager:removeFixedFillTypesArea(self.bunkerSiloArea)
565 g_densityMapHeightManager:removeConvertingFillTypeAreas(self.bunkerSiloArea)
566 end
567
568 if showNotification then
569 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_INFO, g_i18n:getText("ingameNotification_bunkerSiloCovered"))
570 end
571
572 elseif state == BunkerSilo.STATE_FERMENTED then
573
574 if showNotification then
575 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_INFO, g_i18n:getText("ingameNotification_bunkerSiloDoneFermenting"))
576 end
577
578 elseif state == BunkerSilo.STATE_DRAIN then
579
580 self.bunkerSiloArea.offsetFront = 0
581 self.bunkerSiloArea.offsetBack = 0
582
583 if showNotification then
584 g_currentMission:addIngameNotification(FSBaseMission.INGAME_NOTIFICATION_INFO, g_i18n:getText("ingameNotification_bunkerSiloOpened"))
585 end
586
587 if self.isServer then
588 g_densityMapHeightManager:removeConvertingFillTypeAreas(self.bunkerSiloArea)
589 local fillTypes = {}
590 fillTypes[self.outputFillType] = true
591 g_densityMapHeightManager:setFixedFillTypesArea(self.bunkerSiloArea, fillTypes)
592 end
593
594 end
595
596 self.state = state
597 if self.isServer then
598 self:raiseDirtyFlags(self.bunkerSiloDirtyFlag)
599 end
600 end
601end

openSilo

Description
Open silo
Definition
openSilo(float px, float py, float pz)
Arguments
floatpxx player position
floatpyy player position
floatpzz player position
Return Values
floatnewXnew x position
floatnewYnew y position
floatnewZnew z position
Code
608function BunkerSilo:openSilo(px,py,pz)
609 self:setState(BunkerSilo.STATE_DRAIN, true)
610
611 self.bunkerSiloArea.offsetFront = self:getBunkerAreaOffset(true, 0, self.fermentingFillType)
612 self.bunkerSiloArea.offsetBack = self:getBunkerAreaOffset(false, 0, self.fermentingFillType)
613
614 -- check which side is closer to player
615 local openAtFront = self:getIsCloserToFront(px,py,pz)
616 if openAtFront and not self.isOpenedAtFront then
617 self:switchFillTypeAtOffset(true, self.bunkerSiloArea.offsetFront, self.openingLength)
618 self.isOpenedAtFront = true
619 self:raiseDirtyFlags(self.bunkerSiloDirtyFlag)
620 elseif not self.isOpenedAtBack then
621 self:switchFillTypeAtOffset(false, self.bunkerSiloArea.offsetBack, self.openingLength)
622 self.isOpenedAtBack = true
623 self:raiseDirtyFlags(self.bunkerSiloDirtyFlag)
624 end
625end

getBunkerAreaOffset

Description
Get bunker area offset
Definition
getBunkerAreaOffset(boolean updateAtFront, float offset, integer fillType)
Arguments
booleanupdateAtFrontupdate at front
floatoffsetoffset
integerfillTypefill type
Return Values
floatoffsetoffset
Code
633function BunkerSilo:getBunkerAreaOffset(updateAtFront, offset, fillType)
634 local area = self.bunkerSiloArea
635
636 local hx, hz = area.dhx_norm, area.dhz_norm
637 local hl = MathUtil.vector3Length(area.dhx, area.dhy, area.dhz)
638
639 while offset <= (hl - 1) do
640 local pos = offset
641 if not updateAtFront then
642 pos = hl - offset - 1
643 end
644 local d1x,d1z = pos*hx, pos*hz
645 local d2x,d2z = (pos+1)*hx, (pos+1)*hz
646
647 local a0x, a0z = area.sx + d1x, area.sz + d1z
648 local a1x, a1z = area.wx + d1x, area.wz + d1z
649 local a2x, a2z = area.sx + d2x, area.sz + d2z
650
651 local fillLevel = DensityMapHeightUtil.getFillLevelAtArea(fillType, a0x,a0z, a1x,a1z, a2x,a2z)
652 if fillLevel > 0 then
653 return offset
654 end
655 offset = offset + 1
656 end
657
658 return math.max(hl - 1, 0)
659end

switchFillTypeAtOffset

Description
Switch fill type at offset
Definition
switchFillTypeAtOffset(boolean switchAtFront, float offset, float length)
Arguments
booleanswitchAtFrontswitch at front
floatoffsetoffset
floatlengthlength
Code
666function BunkerSilo:switchFillTypeAtOffset(switchAtFront, offset, length)
667
668 local fillType = self.fermentingFillType
669 local newFillType = self.outputFillType
670
671 local a0x, a0z = nil, nil
672 local a1x, a1z = nil, nil
673 local a2x, a2z = nil, nil
674
675 local area = self.bunkerSiloArea
676
677 if switchAtFront then
678 a0x, a0z = area.sx + (offset * area.dhx_norm), area.sz + (offset * area.dhz_norm)
679 a1x, a1z = a0x + area.dwx, a0z + area.dwz
680 a2x, a2z = area.sx + ((offset + length) * area.dhx_norm), area.sz + ((offset + length) * area.dhz_norm)
681 else
682 a0x, a0z = area.hx - (offset * area.dhx_norm), area.hz - (offset * area.dhz_norm)
683 a1x, a1z = a0x + area.dwx, a0z + area.dwz
684 a2x, a2z = area.hx - ((offset + length) * area.dhx_norm), area.hz - ((offset + length) * area.dhz_norm)
685 end
686
687 DensityMapHeightUtil.changeFillTypeAtArea(a0x,a0z, a1x,a1z, a2x,a2z, fillType, newFillType)
688
689end

getIsCloserToFront

Description
Get is closer to front
Definition
getIsCloserToFront(float ix, float iy, float iz)
Arguments
floatixx position
floatiyy position
floatizz position
Return Values
booleanhasCollisionhas collision
floatcollisionDistancedistance to collision
floatnormalXnormal x
floatnormalYnormal y
floatnormalZnormal z
floatnormalDotDirnormal dot direction
booleanisCloserToFrontis closer to front
Code
697function BunkerSilo:getIsCloserToFront(ix,iy,iz)
698 local area = self.bunkerSiloArea
699
700 local x = area.sx + (0.5*area.dwx) + (area.offsetFront * area.dhx_norm)
701 local y = area.sy + (0.5*area.dwy) + (area.offsetFront * area.dhy_norm)
702 local z = area.sz + (0.5*area.dwz) + (area.offsetFront * area.dhz_norm)
703 local distFront = MathUtil.vector3Length(x-ix, y-iy, z-iz)
704
705 local x = area.sx + (0.5*area.dwx) + area.dhx - (area.offsetBack * area.dhx_norm)
706 local y = area.sy + (0.5*area.dwy) + area.dhy - (area.offsetBack * area.dhy_norm)
707 local z = area.sz + (0.5*area.dwz) + area.dhz - (area.offsetBack * area.dhz_norm)
708 local distBack = MathUtil.vector3Length(x-ix, y-iy, z-iz)
709
710 return distFront < distBack
711end

getCanInteract

Description
Get can interact with silo
Definition
getCanInteract(boolean showInformationOnly)
Arguments
booleanshowInformationOnlyshow information only
Return Values
booleancanInteractcan interact
Code
717function BunkerSilo:getCanInteract(showInformationOnly)
718 if showInformationOnly then
719 if (g_currentMission.controlPlayer and self.playerInRange) then
720 return true
721 end
722 if not g_currentMission.controlPlayer then
723 for vehicle in pairs(self.vehiclesInRange) do
724 if vehicle:getIsActiveForInput(true) then
725 return true
726 end
727 end
728 end
729 else
730 if (g_currentMission.controlPlayer and self.playerInRange) then
731 --if next(self.vehiclesInRange) == nil then
732 return true
733 --end
734 end
735 end
736 return false
737end

getCanCloseSilo

Description
Get can close silo
Definition
getCanCloseSilo()
Return Values
booleancanClosecan close silo
Code
742function BunkerSilo:getCanCloseSilo()
743 return self.state == BunkerSilo.STATE_FILL and self.fillLevel > 0 and self.compactedPercent >= 100
744end

getCanOpenSilo

Description
Get can open silo
Definition
getCanOpenSilo()
Return Values
booleancanOpencan open silo
Code
749function BunkerSilo:getCanOpenSilo()
750 if not (self.state == BunkerSilo.STATE_FERMENTED or self.state == BunkerSilo.STATE_DRAIN) then
751 return false
752 end
753 local ix,iy,iz = self:getInteractionPosition()
754 if ix ~= nil then
755 local closerToFront = self:getIsCloserToFront(ix,iy,iz)
756 if closerToFront and not self.isOpenedAtFront then
757 return true
758 end
759 if not closerToFront and not self.isOpenedAtBack then
760 return true
761 end
762 end
763 return false
764end

getInteractionPosition

Description
Get interact position
Definition
getInteractionPosition()
Return Values
floatxx world position
floatyy world position
floatzz world position
Code
778function BunkerSilo:getInteractionPosition()
779 if g_currentMission.controlPlayer and self.playerInRange then
780 return getWorldTranslation(g_currentMission.player.rootNode)
781 else
782 if self.vehiclesInRange[g_currentMission.currentVehicle] ~= nil then
783 return getWorldTranslation(self.vehiclesInRange[g_currentMission.currentVehicle].components[1].node)
784 end
785 end
786 return nil
787end

interactionTriggerCallback

Description
interactionTriggerCallback
Definition
interactionTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay, integer otherId)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
integerotherIdid of other actor
Code
797function BunkerSilo:interactionTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId)
798 if onEnter or onLeave then
799 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
800 if onEnter then
801 self.playerInRange = true
802 g_currentMission:removeActivatableObject(self.activatable) -- make sure it is not added twice
803 g_currentMission:addActivatableObject(self.activatable)
804 else
805 self.playerInRange = false
806 if self.numVehiclesInRange == 0 then
807 g_currentMission:removeActivatableObject(self.activatable)
808 end
809 end
810 else
811 --local vehicle = g_currentMission.nodeToObject[otherId]
812 local vehicle = g_currentMission.nodeToObject[otherShapeId]
813 if vehicle ~= nil then
814 if onEnter then
815 if self.vehiclesInRange[vehicle] == nil then
816 self.vehiclesInRange[vehicle] = true
817 self.numVehiclesInRange = self.numVehiclesInRange + 1
818
819 g_currentMission:removeActivatableObject(self.activatable) -- make sure it is not added twice
820 g_currentMission:addActivatableObject(self.activatable)
821
822 -- add callback if shovel
823 if vehicle.setChangedFillLevelCallback ~= nil then
824 vehicle:setChangedFillLevelCallback(BunkerSilo.onChangedFillLevelCallback, self)
825 end
826 end
827 else
828 if self.vehiclesInRange[vehicle] then
829 self.vehiclesInRange[vehicle] = nil
830 self.numVehiclesInRange = self.numVehiclesInRange - 1
831
832 if self.numVehiclesInRange == 0 and not self.playerInRange then
833 g_currentMission:removeActivatableObject(self.activatable)
834 end
835
836 -- remove callback if shovel
837 if vehicle.setChangedFillLevelCallback ~= nil then
838 vehicle:setChangedFillLevelCallback(nil)
839 end
840 end
841 end
842 end
843 end
844 end
845end

onChangedFillLevelCallback

Description
Called if fill level changed
Definition
onChangedFillLevelCallback(table vehicle, integer fillDelta, integer fillType)
Arguments
tablevehiclevehicle
integerfillDeltafill delta
integerfillTypefill type
Return Values
tableselfinstance of class event
Code
852function BunkerSilo.onChangedFillLevelCallback(self, vehicle, fillDelta, fillType)
853 if fillDelta >= 0 then
854 return
855 end
856
857 local area = self.bunkerSiloArea
858
859 local x,y,z = getWorldTranslation(vehicle.components[1].node)
860 local closerToFront = self:getIsCloserToFront(x,y,z)
861
862 if vehicle.shovel ~= nil and vehicle.shovel.pickUp ~= nil and vehicle.shovel.pickUp.node ~= nil then
863 x,y,z = localToWorld(vehicle.shovel.pickUp.node, 0, 0, vehicle.shovel.pickUp.length)
864 end
865
866 local length = self.openingLength
867
868 if closerToFront then
869 if self.isOpenedAtFront then
870 local p1 = MathUtil.getProjectOnLineParameter(x,z, area.sx,area.sz, area.dhx_norm,area.dhz_norm)
871 if p1 > area.offsetFront - length then
872 local offset = self:getBunkerAreaOffset(true, area.offsetFront, self.fermentingFillType)
873 local targetOffset = math.max(p1, offset) + length
874
875 self:switchFillTypeAtOffset(true, area.offsetFront, targetOffset - area.offsetFront)
876 area.offsetFront = targetOffset
877 end
878 end
879 else
880 if self.isOpenedAtBack then
881 local p1 = MathUtil.getProjectOnLineParameter(x,z, area.hx,area.hz, -area.dhx_norm,-area.dhz_norm)
882 if p1 > area.offsetBack - length then
883 local offset = self:getBunkerAreaOffset(true, area.offsetBack, self.fermentingFillType)
884 local targetOffset = math.max(p1, offset) + length
885
886 self:switchFillTypeAtOffset(false, area.offsetBack, targetOffset - area.offsetBack)
887 area.offsetBack = targetOffset
888 end
889 end
890 end
891end

Farmland

Description
Class for field definitions

new

Description
Create field definition object
Definition
new()
Return Values
tableinstanceInstance of object
Code
25function Farmland:new(customMt)
26 local self = setmetatable({}, customMt or Farmland_mt)
27
28 self.isOwned = false
29 self.xWorldPos = 0
30 self.zWorldPos = 0
31
32 return self
33end

load

Description
Load farmland data from xml
Definition
load(integer xmlFile, string key)
Arguments
integerxmlFilehandle of xml file
stringkeycurrent xml element key
Return Values
booleantrueif loading was successful else false
Code
40function Farmland:load(xmlFile, key)
41 self.id = getXMLInt(xmlFile, key.."#id")
42
43 if self.id == nil or self.id == 0 then
44 print("Error: Invalid farmland id '"..tostring(self.id).."'!")
45 return false
46 end
47
48 self.name = Utils.getNoNil(getXMLString(xmlFile, key.."#name"), "")
49 self.areaInHa = Utils.getNoNil(getXMLFloat(xmlFile, key.."#areaInHa"), 2.5)
50
51 self.fixedPrice = getXMLFloat(xmlFile, key.."#price")
52 if self.fixedPrice == nil then
53 self.priceFactor = Utils.getNoNil(getXMLFloat(xmlFile, key.."#priceScale"), 1)
54 end
55 self.price = self.fixedPrice or 1
56
57 self:updatePrice()
58
59 local npc = g_npcManager:getNPCByIndex(getXMLInt(xmlFile, key.."#npcIndex"))
60 self.npcIndex = g_npcManager:getRandomIndex()
61 if npc ~= nil then
62 self.npcIndex = npc.index
63 end
64
65 -- Names are used with custom NPC sets
66 local npc = g_npcManager:getNPCByName(getXMLString(xmlFile, key.."#npcName"))
67 if npc ~= nil then
68 self.npcIndex = npc.index
69 end
70
71 self.isOwned = false
72 self.defaultFarmProperty = Utils.getNoNil(getXMLBool(xmlFile, key.."#defaultFarmProperty"), false)
73
74 return true
75end

delete

Description
Delete field definition object
Definition
delete()
Code
79function Farmland:delete()
80end

setFarmlandIndicatorPosition

Description
Set farmland area indicator world position
Definition
setFarmlandIndicatorPosition(float xWorldPos, float zWorldPos)
Arguments
floatxWorldPosfarmland indicator x world position
floatzWorldPosfarmland size in ha
Code
86function Farmland:setFarmlandIndicatorPosition(xWorldPos, zWorldPos)
87 self.xWorldPos, self.zWorldPos = xWorldPos, zWorldPos
88end

setArea

Description
Set farmland area
Definition
setArea(float areaInHa)
Arguments
floatareaInHafarmland size in ha
Code
93function Farmland:setArea(areaInHa)
94 self.areaInHa = areaInHa
95 if self.fixedPrice == nil then
96 self:updatePrice()
97 end
98end

Field

Description
Class for field definitions

new

Description
Create ai field definition object
Definition
new()
Return Values
tableinstanceInstance of object
Code
19function Field:new(customMt)
20 local self = {}
21 setmetatable(self, customMt or Field_mt)
22
23 self.fieldId = 0
24 self.posX = 0
25 self.posZ = 0
26 self.rootNode = nil
27 self.name = nil
28 self.mapHotspot = nil
29 self.fieldMissionAllowed = true
30 self.fieldGrassMission = false
31 self.fieldAngle = 0.0
32 self.fieldDimensions = nil
33 self.fieldArea = 1.0
34 self.getFieldStatusPartitions = {}
35 self.setFieldStatusPartitions = {}
36 self.maxFieldStatusPartitions = {}
37 self.isAIActive = true
38 self.fruitType = nil -- current fruit in the field, as seen by FJM
39 self.lastCheckedTime = nil
40
41 self.currentMission = nil
42
43 return self
44end

load

Description
Load Field data from node
Definition
load(integer id)
Arguments
integeridai field node id
Return Values
booleantrueif loading was successful else false
Code
50function Field:load(id)
51 self.rootNode = id
52 self.name = Utils.getNoNil(getUserAttribute(id, "name"), "")
53
54 self.fieldMissionAllowed = Utils.getNoNil(getUserAttribute(id, "fieldMissionAllowed"), true)
55 self.fieldGrassMission = Utils.getNoNil(getUserAttribute(id, "fieldGrassMission"), false)
56
57 local fieldDimensions = I3DUtil.indexToObject(id, getUserAttribute(id, "fieldDimensionIndex"))
58 if fieldDimensions == nil then
59 print("Warning: No fieldDimensionIndex defined for Field '"..getName(id).."'!")
60 return false
61 end
62 local angleRad = math.rad(Utils.getNoNil(tonumber(getUserAttribute(id, "fieldAngle")), 0))
63
64 self.fieldAngle = FSDensityMapUtil.convertToDensityMapAngle(angleRad, g_currentMission.terrainDetailAngleMaxValue)
65 self.fieldDimensions = fieldDimensions
66
67 FieldUtil.updateFieldPartitions(self, self.getFieldStatusPartitions, 900)
68 FieldUtil.updateFieldPartitions(self, self.setFieldStatusPartitions, 400)
69 FieldUtil.updateFieldPartitions(self, self.maxFieldStatusPartitions, 10000000)
70
71 self.posX, self.posZ = FieldUtil.getCenterOfField(self)
72
73 self.nameIndicator = I3DUtil.indexToObject(id, getUserAttribute(id, "nameIndicatorIndex")) -- this is where the field number appears on the ingamemap
74 if self.nameIndicator ~= nil then
75 local x, _, z = getWorldTranslation(self.nameIndicator)
76 self.posX, self.posZ = x, z
77 end
78
79 self.farmland = nil
80
81 return true
82end

delete

Description
Delete field definition object
Definition
delete()
Code
86function Field:delete()
87 if self.mapHotspot == nil then
88 g_currentMission:removeMapHotspot(self.mapHotspot)
89 self.mapHotspot:delete()
90 self.mapHotspot = nil
91 end
92end

HelpIcons

Description
Class for help icons

onCreate

Description
Creating help icons
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
floatmaxClutchTorquemax clutch torque
Code
17function HelpIcons:onCreate(id)
18 local helpIcons = HelpIcons:new(id);
19 g_currentMission:addNonUpdateable(helpIcons);
20 g_currentMission.helpIconsBase = helpIcons;
21end;

new

Description
Creating help icons
Definition
new(integer name)
Arguments
integernamenode id
Return Values
floatrotInertiarotation inertia
tableinstanceInstance of object
Code
27function HelpIcons:new(name)
28 local self = {};
29 setmetatable(self, HelpIcons_mt);
30
31 self.me = name;
32 local num = getNumOfChildren(self.me);
33
34 self.helpIcons = {};
35 for i = 0, num - 1 do
36 local helpIconTriggerId = getChildAt(self.me, i);
37 local helpIconId = getChildAt(helpIconTriggerId, 0);
38 local helpIconCustomNumber = Utils.getNoNil(getUserAttribute(helpIconTriggerId, "customNumber"), 0);
39 addTrigger(helpIconTriggerId, "triggerCallback", self);
40 local helpIcon = {helpIconTriggerId = helpIconTriggerId, helpIconId = helpIconId, helpIconCustomNumber = helpIconCustomNumber};
41 table.insert(self.helpIcons, helpIcon);
42 end;
43 self.visible = true;
44
45 return self;
46end;

delete

Description
Deleting help icons
Definition
delete()
Return Values
floatdampingRatedamping rate [t m^2 s^-1]
Code
50function HelpIcons:delete()
51 for _, helpIcon in pairs(self.helpIcons) do
52 removeTrigger(helpIcon.helpIconTriggerId);
53 end;
54end;

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Return Values
floatdampingRatedamping rate [t m^2 s^-1]
Code
71function HelpIcons:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
72 if onEnter then -- and g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode and g_currentMission.controlPlayer then
73 -- only trigger if the player or a vehicle controlled by the player enters
74 if (g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode and g_currentMission.controlPlayer) or (g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.nodeToObject[otherId]) then
75 local missionInfo = g_currentMission.missionInfo
76
77 for i, helpIcon in ipairs(self.helpIcons) do -- order is important for savegame
78 if helpIcon.helpIconTriggerId == triggerId then
79 if getVisibility(helpIcon.helpIconId) then
80 setVisibility(helpIcon.helpIconId, false);
81 setCollisionMask(helpIcon.helpIconTriggerId, 0);
82
83 -- update help icon string
84 missionInfo.foundHelpIcons = "";
85 for _, helpIcon in ipairs(self.helpIcons) do
86 if getVisibility(helpIcon.helpIconId) then
87 missionInfo.foundHelpIcons = missionInfo.foundHelpIcons .. "0";
88 else
89 missionInfo.foundHelpIcons = missionInfo.foundHelpIcons .. "1";
90 end;
91 end;
92
93 local messageNumber = helpIcon.helpIconCustomNumber;
94 if messageNumber == 0 then
95 messageNumber = i;
96 end;
97 g_currentMission.inGameMessage:showMessage(g_i18n:getText("helpIcon_title" .. messageNumber), g_i18n:getText("helpIcon_text" .. messageNumber), 0);
98 end;
99 end;
100 end;
101
102 end;
103 end;
104end;

showHelpIcons

Description
Show help icons
Definition
showHelpIcons(boolean visible, boolean clearIconStates)
Arguments
booleanvisiblevisible
booleanclearIconStatesclear icon states
Return Values
floatdampingRatedamping rate [t m^2 s^-1]
Code
110function HelpIcons:showHelpIcons(visible, clearIconStates)
111 self.visible = visible;
112
113 local oldStates = g_currentMission.missionInfo.foundHelpIcons;
114
115 for i, helpIcon in ipairs(self.helpIcons) do
116 local isVisible = visible
117 if clearIconStates == nil or not clearIconStates then
118 isVisible = isVisible and string.sub(oldStates, i, i) == "0";
119 end;
120
121 setVisibility(helpIcon.helpIconId, isVisible);
122 if isVisible then
123 setCollisionMask(helpIcon.helpIconTriggerId, 3145728);
124 else
125 setCollisionMask(helpIcon.helpIconTriggerId, 0);
126 end;
127 end;
128
129end;

deleteHelpIcon

Description
Delete help icon
Definition
deleteHelpIcon(integer i)
Arguments
integeriid of help icon
Return Values
floatmaxMotorTorquemax motor torque
Code
134function HelpIcons:deleteHelpIcon(i)
135 if self.helpIcons[i] ~= nil then
136 setVisibility(self.helpIcons[i].helpIconId, false);
137 setCollisionMask(self.helpIcons[i].helpIconTriggerId, 0);
138 end;
139end;

LoadingStation

Description

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
floatbrakeForcebrake force
Code
98function LoadingStation:readStream(streamId, connection)
99 LoadingStation:superClass().readStream(self, streamId, connection)
100 if connection:getIsServer() then
101 for _, loadTrigger in ipairs(self.loadTriggers) do
102 local loadTriggerId = NetworkUtil.readNodeObjectId(streamId)
103 loadTrigger:readStream(streamId, connection)
104 g_client:finishRegisterObject(loadTrigger, loadTriggerId)
105 end
106 end
107end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
floatminRpmmin rpm
Code
113function LoadingStation:writeStream(streamId, connection)
114 LoadingStation:superClass().writeStream(self, streamId, connection)
115 if not connection:getIsServer() then
116 for _, loadTrigger in ipairs(self.loadTriggers) do
117 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(loadTrigger))
118 loadTrigger:writeStream(streamId, connection)
119 g_server:registerObjectInStream(connection, loadTrigger)
120 end
121 end
122end

getIsFillAllowedToFarm

Description
Get whether the given farm is allowed to fill objects from this loading station.
Definition
getIsFillAllowedToFarm()
Return Values
floatmaxRpmmax rpm

NightIllumination

Description
Class for NightIllumination objects which are used for building windows that are illuminated at night

onCreate

Description
Creating NightIllumination object
Definition
onCreate(integer id)
Arguments
integeridID of the node
Return Values
floatminRequiredRpmmin required rpm
floatminRequiredRpmmax required rpm
Code
19function NightIllumination:onCreate(id)
20 g_currentMission:addNonUpdateable(NightIllumination:new(id))
21end

new

Description
Creating NightIllumination object
Definition
new(integer name)
Arguments
integernameID of the node
Return Values
tableinstanceInstance of object
Code
27function NightIllumination:new(id)
28 local self = {}
29 setmetatable(self, NightIllumination_mt)
30
31 g_currentMission.environment:addWeatherChangeListener(self)
32
33 self.id = id
34 self.windowsId = 0
35 self.lightsId = 0
36
37 if getNumOfChildren(id) > 0 then
38 self.windowsId = getChildAt(id, 0)
39 end
40 if getNumOfChildren(id) > 1 then
41 self.lightsId = getChildAt(id, 1)
42 end
43
44 self.lightIntensity = Utils.getNoNil(getUserAttribute(self.id, "lightIntensity"), 1.0)
45
46 -- set windows to dark (using dashboardLightsShader)
47 if self.windowsId ~= 0 then
48 setShaderParameter(self.windowsId, "lightControl", 0, 0, 0, 0, false)
49 end
50
51 -- make lights invisible
52 if self.lightsId ~= 0 then
53 setVisibility(self.lightsId, false)
54 end
55
56 return self
57end

delete

Description
Remove Object from WeatherChangeListeners
Definition
delete()
Return Values
floatlastMotorRpmlast motor rpm
Code
61function NightIllumination:delete()
62 if g_currentMission.environment ~= nil then
63 g_currentMission.environment:removeWeatherChangeListener(self)
64 end
65end

weatherChanged

Description
Change illumination of night objects
Definition
weatherChanged()
Return Values
floatlastMotorRpmlast motor rpm
Code
69function NightIllumination:weatherChanged()
70 if g_currentMission ~= nil and g_currentMission.environment ~= nil then
71 local isLightNeeded = not (g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining())
72
73 if self.windowsId ~= 0 then
74 if isLightNeeded then
75 setShaderParameter(self.windowsId, "lightControl", self.lightIntensity, 0, 0, 0, false)
76 else
77 setShaderParameter(self.windowsId, "lightControl", 0, 0, 0, 0, false)
78 end
79 end
80
81 if self.lightsId ~= 0 then
82 setVisibility(self.lightsId, isLightNeeded)
83 end
84 end
85end

Nightlight2

Description
Class for nightlight objects which are blending in on night

onCreate

Description
Creating nightlight object
Definition
onCreate(integer id)
Arguments
integeridID of the node
Return Values
floatappliedTorquetorque [kN]
Code
15function Nightlight2:onCreate(id)
16 g_currentMission:addNonUpdateable(Nightlight2:new(id))
17end

new

Description
Creating nightlight object
Definition
new(integer name)
Arguments
integernameID of the node
Return Values
floatexternalTorqueexternal torque [kN]
tableinstanceInstance of object
Code
23function Nightlight2:new(id)
24 local self = {}
25 setmetatable(self, Nightlight2_mt)
26
27 self.id = id
28 self.switchCollision = Utils.getNoNil(getUserAttribute(id, "switchCollision"), false)
29
30 if self.switchCollision then
31 self.collisionMask = getCollisionMask(id)
32 end
33
34 self:setVisibility(false)
35
36 g_currentMission.environment:addWeatherChangeListener(self)
37
38 return self
39end

delete

Description
Remove Object from WeatherChangeListeners
Definition
delete()
Return Values
floattorqueexternal torque [kN]
Code
43function Nightlight2:delete()
44 if g_currentMission.environment ~= nil then
45 g_currentMission.environment:removeWeatherChangeListener(self)
46 end
47end

weatherChanged

Description
Change visibility of night object
Definition
weatherChanged()
Return Values
floatequalizedMotorRpmequalized motor rpm
Code
59function Nightlight2:weatherChanged()
60 if g_currentMission ~= nil and g_currentMission.environment ~= nil then
61 self:setVisibility(not (g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining()))
62 end
63end

NightlightFlicker

Description
NightlightFlickers are flickering lights that are only active at night or during bad weather

onCreate

Description
Creating nightlightflicker
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
floatptoMotorRpmRatiopto motor rpm ratio
Code
15function NightlightFlicker:onCreate(id)
16 g_currentMission:addUpdateable(NightlightFlicker:new(id));
17end;

new

Description
Creating nightlightflicker
Definition
new(integer name)
Arguments
integernamenode id
Return Values
floatnonClampedMotorRpmnon clamped motor rpm
tableinstanceInstance of object
Code
23function NightlightFlicker:new(id)
24 local self = {};
25 setmetatable(self, NightlightFlicker_mt);
26
27 self.id = id;
28 self.isVisible = false;
29 self.isFlickerActive = false;
30 self.nextFlicker = 0;
31 self.flickerDuration = 100;
32 setVisibility(self.id, self.isVisible);
33
34 g_currentMission.environment:addWeatherChangeListener(self);
35
36 return self;
37end;

update

Description
Update flickering
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Return Values
floatnonClampedMotorRpmnon clamped motor rpm
Code
45function NightlightFlicker:update(dt)
46 if self.isVisible then
47
48 self.nextFlicker = self.nextFlicker - dt;
49 if self.nextFlicker <= 0 then
50 self.isFlickerActive = true;
51 setVisibility(self.id, false);
52 self.nextFlicker = math.floor(math.random() * 1500 + self.flickerDuration + 10); -- set next flicker at least 10ms after this one
53 end;
54
55 if self.isFlickerActive then
56 self.flickerDuration = self.flickerDuration - dt;
57 if self.flickerDuration <= 0 then
58 self.isFlickerActive = false;
59 self.flickerDuration = math.floor(math.random() * 200);
60 setVisibility(self.id, true);
61 end;
62 end;
63
64 end;
65end;

weatherChanged

Description
Change visibility of night object
Definition
weatherChanged()
Return Values
floatclutchRpmclutch rpm
Code
69function NightlightFlicker:weatherChanged()
70 if g_currentMission ~= nil and g_currentMission.environment ~= nil then
71 self.isVisible = not (g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining());
72 setVisibility(self.id, self.isVisible);
73 end;
74end;

PhysicsObject

Description
Class for physics objects

new

Description
Creating physics object
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustomMt
Return Values
tabletorqueCurvetorque curve
tableinstanceInstance of object
Code
17function PhysicsObject:new(isServer, isClient, customMt)
18
19 local self = Object:new(isServer, isClient, customMt or PhysicsObject_mt)
20
21 self.nodeId = 0
22 self.networkTimeInterpolator = InterpolationTime:new(1.2)
23 self.forcedClipDistance = 60
24
25 self.physicsObjectDirtyFlag = self:getNextDirtyFlag()
26
27 return self
28end

delete

Description
Deleting physics object
Definition
delete()
Return Values
floattorquetorque
Code
32function PhysicsObject:delete()
33 removeWakeUpReport(self.nodeId)
34 g_currentMission:removeNodeObject(self.nodeId)
35 delete(self.nodeId)
36 self.nodeId = 0
37 PhysicsObject:superClass().delete(self)
38end

getAllowsAutoDelete

Description
Get allows auto delete
Definition
getAllowsAutoDelete()
Return Values
floattorquetorque
booleanallowsAutoDeleteallows auto delete
Code
43function PhysicsObject:getAllowsAutoDelete()
44 return true
45end

loadOnCreate

Description
Load on create
Definition
loadOnCreate(integer nodeId)
Arguments
integernodeIdnode id
Return Values
floatmaxForwardSpeedmaximum forward speed
Code
50function PhysicsObject:loadOnCreate(nodeId)
51 self:setNodeId(nodeId)
52 if not self.isServer then
53 self:onGhostRemove()
54 end
55end

setNodeId

Description
Set node id
Definition
setNodeId(integer nodeId)
Arguments
integernodeIdnode Id
Return Values
floatmaxBackwardSpeedmaximum backward speed
Code
60function PhysicsObject:setNodeId(nodeId)
61 self.nodeId = nodeId
62 setRigidBodyType(self.nodeId, self:getDefaultRigidBodyType())
63 addToPhysics(self.nodeId)
64
65 local x, y, z = getTranslation(self.nodeId)
66 local xRot, yRot, zRot = getRotation(self.nodeId)
67 self.sendPosX, self.sendPosY, self.sendPosZ = x, y, z
68 self.sendRotX, self.sendRotY, self.sendRotZ = xRot, yRot, zRot
69
70 if not self.isServer then
71 local quatX, quatY, quatZ, quatW = mathEulerToQuaternion(xRot, yRot, zRot)
72 self.positionInterpolator = InterpolatorPosition:new(x, y, z)
73 self.quaternionInterpolator = InterpolatorQuaternion:new(quatX, quatY, quatZ, quatW)
74 end
75
76 self:addChildsToNodeObject(self.nodeId)
77end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
floatphysicalMaxForwardSpeedphysical maximum forward speed
Code
83function PhysicsObject:readStream(streamId, connection)
84 assert(self.nodeId ~= 0)
85 if connection:getIsServer() then
86 local paramsXZ = g_currentMission.vehicleXZPosCompressionParams
87 local paramsY = g_currentMission.vehicleYPosCompressionParams
88 local x = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
89 local y = NetworkUtil.readCompressedWorldPosition(streamId, paramsY)
90 local z = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
91 local xRot = NetworkUtil.readCompressedAngle(streamId)
92 local yRot = NetworkUtil.readCompressedAngle(streamId)
93 local zRot = NetworkUtil.readCompressedAngle(streamId)
94
95 local quatX, quatY, quatZ, quatW = mathEulerToQuaternion(xRot,yRot,zRot)
96 self:setWorldPositionQuaternion(x, y, z, quatX, quatY, quatZ, quatW, true)
97
98 self.networkTimeInterpolator:reset()
99 end
100end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Return Values
floatphysicalMaxBackwardSpeedphysical maximum backward speed
Code
106function PhysicsObject:writeStream(streamId, connection)
107 if not connection:getIsServer() then
108 local x,y,z = getTranslation(self.nodeId)
109 local xRot,yRot,zRot = getRotation(self.nodeId)
110 local paramsXZ = g_currentMission.vehicleXZPosCompressionParams
111 local paramsY = g_currentMission.vehicleYPosCompressionParams
112 NetworkUtil.writeCompressedWorldPosition(streamId, x, paramsXZ)
113 NetworkUtil.writeCompressedWorldPosition(streamId, y, paramsY)
114 NetworkUtil.writeCompressedWorldPosition(streamId, z, paramsXZ)
115 NetworkUtil.writeCompressedAngle(streamId, xRot)
116 NetworkUtil.writeCompressedAngle(streamId, yRot)
117 NetworkUtil.writeCompressedAngle(streamId, zRot)
118 end
119end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Return Values
floatphysicalMaxSpeedphysical maximum speed
Code
126function PhysicsObject:readUpdateStream(streamId, timestamp, connection)
127 if connection:getIsServer() then
128 if streamReadBool(streamId) then
129 local paramsXZ = g_currentMission.vehicleXZPosCompressionParams
130 local paramsY = g_currentMission.vehicleYPosCompressionParams
131 local x = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
132 local y = NetworkUtil.readCompressedWorldPosition(streamId, paramsY)
133 local z = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
134 local xRot = NetworkUtil.readCompressedAngle(streamId)
135 local yRot = NetworkUtil.readCompressedAngle(streamId)
136 local zRot = NetworkUtil.readCompressedAngle(streamId)
137
138 local quatX, quatY, quatZ, quatW = mathEulerToQuaternion(xRot,yRot,zRot)
139 self.positionInterpolator:setTargetPosition(x, y, z)
140 self.quaternionInterpolator:setTargetQuaternion(quatX, quatY, quatZ, quatW)
141 self.networkTimeInterpolator:startNewPhaseNetwork()
142 end
143 end
144end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Return Values
floatbestGearRatiobest gear ratio
Code
151function PhysicsObject:writeUpdateStream(streamId, connection, dirtyMask)
152 if not connection:getIsServer() then
153 if streamWriteBool(streamId, bitAND(dirtyMask, self.physicsObjectDirtyFlag) ~= 0) then
154 local paramsXZ = g_currentMission.vehicleXZPosCompressionParams
155 local paramsY = g_currentMission.vehicleYPosCompressionParams
156 NetworkUtil.writeCompressedWorldPosition(streamId, self.sendPosX, paramsXZ)
157 NetworkUtil.writeCompressedWorldPosition(streamId, self.sendPosY, paramsY)
158 NetworkUtil.writeCompressedWorldPosition(streamId, self.sendPosZ, paramsXZ)
159
160 NetworkUtil.writeCompressedAngle(streamId, self.sendRotX)
161 NetworkUtil.writeCompressedAngle(streamId, self.sendRotY)
162 NetworkUtil.writeCompressedAngle(streamId, self.sendRotZ)
163 end
164 end
165end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Return Values
floatbestGearbest gear
floatgearRatiogear ratio
Code
170function PhysicsObject:update(dt)
171 if not self.isServer then
172 self.networkTimeInterpolator:update(dt)
173 local interpolationAlpha = self.networkTimeInterpolator:getAlpha()
174 local posX, posY, posZ = self.positionInterpolator:getInterpolatedValues(interpolationAlpha)
175 local quatX, quatY, quatZ, quatW = self.quaternionInterpolator:getInterpolatedValues(interpolationAlpha)
176 self:setWorldPositionQuaternion(posX, posY, posZ, quatX, quatY, quatZ, quatW, false)
177
178 if self.networkTimeInterpolator:isInterpolating() then
179 self:raiseActive()
180 end
181 else
182 if not getIsSleeping(self.nodeId) then
183 self:raiseActive()
184 end
185 end
186end

updateMove

Description
Update move
Definition
updateMove()
Return Values
booleanhasMovedhas moved
Code
192function PhysicsObject:updateMove()
193 local x, y, z = getTranslation(self.nodeId)
194 local xRot, yRot, zRot = getRotation(self.nodeId)
195 local hasMoved = math.abs(self.sendPosX-x)>0.005 or math.abs(self.sendPosY-y)>0.005 or math.abs(self.sendPosZ-z)>0.005 or
196 math.abs(self.sendRotX-xRot)>0.02 or math.abs(self.sendRotY-yRot)>0.02 or math.abs(self.sendRotZ-zRot)>0.02
197
198 if hasMoved then
199 self:raiseDirtyFlags(self.physicsObjectDirtyFlag)
200 self.sendPosX, self.sendPosY, self.sendPosZ = x, y ,z
201 self.sendRotX, self.sendRotY, self.sendRotZ = xRot, yRot, zRot
202 end
203
204 return hasMoved
205end

updateTick

Description
updateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Return Values
floatadjustedAcceleratorPedalthe adjusted accelerator pedal for the current gear situation (e.g. 0 while switching gears)
Code
210function PhysicsObject:updateTick(dt)
211 if self.isServer then
212 self:updateMove()
213 end
214end

testScope

Description
Test scope
Definition
testScope(float x, float y, float z, float coeff)
Arguments
floatxx position
floatyy position
floatzz position
floatcoeffcoeff
Return Values
floatminGearRatiominimum gear ratio
floatmaxGearRatiomaximum gear ratio
booleaninScopein scope
Code
223function PhysicsObject:testScope(x,y,z, coeff)
224 local x1, y1, z1 = getWorldTranslation(self.nodeId)
225 local dist = (x1-x)*(x1-x) + (y1-y)*(y1-y) + (z1-z)*(z1-z)
226 local clipDist = math.min(getClipDistance(self.nodeId)*coeff, self.forcedClipDistance)
227 if dist < clipDist*clipDist then
228 return true
229 else
230 return false
231 end
232end

getUpdatePriority

Description
Get update priority
Definition
getUpdatePriority(float skipCount, float x, float y, float z, float coeff, table connection)
Arguments
floatskipCountskip count
floatxx position
floatyy position
floatzz position
floatcoeffcoeff
tableconnectionconnection
Return Values
floatprioritypriority
Code
243function PhysicsObject:getUpdatePriority(skipCount, x, y, z, coeff, connection)
244 local x1, y1, z1 = getWorldTranslation(self.nodeId)
245 local dist = math.sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y) + (z1-z)*(z1-z))
246 local clipDist = math.min(getClipDistance(self.nodeId)*coeff, self.forcedClipDistance)
247 return (1-dist/clipDist)* 0.8 + 0.5*skipCount * 0.2
248end

onGhostRemove

Description
On ghost remove
Definition
onGhostRemove()
Return Values
integermaxRpmcurrent max rpm
Code
252function PhysicsObject:onGhostRemove()
253 setVisibility(self.nodeId, false)
254 removeFromPhysics(self.nodeId)
255end

onGhostAdd

Description
On ghost add
Definition
onGhostAdd()
Return Values
booleancontinuecontinue
Code
259function PhysicsObject:onGhostAdd()
260 setVisibility(self.nodeId, true)
261 addToPhysics(self.nodeId)
262end

setWorldPositionQuaternion

Description
Set pose
Definition
setWorldPositionQuaternion(float x, float y, float z, float xRot, float yRot, float zRot, float w_rot)
Arguments
floatxx position
floatyz position
floatzz position
floatxRotx rotation
floatyRoty rotation
floatzRotz rotation
floatw_rotw rotation
Return Values
tableinstanceinstance of object
Code
273function PhysicsObject:setWorldPositionQuaternion(x, y, z, quatX, quatY, quatZ, quatW, changeInterp)
274 if not self.isServer then
275 if changeInterp then
276 self.positionInterpolator:setPosition(x, y, z)
277 self.quaternionInterpolator:setQuaternion(quatX, quatY, quatZ, quatW)
278 end
279 end
280
281 setTranslation(self.nodeId, x, y, z)
282 setQuaternion(self.nodeId, quatX, quatY, quatZ, quatW)
283end

getDefaultRigidBodyType

Description
Get default rigid body type
Definition
getDefaultRigidBodyType()
Return Values
booleantrueif loading was successful else false
stringrigidBodyTyperigid body type
Code
288function PhysicsObject:getDefaultRigidBodyType()
289 if self.isServer then
290 return "Dynamic"
291 else
292 return "Kinematic"
293 end
294end

addChildsToNodeObject

Description
Add childs to node object
Definition
addChildsToNodeObject(integer nodeId)
Arguments
integernodeIdid of node
Return Values
booleansuccesstrue if added else false
Code
299function PhysicsObject:addChildsToNodeObject(nodeId)
300 for i=0,getNumOfChildren(nodeId)-1 do
301 self:addChildsToNodeObject(getChildAt(nodeId, i))
302 end
303 local rigidBodyType = getRigidBodyType(nodeId)
304 if rigidBodyType ~= "NoRigidBody" then
305 g_currentMission:addNodeObject(nodeId, self)
306
307 if self.isServer then
308 addWakeUpReport(nodeId, "onPhysicObjectWakeUpCallback", self)
309 end
310 end
311end

Rotator

Description
Rotators rotate around their y axis

onCreate

Description
Creating rotator
Definition
onCreate(integer id)
Arguments
integeridnode id
Return Values
integeriindex of tire type
Code
15function Rotator:onCreate(id)
16 g_currentMission:addUpdateable(Rotator:new(id))
17end

new

Description
Creating rotator
Definition
new(integer name)
Arguments
integernamenode id
Return Values
floatdiffRotSpeedrot speed [rad/sec]
tableinstanceInstance of object
Code
23function Rotator:new(name)
24 local self = {}
25 setmetatable(self, Rotator_mt)
26
27 self.axisTable = {0, 0, 0}
28 self.me = name
29 self.speed = Utils.getNoNil(getUserAttribute(name, "speed"), 0.0012)
30 local axis = Utils.getNoNil(getUserAttribute(name, "axis"), 3)
31 self.axisTable[axis] = 1
32
33 return self
34end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Return Values
floattireFrictiontire friction
Code
42function Rotator:update(dt)
43 rotate(self.me, self.axisTable[1] * self.speed * dt, self.axisTable[2] * self.speed * dt, self.axisTable[3] * self.speed * dt)
44end

SellingStation

Description

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
integergroundTypeground type
booleansuccesssuccess
Code
227function SellingStation:loadFromXMLFile(xmlFile, key)
228 local i=0
229 while true do
230 local statsKey = string.format(key..".stats(%d)", i)
231 if not hasXMLProperty(xmlFile, statsKey) then
232 break
233 end
234 local fillTypeStr = getXMLString(xmlFile, statsKey.."#fillType")
235 local fillType = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr)
236 if fillType ~= nil and self.acceptedFillTypes[fillType] then
237 self.totalReceived[fillType] = Utils.getNoNil(getXMLFloat(xmlFile, statsKey.."#received"), 0)
238 self.totalPaid[fillType] = Utils.getNoNil(getXMLFloat(xmlFile, statsKey.."#paid"), 0)
239 self.pricingDynamics[fillType]:loadFromXMLFile(xmlFile, statsKey)
240 end
241 i = i + 1
242 end
243
244 return true
245end

initPricingDynamics

Description
Initialize pricing dynamics
Definition
initPricingDynamics()
Return Values
tableinstanceinstance of object

SimParticleSystem

Description
This pre-simulates a particle system so it doesn't start at zero when the game begins

onCreate

Description
Creating SimParticleSystem
Definition
onCreate(integer id)
Arguments
integeridnode id
Code
15function SimParticleSystem:onCreate(id)
16 g_currentMission:addNonUpdateable(SimParticleSystem:new(id));
17end;

new

Description
Creating SimParticleSystem
Definition
new(integer name)
Arguments
integernamenode id
Return Values
tableinstanceInstance of object
Code
23function SimParticleSystem:new(name)
24 local self = {};
25 setmetatable(self, SimParticleSystem_mt);
26 self.id = name;
27
28 local particleSystem = nil;
29
30 if getHasClassId(self.id, ClassIds.SHAPE) then
31 local geometry = getGeometry(self.id);
32 if geometry ~= 0 then
33 if getHasClassId(geometry, ClassIds.PRECIPITATION) then
34 particleSystem = geometry;
35 end;
36 end;
37 end;
38
39 if particleSystem ~= nil then
40 local lifespan = getParticleSystemLifespan(particleSystem);
41 addParticleSystemSimulationTime(particleSystem, lifespan);
42 end;
43
44 return self;
45end;

Storage

Description

new

Description
Creating new instance of storage class
Definition
new(boolean isServer, boolean isClient)
Arguments
booleanisServeris server
booleanisClientis client
Return Values
tableselfnew instance of object
Code
23function Storage:new(isServer, isClient, customMt)
24 local self = Object:new(isServer, isClient, customMt or Storage_mt)
25
26 self.unloadingStations = {}
27 self.loadingStations = {}
28
29 self.rootNode = 0
30
31 return self
32end

load

Description
Load storage attributes from object
Definition
load(integer id)
Arguments
integeridid of object
Return Values
booleansuccesssuccess
Code
38function Storage:load(id, xmlFile, key)
39 self.rootNode = id
40
41 self.capacityPerFillType = getXMLFloat(xmlFile, key .. "#capacityPerFillType") or 100000
42 self.costsPerFillLevelAndDay = getXMLFloat(xmlFile, key .. "#costsPerFillLevelAndDay") or 0
43
44 self.fillTypes = {}
45 self.fillLevels = {}
46 self.sortedFillTypes = {}
47
48 local fillTypeCategories = getXMLString(xmlFile, key .. "#fillTypeCategories")
49 local fillTypeNames = getXMLString(xmlFile, key .. "#fillTypes")
50 local fillTypes
51
52 if fillTypeCategories ~= nil and fillTypeNames == nil then
53 fillTypes = g_fillTypeManager:getFillTypesByCategoryNames(fillTypeCategories, "Warning: '"..tostring(key).. "' has invalid fillTypeCategory '%s'.")
54 elseif fillTypeCategories == nil and fillTypeNames ~= nil then
55 fillTypes = g_fillTypeManager:getFillTypesByNames(fillTypeNames, "Warning: '"..tostring(key).. "' has invalid fillType '%s'.")
56 else
57 print("Warning: '"..tostring(key).. "' a 'Storage' entry needs either the 'fillTypeCategories' or 'fillTypes' attribute.")
58 return false
59 end
60
61 for _,fillType in pairs(fillTypes) do
62 self.fillTypes[fillType] = true
63 end
64
65 for fillType,_ in pairs(self.fillTypes) do
66 table.insert(self.sortedFillTypes, fillType)
67 self.fillLevels[fillType] = 0
68 end
69 table.sort(self.sortedFillTypes)
70
71 self.storageDirtyFlag = self:getNextDirtyFlag()
72
73 g_messageCenter:subscribe(MessageType.FARM_DELETED, self.farmDestroyed, self)
74
75 return true
76end

delete

Description
Deleting storage
Definition
delete()
Code
80function Storage:delete()
81 if self.rootNode ~= 0 and entityExists(self.rootNode) then
82 delete(self.rootNode)
83 end
84
85 g_currentMission.environment:removeHourChangeListener(self)
86 g_messageCenter:unsubscribeAll(self)
87
88 Storage:superClass().delete(self)
89end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
95function Storage:readStream(streamId, connection)
96 Storage:superClass().readStream(self, streamId, connection)
97
98 for _, fillType in ipairs(self.sortedFillTypes) do
99 local fillLevel = 0
100 if streamReadBool(streamId) then
101 fillLevel = streamReadFloat32(streamId)
102 end
103 self:setFillLevel(fillLevel, fillType)
104 end
105end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
111function Storage:writeStream(streamId, connection)
112 Storage:superClass().writeStream(self, streamId, connection)
113
114 for _, fillType in ipairs(self.sortedFillTypes) do
115 local fillLevel = self.fillLevels[fillType]
116 if streamWriteBool(streamId, fillLevel > 0) then
117 streamWriteFloat32(streamId, fillLevel)
118 end
119 end
120end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
127function Storage:readUpdateStream(streamId, timestamp, connection)
128 Storage:superClass().readUpdateStream(self, streamId, timestamp, connection)
129 if connection:getIsServer() then
130 if streamReadBool(streamId) then
131 for _, fillType in ipairs(self.sortedFillTypes) do
132 local fillLevel = 0
133 if streamReadBool(streamId) then
134 fillLevel = streamReadFloat32(streamId)
135 end
136 self:setFillLevel(fillLevel, fillType)
137 end
138 end
139 end
140end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
147function Storage:writeUpdateStream(streamId, connection, dirtyMask)
148 Storage:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
149 if not connection:getIsServer() then
150 if streamWriteBool(streamId, bitAND(dirtyMask, self.storageDirtyFlag) ~= 0) then
151 for _, fillType in ipairs(self.sortedFillTypes) do
152 local fillLevel = self.fillLevels[fillType]
153 if streamWriteBool(streamId, fillLevel > 0) then
154 streamWriteFloat32(streamId, fillLevel)
155 end
156 end
157 end
158 end
159end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
166function Storage:loadFromXMLFile(xmlFile, key)
167 self:setOwnerFarmId(Utils.getNoNil(getXMLInt(xmlFile, key .. "#farmId"), AccessHandler.EVERYONE), true)
168
169 local i = 0
170 while true do
171 local siloKey = string.format(key .. ".node(%d)", i)
172 if not hasXMLProperty(xmlFile, siloKey) then
173 break
174 end
175
176 local fillTypeStr = getXMLString(xmlFile, siloKey.."#fillType")
177 local fillLevel = math.max(Utils.getNoNil(getXMLFloat(xmlFile, siloKey.."#fillLevel"), 0), 0)
178 local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr)
179
180 if fillTypeIndex ~= nil then
181 if self.fillLevels[fillTypeIndex] ~= nil then
182 self:setFillLevel(fillLevel, fillTypeIndex, nil)
183 else
184 print("Warning: Filltype '"..fillTypeStr.."' not supported by Storage "..getName(self.rootNode))
185 end
186 else
187 print("Error: Invalid filltype '"..fillTypeStr.."'")
188 end
189
190 i = i + 1
191 end
192
193 return true
194end

getIsFillTypeSupported

Description
Returns if storage allows fill type
Definition
getIsFillTypeSupported(integer fillType)
Arguments
integerfillTypefill type
Return Values
booleanallowallow fill type
Code
224function Storage:getIsFillTypeSupported(fillType)
225 return self.fillTypes[fillType] == true
226end

getFillLevel

Description
Returns fill level
Definition
getFillLevel(integer fillType)
Arguments
integerfillTypefill type
Return Values
floatfillLevelfill level
Code
232function Storage:getFillLevel(fillType)
233 return self.fillLevels[fillType] or 0
234end

setFillLevel

Description
Set fill level of storage
Definition
setFillLevel(float fillLevel, integer fillType)
Arguments
floatfillLevelnew fill level
integerfillTypefill type
Code
244function Storage:setFillLevel(fillLevel, fillType)
245 fillLevel = MathUtil.clamp(fillLevel, 0, self.capacityPerFillType)
246 if self.fillLevels[fillType] ~= nil and fillLevel ~= self.fillLevels[fillType] then
247 self.fillLevels[fillType] = fillLevel
248
249 if self.isServer then
250 self:raiseDirtyFlags(self.storageDirtyFlag)
251 end
252 end
253end

getFreeCapacity

Description
Returns free capacity
Definition
getFreeCapacity(integer fillType)
Arguments
integerfillTypefill type
Return Values
floatfreeCapacityfree capacity
Code
259function Storage:getFreeCapacity(fillType)
260 if self.fillLevels[fillType] ~= nil then
261 return math.max(self.capacityPerFillType - self.fillLevels[fillType], 0)
262 end
263 return 0
264end

hourChanged

Description
Called on hour change
Definition
hourChanged()
Code
272function Storage:hourChanged()
273 if self.isServer then
274 local difficultyMultiplier = g_currentMission.missionInfo.buyPriceMultiplier
275 local fillLevelFactor = difficultyMultiplier * self.costsPerFillLevelAndDay / 24
276
277 local costs = 0
278 for _, fillLevel in pairs(self.fillLevels) do
279 costs = costs + fillLevel * fillLevelFactor
280 end
281
282 g_currentMission:addMoney(-costs, self:getOwnerFarmId(), "propertyMaintenance")
283 g_currentMission:addMoneyChange(-costs, self:getOwnerFarmId(), EconomyManager.MONEY_TYPE_PROPERTY_MAINTENANCE)
284 end
285end

SunAdmirer

Description
Class for objects which are visible when the sun is out

onCreate

Description
Creating sun admirer object
Definition
onCreate(integer id)
Arguments
integeridID of the node
Code
15function SunAdmirer:onCreate(id)
16 g_currentMission:addNonUpdateable(SunAdmirer:new(id))
17end

new

Description
Creating nightlight object
Definition
new(integer name)
Arguments
integernameID of the node
Return Values
tableinstanceInstance of object
Code
23function SunAdmirer:new(id)
24 local self = {}
25 setmetatable(self, SunAdmirer_mt)
26
27 self.id = id
28 self.switchCollision = Utils.getNoNil(getUserAttribute(id, "switchCollision"), false)
29
30 if self.switchCollision then
31 self.collisionMask = getCollisionMask(id)
32 end
33
34 self:setVisibility(true)
35
36 g_currentMission.environment:addWeatherChangeListener(self)
37
38 return self
39end

delete

Description
Remove Object from WeatherChangeListeners
Definition
delete()
Code
43function SunAdmirer:delete()
44 if g_currentMission.environment ~= nil then
45 g_currentMission.environment:removeWeatherChangeListener(self)
46 end
47end

weatherChanged

Description
Change visibility of sun object
Definition
weatherChanged()
Code
59function SunAdmirer:weatherChanged()
60 if g_currentMission ~= nil and g_currentMission.environment ~= nil then
61 self:setVisibility(g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining())
62 end
63end

TourIcons

Description
Tour icons are part of the (optional) guided tour at the career game's start

onCreate

Description
Creating tour icons
Definition
onCreate(integer id)
Arguments
integeridnode id
Code
15function TourIcons:onCreate(id)
16 local tourIcons = TourIcons:new(id)
17 table.insert(g_currentMission.updateables, tourIcons)
18 g_currentMission.tourIconsBase = tourIcons
19end

new

Description
Creating tour icons
Definition
new(integer id)
Arguments
integeridnode id
Return Values
tableinstanceInstance of object
Code
25function TourIcons:new(name)
26 local self = {}
27 setmetatable(self, TourIcons_mt)
28
29 self.me = name
30 local num = getNumOfChildren(self.me)
31
32 self.tourIcons = {}
33 for i = 0, num - 1 do
34 local tourIconTriggerId = getChildAt(self.me, i)
35 local tourIconId = getChildAt(tourIconTriggerId, 0)
36 addTrigger(tourIconTriggerId, "triggerCallback", self)
37 setVisibility(tourIconId, false)
38 local tourIcon = {tourIconTriggerId = tourIconTriggerId, tourIconId = tourIconId}
39 table.insert(self.tourIcons, tourIcon)
40 end
41
42 self.visible = false
43 self.mapHotspot = nil
44 self.currentTourIconNumber = 1
45 self.alpha = 0.25
46 self.alphaDirection = 1
47 self.startTourDialog = false
48 self.startTourDialogDelay = 0
49 self.permanentMessageDelay = 0
50 self.isPaused = false
51 self.pauseTime = 0
52 self.soldStuffAtGrainElevator = false
53
54 _, self.permanentTextSize = getNormalizedScreenValues(0, 28)
55
56 return self
57end

delete

Description
Deleting tour icons
Definition
delete()
Code
61function TourIcons:delete()
62 for _, tourIcon in pairs(self.tourIcons) do
63 removeTrigger(tourIcon.tourIconTriggerId)
64 end
65end

showTourDialog

Description
Show tour yes/no dialog
Definition
showTourDialog()
Code
69function TourIcons:showTourDialog()
70 g_gui:showYesNoDialog({text=g_i18n:getText("tour_text_start"), title="", callback=self.reactToDialog, target=self})
71end

reactToDialog

Description
React to tour dialog
Definition
reactToDialog(boolean yes)
Arguments
booleanyesanswer to dialog
Code
76function TourIcons:reactToDialog(yes)
77 if yes then
78 self.visible = true
79 self:activateNextIcon()
80 -- hide all non-tour question marks
81 if g_currentMission.helpIconsBase ~= nil then
82 g_currentMission.helpIconsBase:showHelpIcons(false, true)
83 end
84 else
85 self.visible = false
86 g_currentMission.hud:showInGameMessage("", g_i18n:getText("tour_text_abort"), -1)
87 end
88
89end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
94function TourIcons:update(dt)
95 if not g_currentMission.missionInfo.isValid and g_server ~= nil and self.initDone == nil and g_currentMission:getIsTourSupported() then
96 self.initDone = true
97
98 -- prepare fields
99 local field = g_fieldManager:getFieldByIndex(24)
100 local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(FruitType.WHEAT)
101 for i = 1,table.getn(field.maxFieldStatusPartitions) do
102 g_fieldManager:setFieldPartitionStatus(field, field.maxFieldStatusPartitions, i, fruitDesc.index, FieldManager.FIELDSTATE_GROWING, fruitDesc.maxHarvestingGrowthState, 3, true, g_currentMission.plowCounterMaxValue, 0, g_currentMission.limeCounterMaxValue)
103 end
104
105 local field = g_fieldManager:getFieldByIndex(25)
106 local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(FruitType.CANOLA)
107 for i = 1,table.getn(field.maxFieldStatusPartitions) do
108 g_fieldManager:setFieldPartitionStatus(field, field.maxFieldStatusPartitions, i, fruitDesc.index, FieldManager.FIELDSTATE_HARVESTED, 0, 0, false, g_currentMission.plowCounterMaxValue, 0, g_currentMission.limeCounterMaxValue)
109 end
110
111 local field = g_fieldManager:getFieldByIndex(26)
112 for i = 1,table.getn(field.maxFieldStatusPartitions) do
113 g_fieldManager:setFieldPartitionStatus(field, field.maxFieldStatusPartitions, i, nil, FieldManager.FIELDSTATE_CULTIVATED, 0, 0, false, g_currentMission.plowCounterMaxValue, 0, g_currentMission.limeCounterMaxValue)
114 end
115
116 local field = g_fieldManager:getFieldByIndex(19)
117 for i = 1,table.getn(field.maxFieldStatusPartitions) do
118 g_fieldManager:setFieldPartitionStatus(field, field.maxFieldStatusPartitions, i, nil, FieldManager.FIELDSTATE_CULTIVATED, 0, 0, false, g_currentMission.plowCounterMaxValue, 0, g_currentMission.limeCounterMaxValue)
119 end
120 end
121
122 if self.startTourDialog then
123 self.startTourDialogDelay = self.startTourDialogDelay - dt
124 local showDialog = true
125 if g_currentMission.cameraFlightManager ~= nil then
126 showDialog = g_currentMission.cameraFlightManager.careerStartFlightPlayed
127 end
128 if showDialog then
129 if self.startTourDialogDelay < 0 then
130 self.startTourDialog = false
131 self:showTourDialog()
132 end
133 end
134 end
135
136 if self.isPaused then
137 if self.pauseTime > 0 then
138 self.pauseTime = self.pauseTime - dt
139 else
140 self.pauseTime = 0
141 self.isPaused = false
142 self:activateNextIcon()
143 end
144 end
145
146 if self.visible and not self.isPaused then
147 -- show current permanent message on screen if no ingame message or any other GUI screen is displayed
148 if not g_currentMission.hud:isInGameMessageVisible() and not g_gui:getIsGuiVisible() then
149
150 if false then --g_i18n:hasText("tour_permanentText" .. self.currentTourIconNumber - 1) then
151
152 if self.permanentMessageDelay > 0 then
153 self.permanentMessageDelay = self.permanentMessageDelay - dt
154 self.alpha = 0.25
155 self.alphaDirection = 1
156 else
157
158 setTextColor(1, 1, 1, self.alpha)
159 setTextBold(true)
160 setTextAlignment(RenderText.ALIGN_CENTER)
161 setTextWrapWidth(0.35)
162 if GS_IS_CONSOLE_VERSION then
163 setTextWrapWidth(0.295)
164 end
165 renderText(0.5, 0.93, self.permanentTextSize, g_i18n:getText("tour_permanentText" .. self.currentTourIconNumber - 1))
166 setTextWrapWidth(0)
167 setTextAlignment(RenderText.ALIGN_LEFT)
168 setTextBold(false)
169 setTextColor(1, 1, 1, 1)
170
171 self.alpha = self.alpha + self.alphaDirection * (dt / 600)
172 if self.alpha > 1 or self.alpha < 0.25 then
173 self.alphaDirection = self.alphaDirection * -1
174 self.alpha = MathUtil.clamp(self.alpha, 0.25, 1)
175 end
176 end
177
178 end
179 end
180
181 -- handle special cases
182
183 --# harvesting
184
185 -- icon #3 activates as soon as the player enters the tour's combine harvester
186 if self.currentTourIconNumber <= 3 then
187 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourCombine"] then
188 self.currentTourIconNumber = 3
189 -- self:activateNextIcon()
190 self.pauseTime = 1000
191 self.isPaused = true
192 end
193 end
194
195 -- wait for player to attach the cutter
196 if self.currentTourIconNumber == 4 then
197 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourCombine"] then
198 if g_currentMission.tourVehicles["tourCombine"].spec_combine.numAttachedCutters > 0 then
199 -- self:activateNextIcon()
200 self.pauseTime = 1000
201 self.isPaused = true
202 end
203 end
204 end
205
206 -- wait for player to activate the cutter
207 if self.currentTourIconNumber == 5 then
208 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourCombine"] then
209 if g_currentMission.controlledVehicle:getIsTurnedOn() then
210 -- self:activateNextIcon()
211 self.pauseTime = 1000
212 self.isPaused = true
213 end
214 end
215 end
216
217 -- wait for player to activate the helper
218 if self.currentTourIconNumber == 7 then
219 if g_currentMission.tourVehicles["tourCombine"]:getIsTurnedOn() and g_currentMission.tourVehicles["tourCombine"]:getIsAIActive() then
220 -- self:activateNextIcon()
221 self.pauseTime = 1000
222 self.isPaused = true
223 end
224 end
225
226 --# cultivating
227
228 -- wait for player to enter tractor1 and attach cultivator
229 if self.currentTourIconNumber == 9 then
230 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourTractor1"] then
231 if g_currentMission.tourVehicles["tourCultivator"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor1"]
232 and g_currentMission.tourVehicles["tourWeight1"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor1"] then
233 -- self:activateNextIcon()
234 self.pauseTime = 1000
235 self.isPaused = true
236 end
237 end
238 end
239
240 if self.currentTourIconNumber == 11 then
241 -- self:activateNextIcon()
242 self.pauseTime = 1000
243 self.isPaused = true
244 end
245
246 --# sowing
247
248 -- wait for player to enter tractor2 and attach sowingMachine
249 if self.currentTourIconNumber == 13 then
250 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourTractor2"] then
251 if g_currentMission.tourVehicles["tourSowingMachine"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor2"]
252 and g_currentMission.tourVehicles["tourWeight2"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor2"] then
253 -- self:activateNextIcon()
254 self.pauseTime = 1000
255 self.isPaused = true
256 end
257 end
258 end
259
260
261 --# overloading / tipping
262
263 -- wait for player to enter tractor3 and attach trailer
264 if self.currentTourIconNumber == 16 then
265 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourTractor3"] then
266 if g_currentMission.tourVehicles["tourTrailer"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor3"] then
267 -- self:activateNextIcon()
268 self.pauseTime = 1000
269 self.isPaused = true
270 end
271 end
272 end
273
274 if self.currentTourIconNumber == 17 then
275 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourTractor3"] then
276 if g_currentMission.tourVehicles["tourTrailer"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor3"] then
277
278 local tractor = g_currentMission.tourVehicles["tourTractor3"]
279 local trailer = g_currentMission.tourVehicles["tourTrailer"]
280 local combine = g_currentMission.tourVehicles["tourCombine"]
281
282 local x,y,z = localToWorld(combine.components[1].node, 6,0,0)
283 self.mapHotspot:setWorldPosition(x, z)
284
285 local xv,yv,zv = getWorldTranslation(tractor.components[1].node)
286 local dist = MathUtil.vector3Length(x-xv, y-yv, z-zv)
287 if dist < 10 then
288 g_currentMission:setMapTargetHotspot(nil)
289 else
290 g_currentMission:setMapTargetHotspot(self.mapHotspot)
291 end
292
293 local fillUnitIndex = 1
294 local dischargeNode = combine:getCurrentDischargeNode()
295 if trailer:getFillUnitFillLevel(fillUnitIndex) > 0 and dischargeNode ~= nil and dischargeNode.dischargeObject == trailer then
296 -- self:activateNextIcon()
297 self.pauseTime = 1000
298 self.isPaused = true
299 end
300 end
301 else
302 -- If the harvester is full or stopped, and a player goes into the harvester to open the pipe, the trailer vehicle
303 -- is not controlled so above code does not trigger. This cascades and breaks the tour.
304 if g_currentMission.tourVehicles["tourTrailer"]:getFillUnitFillLevel(1) > 400 then
305 self.pauseTime = 1000
306 self.isPaused = true
307 end
308 end
309 end
310
311 if self.currentTourIconNumber == 19 then
312 -- self:activateNextIcon()
313 self.pauseTime = 3000
314 self.isPaused = true
315 end
316
317 if self.currentTourIconNumber == 20 then
318 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle == g_currentMission.tourVehicles["tourTractor3"] then
319 if g_currentMission.tourVehicles["tourTrailer"]:getRootVehicle() == g_currentMission.tourVehicles["tourTractor3"] then
320 local trailer = g_currentMission.tourVehicles["tourTrailer"]
321
322 local unloadingStation
323 for _, station in pairs(g_currentMission.unloadingStations) do
324 if station.owningPlaceable ~= nil and station.owningPlaceable.mapBoundId == "sellingStationRestaurant" then
325 unloadingStation = station
326 break
327 end
328 end
329
330 local dischargeNode = trailer:getCurrentDischargeNode()
331
332 if dischargeNode ~= nil and dischargeNode.currentDischargeObject ~= nil and dischargeNode.currentDischargeObject:getTarget() == unloadingStation then
333 -- self:activateNextIcon()
334 self.pauseTime = 3000
335 self.isPaused = true
336 end
337 end
338 end
339 end
340
341 --# shop
342 if self.currentTourIconNumber == 22 then
343 -- self:activateNextIcon()
344 self.pauseTime = 1000
345 self.isPaused = true
346 end
347
348 end
349end

makeIconVisible

Description
Make tour icon visable
Definition
makeIconVisible(integer tourIconId)
Arguments
integertourIconIdid of tour icon
Code
354function TourIcons:makeIconVisible(tourIconId)
355 -- make next icon visible
356 setVisibility(tourIconId, true)
357 local x, _, z = getWorldTranslation(tourIconId)
358
359 if self.mapHotspot == nil then
360 self.mapHotspot = MapHotspot:new("guide", MapHotspot.CATEGORY_TOUR)
361 self.mapHotspot:setImage(nil, getNormalizedUVs(MapHotspot.UV.HIGHLIGHT_MARKER), {0.2705, 0.6514, 0.0802, 1})
362 self.mapHotspot:setPersistent(true)
363 self.mapHotspot:setRenderLast(true)
364 self.mapHotspot:setBlinking(true)
365
366 g_currentMission:addMapHotspot(self.mapHotspot)
367 end
368
369 self.mapHotspot:setWorldPosition(x, z)
370
371
372 -- Find 'hidden' icon used internally only
373 local x,y,z = getWorldTranslation(tourIconId)
374 local h = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,y,z)
375 if y > h then
376 g_currentMission:setMapTargetHotspot(self.mapHotspot)
377 self.mapHotspot.enabled = true
378 else
379 g_currentMission:setMapTargetHotspot(nil)
380 self.mapHotspot.enabled = false
381 end
382
383 g_currentMission.hud.ingameMap:toggleSize(IngameMap.STATE_MINIMAP, true)
384end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
393function TourIcons:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
394 if onEnter then
395 if self.tourIcons[self.currentTourIconNumber] ~= nil then
396 if self.tourIcons[self.currentTourIconNumber].tourIconTriggerId == triggerId and getVisibility(self.tourIcons[self.currentTourIconNumber].tourIconId) then
397 self:activateNextIcon()
398 end
399 end
400 end
401end

activateNextIcon

Description
Activate next icon
Definition
activateNextIcon()
Code
405function TourIcons:activateNextIcon()
406
407 -- make all previous icons invisible (also handles cases where player managed to skip icons)
408 for i = 1, self.currentTourIconNumber do
409 local tourIcon = self.tourIcons[i]
410 if getVisibility(tourIcon.tourIconId) then
411 setVisibility(tourIcon.tourIconId, false)
412 setCollisionMask(tourIcon.tourIconTriggerId, 0)
413 end
414 end
415
416 if self.tourIcons[self.currentTourIconNumber + 1] ~= nil then
417 self:makeIconVisible(self.tourIcons[self.currentTourIconNumber + 1].tourIconId)
418 else
419 -- end of tour!
420 if self.mapHotspot ~= nil then
421 g_currentMission:removeMapHotspot(self.mapHotspot)
422 self.mapHotspot:delete()
423 self.mapHotspot = nil
424 end
425 -- re-display non-tour help icons
426 if g_gameSettings:getValue("showHelpIcons") then
427 if g_currentMission.helpIconsBase ~= nil then
428 g_currentMission.helpIconsBase:showHelpIcons(true, true)
429 end
430 end
431
432 self.visible = false
433 end
434
435 local title = g_i18n:getText("ui_tour")
436 local text = ""
437 local controls = {}
438
439 if self.currentTourIconNumber == 1 then
440
441 text = g_i18n:getText("tour_text_part01_lookAndWalk")
442 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.TOGGLE_MAP_SIZE, nil, g_i18n:getText("action_toggleMapView")))
443
444 local useGamepadButtons = g_inputBinding:getInputHelpMode() == GS_INPUT_HELP_MODE_GAMEPAD
445 if useGamepadButtons then
446 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.AXIS_MOVE_FORWARD_PLAYER, InputAction.AXIS_MOVE_SIDE_PLAYER, g_i18n:getText("action_movePlayer")))
447 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.AXIS_LOOK_UPDOWN_PLAYER, InputAction.AXIS_LOOK_LEFTRIGHT_PLAYER, g_i18n:getText("action_lookPlayer")))
448 else
449 -- special case on PC
450 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.AXIS_MOVE_FORWARD_PLAYER, InputAction.AXIS_MOVE_SIDE_PLAYER, g_i18n:getText("action_movePlayer")))
451
452 -- to show a mouse icon, instead of 'arrow keys' on keyboard
453 -- local lookAroundSymbol = g_inputDisplayManager.controllerSymbols["mouse_MOUSE_BUTTON_NONE"] -- TODO: fix direct access, too error prone
454 -- if lookAroundSymbol ~= nil then
455 -- table.insert(controls, {overlays = {lookAroundSymbol.overlay}, text = g_i18n:getText("action_lookPlayer")} )
456 -- end
457 end
458
459 elseif self.currentTourIconNumber == 2 then -- # harvesting
460
461 text = g_i18n:getText("tour_text_part01_enterCombine")
462 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ENTER, nil, g_i18n:getText("input_ENTER")))
463
464 elseif self.currentTourIconNumber == 3 then
465
466 text = g_i18n:getText("tour_text_part01_attachHeader")
467 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ATTACH, nil, g_i18n:getText("input_ATTACH")))
468
469 elseif self.currentTourIconNumber == 4 then
470
471 text = g_i18n:getText("tour_text_part01_turnOnCombine")
472 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.SWITCH_IMPLEMENT, nil, g_i18n:getText("action_switchImplement")))
473 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.IMPLEMENT_EXTRA2, nil, g_i18n:getText("action_unfold")))
474 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.IMPLEMENT_EXTRA, nil, g_i18n:getText("action_turnOn")))
475
476 elseif self.currentTourIconNumber == 5 then
477
478 text = g_i18n:getText("tour_text_part01_startHarvesting")
479 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.AXIS_ACCELERATE_VEHICLE, InputAction.AXIS_BRAKE_VEHICLE, g_i18n:getText("action_accelerate")))
480 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.AXIS_MOVE_SIDE_VEHICLE, nil, g_i18n:getText("action_steer")))
481
482 elseif self.currentTourIconNumber == 6 then
483
484 text = g_i18n:getText("tour_text_part01_startHelperHarvesting")
485 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.TOGGLE_AI, nil, g_i18n:getText("input_TOGGLE_AI")))
486
487 elseif self.currentTourIconNumber == 7 then
488
489 text = g_i18n:getText("tour_text_part01_finished")
490 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ENTER, nil, g_i18n:getText("action_exitVehicle")))
491
492 elseif self.currentTourIconNumber == 8 then -- # cultivating
493
494 text = g_i18n:getText("tour_text_part02_enterTractor01")
495 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ENTER, nil, g_i18n:getText("input_ENTER")))
496 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ATTACH, nil, g_i18n:getText("input_ATTACH")))
497
498 elseif self.currentTourIconNumber == 9 then
499
500 text = g_i18n:getText("tour_text_part02_startCultivating")
501 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.LOWER_IMPLEMENT, nil, g_i18n:getText("input_LOWER_IMPLEMENT")))
502
503 elseif self.currentTourIconNumber == 10 then
504
505 text = g_i18n:getText("tour_text_part02_enoughCultivating")
506 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.TOGGLE_AI, nil, g_i18n:getText("input_TOGGLE_AI")))
507
508 elseif self.currentTourIconNumber == 11 then
509
510 text = g_i18n:getText("tour_text_part02_finished")
511 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.SWITCH_VEHICLE, nil, g_i18n:getText("input_SWITCH_VEHICLE")))
512 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.SWITCH_VEHICLE_BACK, nil, g_i18n:getText("input_SWITCH_VEHICLE_BACK")))
513
514 elseif self.currentTourIconNumber == 12 then -- # sowing
515
516 text = g_i18n:getText("tour_text_part03_enterTractor01")
517 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ENTER, nil, g_i18n:getText("input_ENTER")))
518 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ATTACH, nil, g_i18n:getText("input_ATTACH")))
519
520 elseif self.currentTourIconNumber == 13 then
521
522 text = g_i18n:getText("tour_text_part03_startSowing")
523 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.IMPLEMENT_EXTRA3, nil, g_i18n:getText("action_chooseSeed")))
524 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.LOWER_IMPLEMENT, nil, g_i18n:getText("input_LOWER_IMPLEMENT")))
525 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.IMPLEMENT_EXTRA, nil, g_i18n:getText("action_turnOn")))
526
527 elseif self.currentTourIconNumber == 14 then
528
529 text = g_i18n:getText("tour_text_part03_finished")
530 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.SWITCH_VEHICLE, nil, g_i18n:getText("input_SWITCH_VEHICLE")))
531 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.SWITCH_VEHICLE_BACK, nil, g_i18n:getText("input_SWITCH_VEHICLE_BACK")))
532
533 elseif self.currentTourIconNumber == 15 then -- # trailer / tipping and selling
534
535 text = g_i18n:getText("tour_text_part04_enterTractor01")
536 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ENTER, nil, g_i18n:getText("input_ENTER")))
537 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.ATTACH, nil, g_i18n:getText("input_ATTACH")))
538
539 elseif self.currentTourIconNumber == 16 then
540
541 text = g_i18n:getText("tour_text_part04_alignToHarvester")
542
543 elseif self.currentTourIconNumber == 17 then
544
545 text = g_i18n:getText("tour_text_part04_unloadWheat")
546
547 elseif self.currentTourIconNumber == 18 then
548
549 text = g_i18n:getText("tour_text_part04_pricesInfo")
550 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.MENU, nil, g_i18n:getText("input_MENU")))
551
552 elseif self.currentTourIconNumber == 19 then
553
554 text = g_i18n:getText("tour_text_part04_sellWheat")
555 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.TOGGLE_TIPSTATE, nil, g_i18n:getText("input_TOGGLE_TIPSTATE")))
556
557 elseif self.currentTourIconNumber == 20 then
558
559 text = g_i18n:getText("tour_text_part04_doneSelling")
560
561 elseif self.currentTourIconNumber == 21 then -- # shop
562
563 text = g_i18n:getText("tour_text_part05_visitShop")
564 table.insert(controls, g_inputDisplayManager:getControllerSymbolOverlays(InputAction.TOGGLE_STORE, nil, g_i18n:getText("input_TOGGLE_STORE")))
565
566 elseif self.currentTourIconNumber == 22 then
567
568 text = g_i18n:getText("tour_text_end")
569
570 end
571
572 if g_currentMission.controlledVehicle ~= nil and g_currentMission.controlledVehicle.setCruiseControlState ~= nil then
573 g_currentMission.controlledVehicle:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF)
574 end
575
576 g_currentMission.hud:showInGameMessage(title, text, -1, controls)
577
578
579 self.currentTourIconNumber = self.currentTourIconNumber + 1
580
581 self.permanentMessageDelay = 250
582end

UnloadingStation

Description

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
99function UnloadingStation:readStream(streamId, connection)
100 UnloadingStation:superClass().readStream(self, streamId, connection)
101 if connection:getIsServer() then
102 for _, unloadTrigger in ipairs(self.unloadTriggers) do
103 local unloadTriggerId = NetworkUtil.readNodeObjectId(streamId)
104 unloadTrigger:readStream(streamId, connection)
105 g_client:finishRegisterObject(unloadTrigger, unloadTriggerId)
106 end
107 end
108end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
114function UnloadingStation:writeStream(streamId, connection)
115 UnloadingStation:superClass().writeStream(self, streamId, connection)
116 if not connection:getIsServer() then
117 for _, unloadTrigger in ipairs(self.unloadTriggers) do
118 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(unloadTrigger))
119 unloadTrigger:writeStream(streamId, connection)
120 g_server:registerObjectInStream(connection, unloadTrigger)
121 end
122 end
123end

VehicleSellingPoint

Description
Class for vehicle selling point

new

Description
Creating vehicle selling point
Definition
new(integer id)
Arguments
integeridnode id
Return Values
tableinstanceInstance of object
Code
16function VehicleSellingPoint:new(id)
17 local self = {}
18 setmetatable(self, VehicleSellingPoint_mt)
19
20 self.id = id
21
22 self.vehicleInRange = {}
23 self.currentVehicle = nil
24 self.currentVehicleId = 0
25
26 self.activateText = g_i18n:getText("action_configSellSpecificVehicle")
27
28 self.isEnabled = true
29 self.objectActivated = false
30
31 return self
32end

delete

Description
Deleting vehicle selling point
Definition
delete()
Code
50function VehicleSellingPoint:delete()
51 g_messageCenter:unsubscribeAll(self)
52
53 if self.playerTrigger ~= nil then
54 removeTrigger(self.playerTrigger)
55 self.playerTrigger = nil
56 end
57 if self.sellTriggerNode ~= nil then
58 removeTrigger(self.sellTriggerNode)
59 self.sellTriggerNode = nil
60 end
61
62 self.sellIcon = nil
63end

getIsActivatable

Description
Get is activateable
Definition
getIsActivatable()
Return Values
booleanisActivateableis activateable
Code
68function VehicleSellingPoint:getIsActivatable()
69 return self.isEnabled and g_currentMission.controlPlayer and (self:getOwnerFarmId() == 0 or g_currentMission:getFarmId() == self:getOwnerFarmId())
70end

onActivateObject

Description
On activate object
Definition
onActivateObject()
Code
78function VehicleSellingPoint:onActivateObject()
79 self:determineCurrentVehicle()
80 g_gui:showDirectSellDialog({vehicle=self.currentVehicle, owner=self, ownWorkshop=self.ownWorkshop})
81end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
86function VehicleSellingPoint:update(dt)
87end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
96function VehicleSellingPoint:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
97 if self.isEnabled and (not g_isPresentationVersion or g_isPresentationVersionShopEnabled) and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then
98 if onEnter or onLeave then
99 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
100 if onEnter then
101 if not self.objectActivated then
102 g_currentMission:addActivatableObject(self)
103 self.objectActivated = true
104 end
105 else
106 if self.objectActivated then
107 g_currentMission:removeActivatableObject(self)
108 self.objectActivated = false
109 end
110 end
111 end
112 end
113 end
114end

sellAreaTriggerCallback

Description
Sell area trigger callback
Definition
sellAreaTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
123function VehicleSellingPoint:sellAreaTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId)
124 if otherShapeId ~= nil and (onEnter or onLeave) then
125 if onEnter then
126 self.vehicleInRange[otherShapeId] = true
127 elseif onLeave then
128 self.vehicleInRange[otherShapeId] = nil
129 end
130
131 self:determineCurrentVehicle()
132 end
133end

determineCurrentVehicle

Description
Determine current vehicle
Definition
determineCurrentVehicle()
Code
137function VehicleSellingPoint:determineCurrentVehicle()
138 self.currentVehicle = nil
139 for vehicleId, inRange in pairs(self.vehicleInRange) do
140 if inRange ~= nil then
141 self.currentVehicle = g_currentMission.nodeToObject[vehicleId]
142
143 if self.currentVehicle ~= nil then
144 if not SpecializationUtil.hasSpecialization(Rideable, self.currentVehicle.specializations) or self.currentVehicle:getOwnerFarmId() ~= self:getOwnerFarmId() then
145 break
146 end
147 end
148 end
149 -- invalid vehicle (not existing or left), remove from list
150 self.vehicleInRange[vehicleId] = nil
151 end
152end

updateIconVisibility

Description
Turn the icon on or off depending on the current game and the players farm
Definition
updateIconVisibility()

VendingMachine

Description

onActivate

Description
Event function for activation input.
Definition
onActivate()

BeehivePlaceable

Description
Class for placeable beehives
Parent
Placeable

new

Description
Creating placeable beehive
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function BeehivePlaceable:new(isServer, isClient, customMt)
19 local mt = customMt
20 if mt == nil then
21 mt = BeehivePlaceable_mt
22 end
23
24 local self = Placeable:new(isServer, isClient, mt)
25
26 registerObjectClassName(self, "BeehivePlaceable")
27
28 return self
29end

delete

Description
Deleting placeable beehive
Definition
delete()
Code
33function BeehivePlaceable:delete()
34 unregisterObjectClassName(self)
35 g_currentMission.environment:removeHourChangeListener(self)
36 if self.particleSystem ~= nil then
37 ParticleUtil.deleteParticleSystem(self.particleSystem)
38 end
39 BeehivePlaceable:superClass().delete(self)
40end

deleteFinal

Description
Deleting placeable beehive final
Definition
deleteFinal()
Code
44function BeehivePlaceable:deleteFinal()
45 BeehivePlaceable:superClass().deleteFinal(self)
46end

load

Description
Load beehive
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
59function BeehivePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
60 if not BeehivePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
61 return false
62 end
63
64 local xmlFile = loadXMLFile("TempXML", xmlFilename)
65
66 self.particleSystem = {}
67 ParticleUtil.loadParticleSystem(xmlFile, self.particleSystem, "placeable.particleSystem", self.nodeId, true, nil, self.baseDirectory)
68
69 delete(xmlFile)
70
71 return true
72end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
76function BeehivePlaceable:finalizePlacement()
77 BeehivePlaceable:superClass().finalizePlacement(self)
78end

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
82function BeehivePlaceable:hourChanged()
83 if self.isServer then
84 g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), "propertyIncome")
85 g_currentMission:addMoneyChange(self.incomePerHour, self:getOwnerFarmId(), EconomyManager.MONEY_TYPE_PROPERTY_INCOME)
86 end
87end

BgaPlaceable

Description
Class for bga
Parent
Placeable

new

Description
Creating placeable silo
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
24function BgaPlaceable:new(isServer, isClient, customMt)
25 local self = Placeable:new(isServer, isClient, customMt or BgaPlaceable_mt)
26
27 registerObjectClassName(self, "BgaPlaceable")
28
29 return self
30end

delete

Description
Deleting placeable silo
Definition
delete()
Code
34function BgaPlaceable:delete()
35 self.bga:delete()
36
37 for _, bunkerSilo in ipairs(self.bunkerSilos) do
38 bunkerSilo:delete()
39 end
40
41 g_farmlandManager:removeStateChangeListener(self)
42
43 unregisterObjectClassName(self)
44 BgaPlaceable:superClass().delete(self)
45end

load

Description
Load silo
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
58function BgaPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
59 if not BgaPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
60 return false
61 end
62
63 local xmlFile = loadXMLFile("TempXML", xmlFilename)
64
65 self.bga = Bga:new(self.isServer, self.isClient)
66 if not self.bga:load(self.nodeId, xmlFile, "placeable.bga") then
67 self.bga:delete()
68 delete(xmlFile)
69 return false
70 end
71
72 self.bunkerSilos = {}
73
74 local i = 0
75 while true do
76 local bunkerKey = string.format("placeable.bunkerSilos.bunkerSilo(%d)", i)
77 if not hasXMLProperty(xmlFile, bunkerKey) then
78 break
79 end
80
81 local bunkerSilo = BunkerSilo:new(self.isServer, self.isClient)
82 if bunkerSilo:load(self.nodeId, xmlFile, bunkerKey) then
83 table.insert(self.bunkerSilos, bunkerSilo)
84 else
85 bunkerSilo:delete()
86 end
87
88 i = i + 1
89 end
90
91 delete(xmlFile)
92
93 return true
94end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
98function BgaPlaceable:finalizePlacement()
99 BgaPlaceable:superClass().finalizePlacement(self)
100
101 self.bga:register(true)
102
103 for _, bunkerSilo in ipairs(self.bunkerSilos) do
104 bunkerSilo:register(true)
105 end
106
107 if self.isServer then
108 self:updateOwnership(true)
109 end
110
111 g_farmlandManager:addStateChangeListener(self)
112end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
118function BgaPlaceable:readStream(streamId, connection)
119 BgaPlaceable:superClass().readStream(self, streamId, connection)
120 if connection:getIsServer() then
121 local bgaId = NetworkUtil.readNodeObjectId(streamId)
122 self.bga:readStream(streamId, connection)
123 g_client:finishRegisterObject(self.bga, bgaId)
124
125 for _, bunkerSilo in ipairs(self.bunkerSilos) do
126 local bunkerSiloId = NetworkUtil.readNodeObjectId(streamId)
127 bunkerSilo:readStream(streamId, connection)
128 g_client:finishRegisterObject(bunkerSilo, bunkerSiloId)
129 end
130 end
131end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
137function BgaPlaceable:writeStream(streamId, connection)
138 BgaPlaceable:superClass().writeStream(self, streamId, connection)
139 if not connection:getIsServer() then
140 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.bga))
141 self.bga:writeStream(streamId, connection)
142 g_server:registerObjectInStream(connection, self.bga)
143
144 for _, bunkerSilo in ipairs(self.bunkerSilos) do
145 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bunkerSilo))
146 bunkerSilo:writeStream(streamId, connection)
147 g_server:registerObjectInStream(connection, bunkerSilo)
148 end
149 end
150end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
167function BgaPlaceable:collectPickObjects(node)
168 local foundNode = false
169 for _, unloadTrigger in ipairs(self.bga.bunker.unloadingStation.unloadTriggers) do
170 if node == unloadTrigger.exactFillRootNode then
171 foundNode = true
172 break
173 end
174 end
175
176 if not foundNode then
177 for _, loadTrigger in ipairs(self.bga.digestateSilo.loadingStation.loadTriggers) do
178 if node == loadTrigger.triggerNode then
179 foundNode = true
180 break
181 end
182 end
183 end
184
185 if not foundNode then
186 BgaPlaceable:superClass().collectPickObjects(self, node)
187 end
188end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
196function BgaPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
197 if not BgaPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
198 return false
199 end
200
201 self.bga:loadFromXMLFile(xmlFile, key..".bga", resetVehicles)
202
203 local i = 0
204 while true do
205 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, i)
206 if not hasXMLProperty(xmlFile, bunkerKey) then
207 break
208 end
209
210 local index = getXMLInt(xmlFile, bunkerKey.."#index")
211
212 if index ~= nil then
213 if self.bunkerSilos[index] ~= nil then
214 if not self.bunkerSilos[index]:loadFromXMLFile(xmlFile, bunkerKey) then
215 return false
216 end
217 else
218 g_logManager:warning("Could not load bunkersilo. Given 'index' '%d' is not defined!", index)
219 end
220 end
221
222 i = i + 1
223 end
224
225 return true
226end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
233function BgaPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
234 BgaPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
235
236 self.bga:saveToXMLFile(xmlFile, key..".bga", usedModNames)
237
238 for k, bunkerSilo in ipairs(self.bunkerSilos) do
239 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, k-1)
240 setXMLInt(xmlFile, bunkerKey .. "#index", k)
241 bunkerSilo:saveToXMLFile(xmlFile, bunkerKey, usedModNames)
242 end
243end

BunkerSiloPlaceable

Description

new

Description
Creating placeable silo
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
26function BunkerSiloPlaceable:new(isServer, isClient, customMt)
27 local self = Placeable:new(isServer, isClient, customMt or BgaPlaceable_mt)
28
29 registerObjectClassName(self, "BunkerSiloPlaceable")
30
31 return self
32end

delete

Description
Deleting placeable silo
Definition
delete()
Code
36function BunkerSiloPlaceable:delete()
37 for _, bunkerSilo in ipairs(self.bunkerSilos) do
38 bunkerSilo:delete()
39 end
40
41 unregisterObjectClassName(self)
42 BunkerSiloPlaceable:superClass().delete(self)
43end

load

Description
Load silo
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
56function BunkerSiloPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
57 if not BunkerSiloPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
58 return false
59 end
60
61 local xmlFile = loadXMLFile("TempXML", xmlFilename)
62
63 self.bunkerSilos = {}
64
65 local i = 0
66 while true do
67 local bunkerKey = string.format("placeable.bunkerSilos.bunkerSilo(%d)", i)
68 if not hasXMLProperty(xmlFile, bunkerKey) then
69 break
70 end
71
72 local bunkerSilo = BunkerSilo:new(self.isServer, self.isClient)
73 if bunkerSilo:load(self.nodeId, xmlFile, bunkerKey) then
74 table.insert(self.bunkerSilos, bunkerSilo)
75 else
76 bunkerSilo:delete()
77 end
78
79 i = i + 1
80 end
81
82 delete(xmlFile)
83
84 return true
85end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
89function BunkerSiloPlaceable:finalizePlacement()
90 BunkerSiloPlaceable:superClass().finalizePlacement(self)
91
92 for _, bunkerSilo in ipairs(self.bunkerSilos) do
93 bunkerSilo:register(true)
94 end
95end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
109function BunkerSiloPlaceable:readStream(streamId, connection)
110 BunkerSiloPlaceable:superClass().readStream(self, streamId, connection)
111 if connection:getIsServer() then
112 for _, bunkerSilo in ipairs(self.bunkerSilos) do
113 local bunkerSiloId = NetworkUtil.readNodeObjectId(streamId)
114 bunkerSilo:readStream(streamId, connection)
115 g_client:finishRegisterObject(bunkerSilo, bunkerSiloId)
116 end
117 end
118end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
124function BunkerSiloPlaceable:writeStream(streamId, connection)
125 BunkerSiloPlaceable:superClass().writeStream(self, streamId, connection)
126 if not connection:getIsServer() then
127 for _, bunkerSilo in ipairs(self.bunkerSilos) do
128 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(bunkerSilo))
129 bunkerSilo:writeStream(streamId, connection)
130 g_server:registerObjectInStream(connection, bunkerSilo)
131 end
132 end
133end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
138function BunkerSiloPlaceable:collectPickObjects(node)
139-- local foundNode = false
140-- for _, unloadTrigger in ipairs(self.bga.bunker.unloadingStation.unloadTriggers) do
141-- if node == unloadTrigger.exactFillRootNode then
142-- foundNode = true
143-- break
144-- end
145-- end
146
147 if not foundNode then
148 BunkerSiloPlaceable:superClass().collectPickObjects(self, node)
149 end
150end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
158function BunkerSiloPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
159 if not BunkerSiloPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
160 return false
161 end
162
163 local i = 0
164 while true do
165 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, i)
166 if not hasXMLProperty(xmlFile, bunkerKey) then
167 break
168 end
169
170 local index = getXMLInt(xmlFile, bunkerKey.."#index")
171
172 if index ~= nil then
173 if self.bunkerSilos[index] ~= nil then
174 if not self.bunkerSilos[index]:loadFromXMLFile(xmlFile, bunkerKey) then
175 return false
176 end
177 else
178 g_logManager:warning("Could not load bunkersilo. Given 'index' '%d' is not defined!", index)
179 end
180 end
181
182 i = i + 1
183 end
184
185 return true
186end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
193function BunkerSiloPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
194 BunkerSiloPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
195
196 for k, bunkerSilo in ipairs(self.bunkerSilos) do
197 local bunkerKey = string.format("%s.bunkerSilo(%d)", key, k-1)
198 setXMLInt(xmlFile, bunkerKey .. "#index", k)
199 bunkerSilo:saveToXMLFile(xmlFile, bunkerKey, usedModNames)
200 end
201end

BuyingStationPlaceable

Description

new

Description
Creating placeable silo
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
26function BuyingStationPlaceable:new(isServer, isClient, customMt)
27 local self = Placeable:new(isServer, isClient, customMt or SiloPlaceable_mt)
28
29 registerObjectClassName(self, "BuyingStationPlaceable")
30
31 return self
32end

delete

Description
Deleting placeable silo
Definition
delete()
Code
36function BuyingStationPlaceable:delete()
37 if self.buyingStation ~= nil then
38 self.buyingStation:delete()
39 end
40
41 unregisterObjectClassName(self)
42 BuyingStationPlaceable:superClass().delete(self)
43end

load

Description
Load silo
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
56function BuyingStationPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
57 if not BuyingStationPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
58 return false
59 end
60
61 local xmlFile = loadXMLFile("TempXML", xmlFilename)
62
63 self.buyingStation = BuyingStation:new(self.isServer, self.isClient)
64 self.buyingStation:load(self.nodeId, xmlFile, "placeable.buyingStation")
65 self.buyingStation.owningPlaceable = self
66
67 delete(xmlFile)
68
69 return true
70end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
74function BuyingStationPlaceable:finalizePlacement()
75 BuyingStationPlaceable:superClass().finalizePlacement(self)
76
77 self.buyingStation:register(true)
78end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
84function BuyingStationPlaceable:readStream(streamId, connection)
85 BuyingStationPlaceable:superClass().readStream(self, streamId, connection)
86 if connection:getIsServer() then
87 local buyingStationId = NetworkUtil.readNodeObjectId(streamId)
88 self.buyingStation:readStream(streamId, connection)
89 g_client:finishRegisterObject(self.buyingStation, buyingStationId)
90 end
91end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
97function BuyingStationPlaceable:writeStream(streamId, connection)
98 BuyingStationPlaceable:superClass().writeStream(self, streamId, connection)
99 if not connection:getIsServer() then
100 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.buyingStation))
101 self.buyingStation:writeStream(streamId, connection)
102 g_server:registerObjectInStream(connection, self.buyingStation)
103 end
104end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
109function BuyingStationPlaceable:collectPickObjects(node)
110 local foundNode = false
111 if not foundNode then
112 for _, loadTrigger in ipairs(self.buyingStation.loadTriggers) do
113 if node == loadTrigger.triggerNode then
114 foundNode = true
115 break
116 end
117 end
118 end
119
120 if not foundNode then
121 BuyingStationPlaceable:superClass().collectPickObjects(self, node)
122 end
123end

Doghouse

Description

new

Description
Creating instance and initializing member variables
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom meta table
Return Values
tableinstanceInstance of object
Code
14function Doghouse:new(isServer, isClient, customMt)
15 local self = Placeable:new(isServer, isClient, customMt or Doghouse_mt)
16
17 registerObjectClassName(self, "Doghouse")
18 -- dog
19 self.dog = Dog:new()
20
21 -- trigger
22 self.triggerNode = nil
23 self.isActivatable = false
24 self.activateText = g_i18n:getText("action_doghouseFillbowl")
25
26 -- network
27 self.forcedClipDistance = 80
28
29 if not g_currentMission.gameStarted then
30 g_currentMission:registerObjectToCallOnMissionStart(self)
31 end
32
33 return self
34end

delete

Description
Delete instance
Definition
delete()
Code
38function Doghouse:delete()
39 self.dog:delete()
40 self.dog = nil
41 unregisterObjectClassName(self)
42 if self.triggerNode ~= nil then
43 removeTrigger(self.triggerNode)
44 end
45 Doghouse:superClass().delete(self)
46end

getCanBePlacedAt

Description
Returns true if we can place a building
Definition
getCanBePlacedAt()
Return Values
Code
51function Doghouse:getCanBePlacedAt(x, y, z, distance)
52 local canBePlaced = Doghouse:superClass().getCanBePlacedAt(self, x, y, z, distance)
53 return canBePlaced and not self:isDoghouseRegistered()
54end

canBuy

Description
Returns true if we can place a building
Definition
canBuy()
Return Values
Code
59function Doghouse:canBuy()
60 local canBuy = AnimalHusbandry:superClass().canBuy(self)
61 return canBuy and not self:isDoghouseRegistered(), g_i18n:getText("warning_onlyOneOfThisItemAllowedPerFarm")
62end

finalizePlacement

Description
Finalize placement
Definition
finalizePlacement()
Return Values
boolreturnstrue if placement successful
Code
67function Doghouse:finalizePlacement()
68 Doghouse:superClass().finalizePlacement(self)
69
70 -- dog specific information
71 local xmlFile = loadXMLFile("TempXML", self.configFileName)
72
73 if xmlFile == 0 then
74 return false
75 end
76
77 self.spawnNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.dog#spawnNode"))
78 local posX, posY, posZ = getWorldTranslation(self.spawnNode)
79 local dogXMLConfig = getXMLString(xmlFile, "placeable.dog#xmlFilename")
80 self.dog:init(self, dogXMLConfig, posX, posY, posZ, self.isServer, self.isClient)
81 self:registerDoghouseToMission()
82
83 self.namePlateNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.nameplate#node"))
84
85 -- player interaction trigger
86 self.triggerNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.playerInteractionTrigger#node"))
87 if self.triggerNode ~= nil then
88 addTrigger(self.triggerNode, "playerInteractionTriggerCallback", self)
89 end
90
91 self.foodNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.bowl#foodNode"))
92 delete(xmlFile)
93 if self.foodNode ~= nil then
94 setVisibility(self.foodNode, false)
95 return true
96 end
97 return false
98end

onSell

Description
Called on sell of the placeable
Definition
onSell()
Code
102function Doghouse:onSell()
103 Doghouse:superClass().onSell(self)
104 if self.isServer then
105 self:unregisterDoghouseToMission()
106 end
107end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
113function Doghouse:readStream(streamId, connection)
114 Doghouse:superClass().readStream(self, streamId, connection)
115 if connection:getIsServer() then
116 self.dog:setName(Utils.getNoNil(streamReadString(streamId), ""))
117 end
118end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
124function Doghouse:writeStream(streamId, connection)
125 Doghouse:superClass().writeStream(self, streamId, connection)
126 if not connection:getIsServer() then
127 streamWriteString(streamId, self.dog.name)
128 end
129end

writeUpdateStream

Description
Write update network stream
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdnetwork stream identification
tableconnectionconnection information
integerdirtyMask
Code
136function Doghouse:writeUpdateStream(streamId, connection, dirtyMask)
137 Doghouse:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
138 self.dog:writeUpdateStream(streamId, connection, dirtyMask)
139end

readUpdateStream

Description
Read update network stream
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdnetwork stream identification
integertimestamp
tableconnectionconnection information
Code
146function Doghouse:readUpdateStream(streamId, timestamp, connection)
147 Doghouse:superClass().readUpdateStream(self, streamId, timestamp, connection)
148 self.dog:readUpdateStream(streamId, timestamp, connection)
149end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
157function Doghouse:loadFromXMLFile(xmlFile, key, resetVehicles)
158 local result = Doghouse:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles)
159
160 if result then
161 self.dog:setName(getXMLString(xmlFile, key.."#animalName"))
162 return result
163 end
164 return result
165end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
172function Doghouse:saveToXMLFile(xmlFile, key, usedModNames)
173 Doghouse:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
174
175 setXMLString(xmlFile, key.."#animalName", HTMLUtil.encodeToHTML(self.dog.name))
176end

testScope

Description
Test scope
Definition
testScope(float x, float y, float z, float coeff)
Arguments
floatxx position
floatyy position
floatzz position
floatcoeffcoeff
Return Values
booleaninScopein scope
Code
185function Doghouse:testScope(x,y,z, coeff)
186 local distance, clipDistance = getCompanionClosestDistance(self.dog.dogInstance, x, y, z)
187 local clipDist = math.min(clipDistance * coeff, self.forcedClipDistance)
188
189 if distance < clipDist then
190 return true
191 else
192 return false
193 end
194end

getUpdatePriority

Description
Get update priority
Definition
getUpdatePriority(float skipCount, float x, float y, float z, float coeff, table connection)
Arguments
floatskipCountskip count
floatxx position
floatyy position
floatzz position
floatcoeffcoeff
tableconnectionconnection
Return Values
floatprioritypriority
Code
205function Doghouse:getUpdatePriority(skipCount, x, y, z, coeff, connection)
206 local distance, clipDistance = getCompanionClosestDistance(self.dog.dogInstance, x, y, z)
207 local clipDist = math.min(clipDistance * coeff, self.forcedClipDistance)
208 local result = (1.0 - distance / clipDist) * 0.8 + 0.5 * skipCount * 0.2
209
210 return result
211end

onGhostRemove

Description
On ghost remove
Definition
onGhostRemove()
Code
215function Doghouse:onGhostRemove()
216 setVisibility(self.nodeId, false)
217 removeFromPhysics(self.nodeId)
218 self.dog:setVisibility(false)
219end

onGhostAdd

Description
On ghost add
Definition
onGhostAdd()
Code
223function Doghouse:onGhostAdd()
224 setVisibility(self.nodeId, true)
225 addToPhysics(self.nodeId)
226 self.dog:setVisibility(true)
227end

updateTick

Description
Update network tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
232function Doghouse:updateTick(dt)
233 Doghouse:superClass().updateTick(self, dt)
234
235 self.dog:updateTick(dt)
236end

drawDogName

Description
Definition
drawDogName()
Code
252function Doghouse:drawDogName()
253 -- @Todo: adust text width
254 setTextColor(0.843, 0.745, 0.705, 1.0)
255 setTextAlignment(RenderText.ALIGN_CENTER)
256 local x,y,z = getWorldTranslation(self.namePlateNode)
257 local rx,ry,rz = getWorldRotation(self.namePlateNode)
258 renderText3D(x,y,z, rx,ry,rz, 0.04, self.dog.name)
259 setTextAlignment(RenderText.ALIGN_LEFT)
260end

playerInteractionTriggerCallback

Description
Callback when interaction trigger is activated
Definition
playerInteractionTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
269function Doghouse:playerInteractionTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
270 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode and g_currentMission.player.farmId == self:getOwnerFarmId() then
271 if onEnter then
272 self.isActivatable = true
273 elseif onLeave then
274 self.isActivatable = false
275 end
276 end
277 self:raiseActive()
278end

onActivateObject

Description
Callback on bowl activated
Definition
onActivateObject()
Code
282function Doghouse:onActivateObject()
283 self:raiseActive()
284end

getIsActivatable

Description
Checks if doghouse can be activated and bowl is empty
Definition
getIsActivatable()
Return Values
boolreturntrue if doghouse can be activated to fill bowl
Code
289function Doghouse:getIsActivatable()
290 return self.isActivatable
291end

drawActivate

Description
Draw HUD icon
Definition
drawActivate()
Code
295function Doghouse:drawActivate()
296 g_currentMission:showFillDogBowlContext()
297end

onPlayerLeave

Description
Teleport animal back to doghouse
Definition
onPlayerLeave()
Code
301function Doghouse:onPlayerLeave()
302 self:raiseActive()
303end

isDoghouseRegistered

Description
Returns true if a doghouse is registered
Definition
isDoghouseRegistered()
Return Values
Code
308function Doghouse:isDoghouseRegistered()
309 local dogHouse = g_currentMission:getDoghouse(self:getOwnerFarmId())
310 return dogHouse ~= nil
311end

registerDoghouseToMission

Description
Registers the doghouse to the mission game.
Definition
registerDoghouseToMission()
Return Values
booltrueif registration went well
Code
316function Doghouse:registerDoghouseToMission()
317 if not self:isDoghouseRegistered() and self.dog ~= nil then
318 g_currentMission.doghouses[self.dog] = self
319 return true
320 end
321 return false
322end

unregisterDoghouseToMission

Description
Registers the doghouse to the mission game.
Definition
unregisterDoghouseToMission()
Return Values
booltrueif registration went well
Code
327function Doghouse:unregisterDoghouseToMission()
328 if self.dog ~= nil then
329 g_currentMission.doghouses[self.dog] = nil
330 return true
331 end
332 return false
333end

FarmhousePlaceable

Description
Class for placeable farmhouse
Parent
Placeable

new

Description
Creating placeable farmhouse
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
25function FarmhousePlaceable:new(isServer, isClient, customMt)
26 local self = Placeable:new(isServer, isClient, customMt or FarmhousePlaceable_mt)
27
28 registerObjectClassName(self, "FarmhousePlaceable")
29
30 return self
31end

delete

Description
Deleting placeable farmhouse
Definition
delete()
Code
35function FarmhousePlaceable:delete()
36 unregisterObjectClassName(self)
37
38 if self.sleepingTrigger ~= nil then
39 removeTrigger(self.sleepingTrigger)
40 end
41
42 g_currentMission:removeActivatableObject(self)
43 self.objectActivated = false
44
45 FarmhousePlaceable:superClass().delete(self)
46end

load

Description
Load farmhouse
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
59function FarmhousePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
60 if not FarmhousePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
61 return false
62 end
63
64 local xmlFile = loadXMLFile("TempXML", xmlFilename)
65
66 self.spawnNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.farmhouse#spawnNode"))
67
68 self.sleepingTrigger = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.farmhouse.sleeping#triggerNode"))
69 if self.sleepingTrigger ~= nil then
70 addTrigger(self.sleepingTrigger, "sleepingTriggerCallback", self)
71 end
72 self.sleepingCamera = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.farmhouse.sleeping#cameraNode"))
73
74 self.activateText = g_i18n:getText("ui_inGameSleep")
75
76 self.isEnabled = true
77 self.objectActivated = false
78
79
80 delete(xmlFile)
81
82 return true
83end

getIsActivatable

Description
Get is activateable
Definition
getIsActivatable()
Return Values
booleanisActivateableis activateable
Code
134function FarmhousePlaceable:getIsActivatable()
135 return g_currentMission:getFarmId() == self:getOwnerFarmId()
136end

onActivateObject

Description
On activate object
Definition
onActivateObject()
Code
144function FarmhousePlaceable:onActivateObject()
145 g_sleepManager:showDialog()
146end

GreenhousePlaceable

Description
Class for placeable greenhouse

new

Description
Creating placeable greenhouse
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
20function GreenhousePlaceable:new(isServer, isClient, customMt)
21 local self = Placeable:new(isServer, isClient, customMt or GreenhousePlaceable_mt)
22
23 registerObjectClassName(self, "GreenhousePlaceable")
24
25 self.waterTankCapacity = 1000
26 self.waterTankFillLevel = 1000
27 self.sentWaterTankFillLevel = self.waterTankFillLevel
28 self.waterTankUsagePerHour = 0
29 self.waterTankFillLitersPerSecond = 200
30 self.waterTrailers = {}
31 self.isFruitAlive = true
32 self.displayFruit = false
33
34 self.manureFillLevel = 0
35 self.manureUsagePerHour = 0
36 self.manureCapacity = 200
37 self.manurePlaneMinY = 0
38 self.manurePlaneMaxY = 1
39 self.sentManureFillLevel = self.manureFillLevel
40
41 self.vehiclesInRange = {}
42 self.playerInRange = false
43
44 self.greenhousePlaceableDirtyFlag = self:getNextDirtyFlag()
45
46 self.waterTrailerActivatable = GreenhousePlaceableWaterTankActivatable:new(self)
47
48 return self
49end

delete

Description
Deleting placeable greenhouse
Definition
delete()
Code
53function GreenhousePlaceable:delete()
54 if self.shovelTarget ~= nil then
55 self.shovelTarget:delete()
56 end
57
58 g_currentMission:removeActivatableObject(self.waterTrailerActivatable)
59 unregisterObjectClassName(self)
60 g_currentMission.environment:removeHourChangeListener(self)
61
62 if self.waterTankTriggerNode ~= nil then
63 removeTrigger(self.waterTankTriggerNode)
64 end
65
66 if g_client ~= nil then
67 for _,sample in pairs(self.samples) do
68 g_soundManager:deleteSample(sample)
69 end
70 end
71
72 GreenhousePlaceable:superClass().delete(self)
73end

deleteFinal

Description
Deleting placeable greenhouse final
Definition
deleteFinal()
Code
77function GreenhousePlaceable:deleteFinal()
78 GreenhousePlaceable:superClass().deleteFinal(self)
79end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
85function GreenhousePlaceable:readStream(streamId, connection)
86 GreenhousePlaceable:superClass().readStream(self, streamId, connection)
87 if connection:getIsServer() then
88 local waterTankFillLevel = streamReadUInt8(streamId)/255*self.waterTankCapacity
89 self:setWaterTankFillLevel(waterTankFillLevel)
90 local manureFillLevel = streamReadUInt8(streamId)/255*self.manureCapacity
91 self:setManureFillLevel(manureFillLevel)
92 end
93end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
99function GreenhousePlaceable:writeStream(streamId, connection)
100 GreenhousePlaceable:superClass().writeStream(self, streamId, connection)
101 if not connection:getIsServer() then
102 streamWriteUInt8(streamId, math.floor(self.waterTankFillLevel/self.waterTankCapacity * 255))
103 streamWriteUInt8(streamId, math.floor(self.manureFillLevel/self.manureCapacity * 255))
104 end
105end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
112function GreenhousePlaceable:readUpdateStream(streamId, timestamp, connection)
113 GreenhousePlaceable:superClass().readUpdateStream(self, streamId, timestamp, connection)
114 if connection:getIsServer() then
115 local waterTankFillLevel = streamReadUInt8(streamId)/255*self.waterTankCapacity
116 self:setWaterTankFillLevel(waterTankFillLevel)
117 local manureFillLevel = streamReadUInt8(streamId)/255*self.manureCapacity
118 self:setManureFillLevel(manureFillLevel)
119 end
120end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
127function GreenhousePlaceable:writeUpdateStream(streamId, connection, dirtyMask)
128 GreenhousePlaceable:superClass().writeUpdateStream(self, streamId, connection, dirtyMask)
129 if not connection:getIsServer() then
130 streamWriteUInt8(streamId, math.floor(self.waterTankFillLevel/self.waterTankCapacity * 255))
131 streamWriteUInt8(streamId, math.floor(self.manureFillLevel/self.manureCapacity * 255))
132 end
133end

createNode

Description
Create node
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleansuccesssuccess
Code
139function GreenhousePlaceable:createNode(i3dFilename)
140 if not GreenhousePlaceable:superClass().createNode(self, i3dFilename) then
141 return false
142 end
143
144 return true
145end

load

Description
Load greenhouse
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
158function GreenhousePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
159 if not GreenhousePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
160 return false
161 end
162
163 local xmlFile = loadXMLFile("TempXML", xmlFilename)
164
165 local fruitAlive = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.fruit#alive"))
166 local fruitDead = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.fruit#dead"))
167 if fruitAlive ~= nil then
168 self.fruitAlive = fruitAlive
169 end
170 if fruitDead ~= nil then
171 self.fruitDead = fruitDead
172 end
173
174 self.waterTankTriggerNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.waterTank#triggerNode"))
175 self.waterTankCapacity = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.waterTank#capacity"), self.waterTankCapacity)
176 self.waterTankUsagePerHour = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.waterTank#usagePerHour"), self.waterTankUsagePerHour)
177 self.waterTankFillLitersPerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.waterTank#fillLitersPerSecond"), self.waterTankFillLitersPerSecond)
178
179 self.samples = {}
180 if g_client ~= nil then
181 self.samples.refuel = g_soundManager:loadSampleFromXML(xmlFile, "placeable.waterTank.sounds", "refuel", self.baseDirectory, self.nodeId, 0, AudioGroup.VEHICLE, nil, nil)
182 end
183
184 self.manurePlane = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.manurePlane#node"))
185 self.shovelTargetNode = I3DUtil.indexToObject(self.nodeId, Utils.getNoNil(getXMLString(xmlFile, "placeable.manurePlane#shovelTargetIndex"), getXMLString(xmlFile, "placeable.manurePlane#collisionNode")))
186 local minY, maxY = StringUtil.getVectorFromString(getXMLString(xmlFile, "placeable.manurePlane#minMaxY"))
187 if minY ~= nil and maxY ~= nil then
188 self.manurePlaneMinY = minY
189 self.manurePlaneMaxY = maxY
190 end
191 self.manureCapacity = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.manurePlane#capacity"), self.manureCapacity)
192 self.manureUsagePerHour = Utils.getNoNil(getXMLFloat(xmlFile, "placeable.manurePlane#usagePerHour"), self.manureUsagePerHour)
193
194 delete(xmlFile)
195
196 self:setWaterTankFillLevel(0)
197 self.sentWaterTankFillLevel = self.waterTankFillLevel
198
199 self:setManureFillLevel(0)
200 self.sentManureFillLevel = self.manureFillLevel
201
202 return true
203end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
207function GreenhousePlaceable:finalizePlacement()
208 GreenhousePlaceable:superClass().finalizePlacement(self)
209 g_currentMission.environment:addHourChangeListener(self)
210 if self.waterTankTriggerNode ~= nil then
211 addTrigger(self.waterTankTriggerNode, "onWaterTankTrigger", self)
212 end
213
214 if self.shovelTargetNode ~= nil then
215 if self.shovelTargetNode ~= nil then
216 self.shovelTarget = ShovelTarget:new(self)
217 if not self.shovelTarget:load(self.shovelTargetNode) then
218 self.shovelTarget:delete()
219 self.shovelTarget = nil
220 end
221 end
222 end
223end

initPose

Description
Initialize pose
Definition
initPose(float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
floatxx world position
floatyy world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Code
234function GreenhousePlaceable:initPose(x,y,z, rx,ry,rz, initRandom)
235 GreenhousePlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom)
236end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
244function GreenhousePlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
245
246 if not GreenhousePlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
247 return false
248 end
249
250 local waterTankFillLevel = getXMLFloat(xmlFile, key.."#waterTankFillLevel")
251 if waterTankFillLevel ~= nil then
252 self:setWaterTankFillLevel(waterTankFillLevel)
253 end
254 local manureFillLevel = getXMLFloat(xmlFile, key.."#manureFillLevel")
255 if manureFillLevel ~= nil then
256 self:setManureFillLevel(manureFillLevel)
257 end
258
259 return true
260end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
267function GreenhousePlaceable:saveToXMLFile(xmlFile, key, usedModNames)
268 GreenhousePlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
269
270 setXMLFloat(xmlFile, key.."#waterTankFillLevel", self.waterTankFillLevel)
271 setXMLFloat(xmlFile, key.."#manureFillLevel", self.manureFillLevel)
272end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
277function GreenhousePlaceable:update(dt)
278 GreenhousePlaceable:superClass().update(self, dt)
279 if self:getShowInfo() then
280 g_currentMission:addExtraPrintText(g_i18n:getText("info_waterFillLevel").." "..math.floor(self.waterTankFillLevel).." ("..math.floor(100*self.waterTankFillLevel/self.waterTankCapacity).."%)")
281 g_currentMission:addExtraPrintText(g_i18n:getText("info_manureFillLevel").." "..math.floor(self.manureFillLevel).." ("..math.floor(100*self.manureFillLevel/self.manureCapacity).."%)")
282 end
283end

updateTick

Description
updateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
288function GreenhousePlaceable:updateTick(dt)
289 if self.isServer then
290
291 if self.waterTankFillLevel ~= self.sentWaterTankFillLevel then
292 self:raiseDirtyFlags(self.greenhousePlaceableDirtyFlag)
293
294 self.sentWaterTankFillLevel = self.waterTankFillLevel
295 end
296 if self.manureFillLevel ~= self.sentManureFillLevel then
297 self:raiseDirtyFlags(self.greenhousePlaceableDirtyFlag)
298
299 self.sentManureFillLevel = self.manureFillLevel
300 end
301
302 if self.isWaterTankFilling then
303 local disableFilling = false
304 local waterFillLevel = self.waterTankFillTrailer:getFillLevel(FillType.WATER)
305 if waterFillLevel > 0 then
306 local oldFillLevel = self.waterTankFillLevel
307
308 local delta = self.waterTankFillLitersPerSecond*dt*0.001
309 delta = math.min(delta, waterFillLevel)
310
311 self:setWaterTankFillLevel(self.waterTankFillLevel + delta)
312
313 local delta = self.waterTankFillLevel - oldFillLevel
314 if delta <= 0 then
315 disableFilling = true
316 end
317 self.waterTankFillTrailer:setFillLevel(waterFillLevel - delta, FillType.WATER, true)
318 else
319 disableFilling = true
320 end
321 if disableFilling then
322 self:setIsWaterTankFilling(false)
323 end
324 end
325
326 end
327end

getShowInfo

Description
Returns true if info should show
Definition
getShowInfo()
Return Values
booleanshowInfoshow info
Code
332function GreenhousePlaceable:getShowInfo()
333 if (g_currentMission.controlPlayer and self.playerInRange) then
334 return true
335 end
336 if not g_currentMission.controlPlayer then
337 for vehicle in pairs(self.vehiclesInRange) do
338 if vehicle:getIsActiveForInput() then
339 return true
340 end
341 end
342 end
343 return false
344end

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
348function GreenhousePlaceable:hourChanged()
349 if self.isServer then
350 self:setWaterTankFillLevel(self.waterTankFillLevel - self.waterTankUsagePerHour)
351 self:setManureFillLevel(self.manureFillLevel - self.manureUsagePerHour)
352
353 if self.isFruitAlive then
354 local income = self.incomePerHour
355 if self.manureFillLevel > 0 then
356 income = income * 2
357 end
358 g_currentMission:addMoney(income, self:getOwnerFarmId(), "propertyIncome")
359 g_currentMission:addMoneyChange(income, self:getOwnerFarmId(), EconomyManager.MONEY_TYPE_PROPERTY_INCOME)
360 end
361 end
362end

setWaterTankFillLevel

Description
Set water tank fill level
Definition
setWaterTankFillLevel(float fillLevel)
Arguments
floatfillLevelnew fill level
Code
367function GreenhousePlaceable:setWaterTankFillLevel(fillLevel)
368 self.waterTankFillLevel = MathUtil.clamp(fillLevel, 0, self.waterTankCapacity)
369
370 self.isFruitAlive = self.waterTankFillLevel > 0.0001
371
372 if self.waterTankFillLevel > 0 then
373 self.displayFruit = true
374 end
375
376 if self.fruitAlive ~= nil then
377 setVisibility(self.fruitAlive, self.isFruitAlive and self.displayFruit)
378 end
379 if self.fruitDead ~= nil then
380 setVisibility(self.fruitDead, not self.isFruitAlive and self.displayFruit)
381 end
382end

addFillLevelFromTool_OLD

Description
Add fill level from tool to trigger
Definition
addFillLevelFromTool_OLD(table object, float fillDelta, integer fillType, integer toolType)
Arguments
tableobjectobject
floatfillDeltadelta to fill
integerfillTypefill type index
integertoolTypetool type index
Return Values
floatfillDeltareal fill delta
Code
391function GreenhousePlaceable:addFillLevelFromTool_OLD(object, fillDelta, fillType, toolType)
392 fillDelta = math.min(fillDelta, self.manureCapacity-self.manureFillLevel)
393
394 if fillDelta > 0 then
395 self:setManureFillLevel(self.manureFillLevel+fillDelta)
396 end
397
398 return fillDelta
399end

getAllowFillTypeFromTool

Description
Returns if shovel fill type is allowed
Definition
getAllowFillTypeFromTool()
Return Values
floatisAllowedis allowed
Code
404function GreenhousePlaceable:getAllowFillTypeFromTool(fillType)
405 return fillType == FillType.MANURE
406end

setManureFillLevel

Description
Set manure fill level
Definition
setManureFillLevel(float fillLevel)
Arguments
floatfillLevelnew fill level
Code
411function GreenhousePlaceable:setManureFillLevel(fillLevel)
412 self.manureFillLevel = MathUtil.clamp(fillLevel, 0, self.manureCapacity)
413
414 if self.manurePlane ~= nil then
415 setVisibility(self.manurePlane, self.manureFillLevel > 0.0001)
416 local x,y,z = getTranslation(self.manurePlane)
417 y = self.manurePlaneMinY + self.manureFillLevel/self.manureCapacity * (self.manurePlaneMaxY - self.manurePlaneMinY)
418
419 setTranslation(self.manurePlane, x,y,z)
420 end
421end

setIsWaterTankFilling

Description
Set is water tank filling
Definition
setIsWaterTankFilling(boolean isWaterTankFilling, table trailer, boolean noEventSend)
Arguments
booleanisWaterTankFillingis water tank filling
tabletrailertrailer
booleannoEventSendno event send
Code
428function GreenhousePlaceable:setIsWaterTankFilling(isWaterTankFilling, trailer, noEventSend)
429 GreenhouseSetIsWaterTankFillingEvent.sendEvent(self, isWaterTankFilling, trailer, noEventSend)
430 if self.isWaterTankFilling ~= isWaterTankFilling then
431 self.isWaterTankFilling = isWaterTankFilling
432 self.waterTankFillTrailer = trailer
433 end
434 if g_client ~= nil then
435 if isWaterTankFilling then
436 g_soundManager:playSample(self.samples.refuel)
437 else
438 g_soundManager:stopSample(self.samples.refuel)
439 end
440 end
441end

addWaterTrailer

Description
Add water trailer in range
Definition
addWaterTrailer(table trailer)
Arguments
tabletrailertrailer
Code
446function GreenhousePlaceable:addWaterTrailer(trailer)
447 if table.getn(self.waterTrailers) == 0 then
448 g_currentMission:addActivatableObject(self.waterTrailerActivatable)
449 end
450 table.insert(self.waterTrailers, trailer)
451end

removeWaterTrailer

Description
Remove water trailer in range
Definition
removeWaterTrailer(table trailer)
Arguments
tabletrailertrailer
Code
456function GreenhousePlaceable:removeWaterTrailer(trailer)
457 for i=1, table.getn(self.waterTrailers) do
458 if self.waterTrailers[i] == trailer then
459 table.remove(self.waterTrailers, i)
460 break
461 end
462 end
463 if table.getn(self.waterTrailers) == 0 then
464 if self.isServer then
465 self:setIsWaterTankFilling(false)
466 end
467 g_currentMission:removeActivatableObject(self.waterTrailerActivatable)
468 end
469end

onWaterTankTrigger

Description
Water tank trigger
Definition
onWaterTankTrigger(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
integerotherShapeIdid of other actor
Code
479function GreenhousePlaceable:onWaterTankTrigger(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
480 if onEnter or onLeave then
481
482 if g_currentMission.player ~= nil and otherActorId == g_currentMission.player.rootNode then
483 if onEnter then
484 self.playerInRange = true
485 else
486 self.playerInRange = false
487 end
488 else
489 local vehicle = g_currentMission.nodeToObject[otherActorId]
490 if vehicle ~= nil then
491 if onEnter then
492 self.vehiclesInRange[vehicle] = true
493 else
494 self.vehiclesInRange[vehicle] = nil
495 end
496 end
497
498
499 local trailer = g_currentMission.objectToTrailer[otherShapeId]
500 if trailer ~= nil and trailer:allowFillType(FillType.WATER, false) then
501 if onEnter then
502 self:addWaterTrailer(trailer)
503 else -- onLeave
504 self:removeWaterTrailer(trailer)
505 end
506 end
507 end
508 end
509end

HeatingPlantPlaceable

Description
Class for placeable heating plants
Parent
Placeable

new

Description
Creating placeable high pressure washer
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function HeatingPlantPlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = HeatingPlantPlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "HeatingPlantPlaceable");
27
28 self.heatingPlantDirtyFlag = self:getNextDirtyFlag();
29
30 return self;
31end;

delete

Description
Deleting heating plant
Definition
delete()
Code
35function HeatingPlantPlaceable:delete()
36 if self.tipTrigger ~= nil then
37 self.tipTrigger:removeUpdateEventListener(self)
38 self.tipTrigger:delete()
39 end
40
41 if self.exhaustEffect ~= nil then
42 g_i3DManager:releaseSharedI3DFile(self.exhaustEffect.filename, self.baseDirectory, true);
43 end
44
45 g_animationManager:deleteAnimations(self.animationNodes)
46
47 unregisterObjectClassName(self);
48 HeatingPlantPlaceable:superClass().delete(self);
49end;

load

Description
Load heating plant
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
62function HeatingPlantPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
63 if not HeatingPlantPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
64 return false;
65 end;
66
67 local xmlFile = loadXMLFile("TempXML", xmlFilename);
68
69 self.tipTrigger = TipTrigger:new(self.isServer, self.isClient)
70 if self.tipTrigger:load(I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.heatingPlant#tipTrigger"))) then
71 self.tipTrigger:register(true)
72 self.tipTrigger:addUpdateEventListener(self)
73 else
74 self.tipTrigger:delete()
75 self.tipTrigger = nil
76 end
77
78 if self.isClient then
79 self.animationNodes = g_animationManager:loadAnimations(xmlFile, "placeable.animationNodes", self.nodeId, self, nil)
80
81 local filename = getXMLString(xmlFile, "placeable.exhaust#filename");
82 local node = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.exhaust#index"));
83 if filename ~= nil then
84 local i3dNode = g_i3DManager:loadSharedI3DFile(filename, self.baseDirectory, false, false, false);
85 if i3dNode ~= 0 then
86 self.exhaustEffect = {}
87 self.exhaustEffect.node = getChildAt(i3dNode, 0);
88 self.exhaustEffect.filename = filename
89 link(Utils.getNoNil(node, self.nodeId), self.exhaustEffect.node);
90 setVisibility(self.exhaustEffect.node, false);
91 setShaderParameter(self.exhaustEffect.node, "param", 0, 0, 0, 0.4, false);
92 delete(i3dNode);
93 end
94 end
95 end
96
97 self.workingTimeDuration = 120*1000
98 self.workingTime = 0
99
100 delete(xmlFile);
101
102 return true;
103end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
109function HeatingPlantPlaceable:readStream(streamId, connection)
110 HeatingPlantPlaceable:superClass().readStream(self, streamId, connection);
111 if connection:getIsServer() then
112 local tipTriggerId = NetworkUtil.readNodeObjectId(streamId);
113 self.tipTrigger:readStream(streamId, connection);
114 g_client:finishRegisterObject(self.tipTrigger, tipTriggerId);
115 end
116end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
122function HeatingPlantPlaceable:writeStream(streamId, connection)
123 HeatingPlantPlaceable:superClass().writeStream(self, streamId, connection);
124 if not connection:getIsServer() then
125 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.tipTrigger));
126 self.tipTrigger:writeStream(streamId, connection);
127 g_server:registerObjectInStream(connection, self.tipTrigger);
128 end
129end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
136function HeatingPlantPlaceable:readUpdateStream(streamId, timestamp, connection)
137 HeatingPlantPlaceable:superClass().readUpdateStream(self, streamId, timestamp, connection);
138 if connection:getIsServer() then
139 local workingTimeBiggerZero = streamReadBool(streamId)
140 if workingTimeBiggerZero then
141 self.workingTime = self.workingTimeDuration
142 if self.exhaustEffect ~= nil then
143 setVisibility(self.exhaustEffect.node, true);
144 end
145 end
146 end;
147end;

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
154function HeatingPlantPlaceable:writeUpdateStream(streamId, connection, dirtyMask)
155 HeatingPlantPlaceable:superClass().writeUpdateStream(self, streamId, connection, dirtyMask);
156 if not connection:getIsServer() then
157 streamWriteBool(streamId, self.workingTime > 0)
158 end;
159end;

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
164function HeatingPlantPlaceable:collectPickObjects(node)
165 if self.tipTrigger == nil or self.tipTrigger.shovelTarget == nil or self.tipTrigger.shovelTarget.nodeId ~= node then
166 HeatingPlantPlaceable:superClass().collectPickObjects(self, node)
167 end
168end;

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
173function HeatingPlantPlaceable:update(dt)
174 HeatingPlantPlaceable:superClass().update(self, dt);
175
176 if self.isClient then
177 if self.workingTime > 0 then
178 self.workingTime = self.workingTime - dt
179 if self.workingTime <= 0 then
180 if self.exhaustEffect ~= nil then
181 setVisibility(self.exhaustEffect.node, false);
182 end
183 g_animationManager:stopAnimations(self.animationNodes)
184 end
185 end
186 end
187end

updateTick

Description
Update tick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
192function HeatingPlantPlaceable:updateTick(dt)
193 HeatingPlantPlaceable:superClass().updateTick(self, dt);
194end

onUpdateEvent

Description
Called if someone filled in something
Definition
onUpdateEvent(table trigger, float fillDelta, integer fillType, table trailer, table tipTriggerTarget)
Arguments
tabletriggertrigger
floatfillDeltadelta filled in
integerfillTypefill type filled in
tabletrailerobject of trailer
tabletipTriggerTargettip trigger target
Code
203function HeatingPlantPlaceable:onUpdateEvent(trigger, fillDelta, fillType, trailer, tipTriggerTarget)
204 if self.exhaustEffect ~= nil then
205 setVisibility(self.exhaustEffect.node, true);
206 end
207 if self.isServer then
208 self:raiseDirtyFlags(self.heatingPlantDirtyFlag);
209 end
210 self.workingTime = self.workingTimeDuration
211
212 g_animationManager:startAnimations(self.animationNodes)
213end

SellingStationPlaceable

Description

new

Description
Creating placeable silo
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
26function SellingStationPlaceable:new(isServer, isClient, customMt)
27 local self = Placeable:new(isServer, isClient, customMt or SellStationPlaceable_mt)
28
29 registerObjectClassName(self, "SellingStationPlaceable")
30
31 return self
32end

delete

Description
Deleting placeable silo
Definition
delete()
Code
36function SellingStationPlaceable:delete()
37 if self.sellingStation ~= nil then
38 g_currentMission:removeUnloadingStation(self.sellingStation)
39 self.sellingStation:delete()
40 end
41
42 unregisterObjectClassName(self)
43 SellingStationPlaceable:superClass().delete(self)
44end

load

Description
Load silo
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
57function SellingStationPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
58 if not SellingStationPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
59 return false
60 end
61
62 local xmlFile = loadXMLFile("TempXML", xmlFilename)
63
64 self.sellingStation = SellingStation:new(self.isServer, self.isClient)
65 self.sellingStation:load(self.nodeId, xmlFile, "placeable.sellingStation")
66 self.sellingStation.owningPlaceable = self
67
68 delete(xmlFile)
69
70 return true
71end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
75function SellingStationPlaceable:finalizePlacement()
76 SellingStationPlaceable:superClass().finalizePlacement(self)
77 self.sellingStation:register(true)
78 g_currentMission:addUnloadingStation(self.sellingStation)
79end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
85function SellingStationPlaceable:readStream(streamId, connection)
86 SellingStationPlaceable:superClass().readStream(self, streamId, connection)
87 if connection:getIsServer() then
88 local sellingStationId = NetworkUtil.readNodeObjectId(streamId)
89 self.sellingStation:readStream(streamId, connection)
90 g_client:finishRegisterObject(self.sellingStation, sellingStationId)
91 end
92end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
98function SellingStationPlaceable:writeStream(streamId, connection)
99 SellingStationPlaceable:superClass().writeStream(self, streamId, connection)
100 if not connection:getIsServer() then
101 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.sellingStation))
102 self.sellingStation:writeStream(streamId, connection)
103 g_server:registerObjectInStream(connection, self.sellingStation)
104 end
105end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
110function SellingStationPlaceable:collectPickObjects(node)
111 local foundNode = false
112 for _, unloadTrigger in ipairs(self.sellingStation.unloadTriggers) do
113 if node == unloadTrigger.exactFillRootNode then
114 foundNode = true
115 break
116 end
117 end
118
119 if not foundNode then
120 SellingStationPlaceable:superClass().collectPickObjects(self, node)
121 end
122end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
130function SellingStationPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
131 if not SellingStationPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
132 return false
133 end
134
135 if not self.sellingStation:loadFromXMLFile(xmlFile, key..".sellingStation") then
136 return false
137 end
138
139 return true
140end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
147function SellingStationPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
148 SellingStationPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
149
150 self.sellingStation:saveToXMLFile(xmlFile, key..".sellingStation", usedModNames)
151end

SiloPlaceable

Description
Class for placeable silo
Parent
Placeable

new

Description
Creating placeable silo
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function SiloPlaceable:new(isServer, isClient, customMt)
19 local self = Placeable:new(isServer, isClient, customMt or SiloPlaceable_mt)
20
21 registerObjectClassName(self, "SiloPlaceable")
22
23 return self
24end

delete

Description
Deleting placeable silo
Definition
delete()
Code
28function SiloPlaceable:delete()
29 if self.unloadingStation ~= nil then
30 self.unloadingStation:delete()
31 end
32
33 if self.loadingStation ~= nil then
34 self.loadingStation:delete()
35 end
36
37 for _, storage in ipairs(self.storages) do
38 g_currentMission:removeStorage(storage)
39 storage:delete()
40 end
41
42 unregisterObjectClassName(self)
43 SiloPlaceable:superClass().delete(self)
44end

load

Description
Load silo
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
57function SiloPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
58 if not SiloPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
59 return false
60 end
61
62 local xmlFile = loadXMLFile("TempXML", xmlFilename)
63
64 self.storagePerFarm = Utils.getNoNil(getXMLBool(xmlFile, "placeable.storages#perFarm"), false)
65 self.foreignSilo = Utils.getNoNil(getXMLBool(xmlFile, "placeable.storages#foreignSilo"), self.storagePerFarm) -- Shows as foreign silo in the menu
66
67 self.unloadingStation = UnloadingStation:new(self.isServer, self.isClient)
68 self.unloadingStation:load(self.nodeId, xmlFile, "placeable.unloadingStation")
69 self.unloadingStation.owningPlaceable = self
70 self.unloadingStation.hasStoragePerFarm = self.storagePerFarm
71
72 self.loadingStation = LoadingStation:new(self.isServer, self.isClient)
73 self.loadingStation:load(self.nodeId, xmlFile, "placeable.loadingStation")
74 self.loadingStation.owningPlaceable = self
75 self.loadingStation.hasStoragePerFarm = self.storagePerFarm
76
77 local numStorageSets = self.storagePerFarm and FarmManager.MAX_NUM_FARMS or 1
78 if not g_currentMission.missionDynamicInfo.isMultiplayer then
79 numStorageSets = 1
80 end
81
82 self.storages = {}
83 local i = 0
84 while true do
85 local storageKey = string.format("placeable.storages.storage(%d)", i)
86 if not hasXMLProperty(xmlFile, storageKey) then
87 break
88 end
89
90 local storageNode = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, storageKey.."#node"))
91 if storageNode ~= nil then
92 for i = 1, numStorageSets do
93 local storage = Storage:new(self.isServer, self.isClient)
94 if storage:load(storageNode, xmlFile, storageKey) then
95 storage.ownerFarmId = i
96 storage.foreignSilo = self.foreignSilo -- Pass along for usage by prices menu
97 table.insert(self.storages, storage)
98 end
99 end
100 else
101 g_logManager:xmlWarning(xmlFilename, "Missing 'node' for storage '%s'!", storageKey)
102 end
103
104 i = i + 1
105 end
106
107 delete(xmlFile)
108
109 return true
110end

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
114function SiloPlaceable:finalizePlacement()
115 SiloPlaceable:superClass().finalizePlacement(self)
116
117 self.unloadingStation:register(true)
118 g_currentMission:addUnloadingStation(self.unloadingStation)
119
120 self.loadingStation:register(true)
121 g_currentMission:addLoadingStation(self.loadingStation)
122
123 for _, storage in ipairs(self.storages) do
124 if not self.storagePerFarm then
125 storage:setOwnerFarmId(self:getOwnerFarmId(), true)
126 end
127
128 g_currentMission:addStorage(storage)
129
130 storage:register(true)
131
132 g_currentMission:addStorageToUnloadingStations(storage, {self.unloadingStation}, false)
133 g_currentMission:addStorageToLoadingStations(storage, {self.loadingStation}, false)
134 end
135end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
161function SiloPlaceable:readStream(streamId, connection)
162 SiloPlaceable:superClass().readStream(self, streamId, connection)
163 if connection:getIsServer() then
164 local unloadingStationId = NetworkUtil.readNodeObjectId(streamId)
165 self.unloadingStation:readStream(streamId, connection)
166 g_client:finishRegisterObject(self.unloadingStation, unloadingStationId)
167
168 local loadingStationId = NetworkUtil.readNodeObjectId(streamId)
169 self.loadingStation:readStream(streamId, connection)
170 g_client:finishRegisterObject(self.loadingStation, loadingStationId)
171
172 for _, storage in ipairs(self.storages) do
173 local storageId = NetworkUtil.readNodeObjectId(streamId)
174 storage:readStream(streamId, connection)
175 g_client:finishRegisterObject(storage, storageId)
176 end
177 end
178end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
184function SiloPlaceable:writeStream(streamId, connection)
185 SiloPlaceable:superClass().writeStream(self, streamId, connection)
186 if not connection:getIsServer() then
187 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.unloadingStation))
188 self.unloadingStation:writeStream(streamId, connection)
189 g_server:registerObjectInStream(connection, self.unloadingStation)
190
191 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(self.loadingStation))
192 self.loadingStation:writeStream(streamId, connection)
193 g_server:registerObjectInStream(connection, self.loadingStation)
194
195 for _, storage in ipairs(self.storages) do
196 NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(storage))
197 storage:writeStream(streamId, connection)
198 g_server:registerObjectInStream(connection, storage)
199 end
200 end
201end

collectPickObjects

Description
Collect pick objects
Definition
collectPickObjects(integer node)
Arguments
integernodenode id
Code
218function SiloPlaceable:collectPickObjects(node)
219 local foundNode = false
220 for _, unloadTrigger in ipairs(self.unloadingStation.unloadTriggers) do
221 if node == unloadTrigger.exactFillRootNode then
222 foundNode = true
223 break
224 end
225 end
226
227 if not foundNode then
228 for _, loadTrigger in ipairs(self.loadingStation.loadTriggers) do
229 if node == loadTrigger.triggerNode then
230 foundNode = true
231 break
232 end
233 end
234 end
235
236 if not foundNode then
237 SiloPlaceable:superClass().collectPickObjects(self, node)
238 end
239end

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
247function SiloPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
248 if not SiloPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
249 return false
250 end
251
252 if not self.unloadingStation:loadFromXMLFile(xmlFile, key..".unloadingStation") then
253 return false
254 end
255
256 local i = 0
257 while true do
258 local storageKey = string.format("%s.storage(%d)", key, i)
259 if not hasXMLProperty(xmlFile, storageKey) then
260 break
261 end
262
263 local index = getXMLInt(xmlFile, storageKey.."#index")
264
265 if index ~= nil then
266 if self.storages[index] ~= nil then
267 if not self.storages[index]:loadFromXMLFile(xmlFile, storageKey) then
268 return false
269 end
270 else
271 g_logManager:warning("Could not load storage. Given 'index' '%d' is not defined!", index)
272 end
273 end
274
275 i = i + 1
276 end
277
278 return true
279end

saveToXMLFile

Description
Get save attributes and nodes
Definition
saveToXMLFile(string nodeIdent)
Arguments
stringnodeIdentnode ident
Return Values
stringattributesattributes
stringnodesnodes
Code
286function SiloPlaceable:saveToXMLFile(xmlFile, key, usedModNames)
287 SiloPlaceable:superClass().saveToXMLFile(self, xmlFile, key, usedModNames)
288
289 self.unloadingStation:saveToXMLFile(xmlFile, key..".unloadingStation", usedModNames)
290
291 for k, storage in ipairs(self.storages) do
292 local storageKey = string.format("%s.storage(%d)", key, k-1)
293 setXMLInt(xmlFile, storageKey .. "#index", k)
294 storage:saveToXMLFile(xmlFile, storageKey, usedModNames)
295 end
296end

SolarCollectorPlaceable

Description
Class for placeable solar collectors
Parent
Placeable

new

Description
Creating placeable solar collector
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function SolarCollectorPlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = SolarCollectorPlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "SolarCollectorPlaceable");
27
28 self.headNode = 0;
29 self.incomePerHour = 0;
30 self.headRotationRandom = 0;
31 return self;
32end;

delete

Description
Deleting solar collector
Definition
delete()
Code
36function SolarCollectorPlaceable:delete()
37 unregisterObjectClassName(self);
38 g_currentMission.environment:removeHourChangeListener(self);
39 SolarCollectorPlaceable:superClass().delete(self);
40end;

deleteFinal

Description
Deleting placeable solar collector final
Definition
deleteFinal()
Code
44function SolarCollectorPlaceable:deleteFinal()
45 SolarCollectorPlaceable:superClass().deleteFinal(self);
46end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
52function SolarCollectorPlaceable:readStream(streamId, connection)
53 if connection:getIsServer() then
54 self.headRotationRandom=NetworkUtil.readCompressedAngle(streamId);
55 end;
56 SolarCollectorPlaceable:superClass().readStream(self, streamId, connection);
57end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
63function SolarCollectorPlaceable:writeStream(streamId, connection)
64 if not connection:getIsServer() then
65 NetworkUtil.writeCompressedAngle(streamId, self.headRotationRandom);
66 end;
67 SolarCollectorPlaceable:superClass().writeStream(self, streamId, connection);
68end;

createNode

Description
Create node
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleansuccesssuccess
Code
82function SolarCollectorPlaceable:createNode(i3dFilename)
83 if not SolarCollectorPlaceable:superClass().createNode(self, i3dFilename) then
84 return false;
85 end;
86
87 if getNumOfChildren(self.nodeId) < 1 then
88 delete(self.nodeId);
89 self.nodeId = 0;
90 return false;
91 end;
92 self.headNode = getChildAt(self.nodeId, 0);
93
94 return true;
95end;

load

Description
Load solar collector
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
108function SolarCollectorPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
109 if not SolarCollectorPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
110 return false;
111 end;
112
113 return true;
114end;

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
118function SolarCollectorPlaceable:finalizePlacement()
119 SolarCollectorPlaceable:superClass().finalizePlacement(self);
120 g_currentMission.environment:addHourChangeListener(self);
121end

initPose

Description
Initialize pose
Definition
initPose(float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
floatxx world position
floatyy world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Code
132function SolarCollectorPlaceable:initPose(x,y,z, rx,ry,rz, initRandom)
133 SolarCollectorPlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom);
134
135 local rotVariation = 0.1;
136 self.headRotationRandom = math.rad(75-90) + math.random() * 2*rotVariation - rotVariation; -- 75-90 = rotate to light (75 y rot) x axis
137
138 self:updateHeadRotation();
139end;

updateHeadRotation

Description
Updates the rotation of the head
Definition
updateHeadRotation()
Code
143function SolarCollectorPlaceable:updateHeadRotation()
144
145 local headRotation = math.rad(75-90);
146 if g_currentMission.environment.sunLightId ~= nil then
147 local dx,_,dz = localDirectionToWorld(g_currentMission.environment.sunLightId, 0,0,1);
148 headRotation = math.atan2(dx, dz);
149 end
150 headRotation = headRotation + self.headRotationRandom;
151
152 local dx,_,dz = worldDirectionToLocal(self.nodeId, math.sin(headRotation),0,math.cos(headRotation));
153 setDirection(self.headNode, dx,0,dz, 0,1,0);
154end;

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
162function SolarCollectorPlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
163 local headRotationRandom = getXMLFloat(xmlFile, key.."#headRotationRandom");
164 if headRotationRandom == nil then
165 return false;
166 end;
167
168 self.headRotationRandom = headRotationRandom;
169
170 if not SolarCollectorPlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
171 return false;
172 end;
173
174 return true;
175end;

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
188function SolarCollectorPlaceable:hourChanged()
189 if self.isServer then
190 g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), "propertyIncome");
191 g_currentMission:addMoneyChange(self.incomePerHour, self:getOwnerFarmId(), EconomyManager.MONEY_TYPE_PROPERTY_INCOME);
192 end
193 self:updateHeadRotation();
194end

WindTurbinePlaceable

Description
Class for placeable wind turbines
Parent
Placeable

new

Description
Creating placeable wind turbine
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
18function WindTurbinePlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = WindTurbinePlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, "WindTurbinePlaceable");
27
28 self.rotationNode = 0;
29 self.headNode = 0;
30 self.incomePerHour = 0;
31 return self;
32end;

delete

Description
Deleting placeable wind turbine
Definition
delete()
Code
36function WindTurbinePlaceable:delete()
37 unregisterObjectClassName(self);
38 g_currentMission.environment:removeHourChangeListener(self);
39 WindTurbinePlaceable:superClass().delete(self);
40end;

deleteFinal

Description
Deleting placeable wind turbine
Definition
deleteFinal()
Code
44function WindTurbinePlaceable:deleteFinal()
45 WindTurbinePlaceable:superClass().deleteFinal(self);
46end;

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
52function WindTurbinePlaceable:readStream(streamId, connection)
53 if connection:getIsServer() then
54 self.headRotation=NetworkUtil.readCompressedAngle(streamId);
55 end;
56 WindTurbinePlaceable:superClass().readStream(self, streamId, connection);
57end;

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
63function WindTurbinePlaceable:writeStream(streamId, connection)
64 if not connection:getIsServer() then
65 NetworkUtil.writeCompressedAngle(streamId, self.headRotation);
66 end;
67 WindTurbinePlaceable:superClass().writeStream(self, streamId, connection);
68end;

createNode

Description
Create node
Definition
createNode(string i3dFilename)
Arguments
stringi3dFilenamei3d file name
Return Values
booleansuccesssuccess
Code
82function WindTurbinePlaceable:createNode(i3dFilename)
83 if not WindTurbinePlaceable:superClass().createNode(self, i3dFilename) then
84 return false;
85 end;
86
87 if getNumOfChildren(self.nodeId) < 1 then
88 delete(self.nodeId);
89 self.nodeId = 0;
90 return false;
91 end;
92 self.headNode = getChildAt(self.nodeId, 0);
93 if getNumOfChildren(self.headNode) < 1 then
94 delete(self.nodeId);
95 self.nodeId = 0;
96 return false;
97 end;
98 self.rotationNode = getChildAt(self.headNode, 0);
99
100 return true;
101end;

load

Description
Load wind turbine
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
114function WindTurbinePlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
115 if not WindTurbinePlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
116 return false;
117 end;
118
119 return true;
120end;

finalizePlacement

Description
Called if placeable is placed
Definition
finalizePlacement()
Code
124function WindTurbinePlaceable:finalizePlacement()
125 WindTurbinePlaceable:superClass().finalizePlacement(self);
126 g_currentMission.environment:addHourChangeListener(self);
127end

initPose

Description
Initialize pose
Definition
initPose(float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
floatxx world position
floatyy world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Code
138function WindTurbinePlaceable:initPose(x,y,z, rx,ry,rz, initRandom)
139 WindTurbinePlaceable:superClass().initPose(self, x,y,z, rx,ry,rz, initRandom);
140
141 if initRandom == nil or initRandom == true then
142 local rotVariation = 0.2;
143 self.headRotation = 0.7 + math.random() * 2*rotVariation - rotVariation;
144 end;
145 rotate(self.rotationNode, 0,0,math.random()*math.pi*2);
146 self:updateHeadRotation();
147end;

updateHeadRotation

Description
Updating head rotation
Definition
updateHeadRotation()
Code
151function WindTurbinePlaceable:updateHeadRotation()
152 local dx,_,dz = worldDirectionToLocal(self.nodeId, math.sin(self.headRotation),0,math.cos(self.headRotation));
153 setDirection(self.headNode, dx,0,dz, 0,1,0);
154end;

loadFromXMLFile

Description
Loading from attributes and nodes
Definition
loadFromXMLFile(integer xmlFile, string key, boolean resetVehicles)
Arguments
integerxmlFileid of xml object
stringkeykey
booleanresetVehiclesreset vehicles
Return Values
booleansuccesssuccess
Code
162function WindTurbinePlaceable:loadFromXMLFile(xmlFile, key, resetVehicles)
163 local headRotation = getXMLFloat(xmlFile, key.."#headRotation");
164 if headRotation == nil then
165 return false;
166 end;
167
168 self.headRotation = headRotation;
169
170 if not WindTurbinePlaceable:superClass().loadFromXMLFile(self, xmlFile, key, resetVehicles) then
171 return false;
172 end;
173
174 return true;
175end;

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
186function WindTurbinePlaceable:update(dt)
187 if self.rotationNode ~= 0 then
188 rotate(self.rotationNode, 0,0,-0.0025*dt);
189 end;
190end;

hourChanged

Description
Called if hour changed
Definition
hourChanged()
Code
194function WindTurbinePlaceable:hourChanged()
195 if self.isServer then
196 g_currentMission:addMoney(self.incomePerHour, self:getOwnerFarmId(), "propertyIncome");
197 g_currentMission:addMoneyChange(self.incomePerHour, self:getOwnerFarmId(), EconomyManager.MONEY_TYPE_PROPERTY_INCOME);
198 end
199end

WoodSellStationPlaceable

Description

new

Description
Creating woodsell station
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
26function WoodSellStationPlaceable:new(isServer, isClient, customMt)
27 local self = Placeable:new(isServer, isClient, customMt or WoodSellStationPlaceable_mt)
28
29 registerObjectClassName(self, "WoodSellStationPlaceable")
30
31 self.woodInTrigger = {}
32
33 return self
34end

delete

Description
Deleting trigger
Definition
delete()
Code
38function WoodSellStationPlaceable:delete()
39 if self.mapHotspot ~= nil then
40 g_currentMission:removeMapHotspot(self.mapHotspot)
41 self.mapHotspot:delete()
42 end
43
44 if self.woodSellTrigger ~= nil then
45 removeTrigger(self.woodSellTrigger)
46 self.woodSellTrigger = nil
47 end
48
49 if self.sellTrigger ~= nil then
50 g_currentMission:removeActivatableObject(self)
51 removeTrigger(self.sellTrigger)
52 self.sellTrigger = nil
53 end
54
55 unregisterObjectClassName(self)
56 WoodSellStationPlaceable:superClass().delete(self)
57end

load

Description
Load woodsell station
Definition
load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)
Arguments
stringxmlFilenamexml file name
floatxx world position
floatyz world position
floatzz world position
floatrxrx world rotation
floatryry world rotation
floatrzrz world rotation
booleaninitRandominitialize random
Return Values
booleansuccesssuccess
Code
70function WoodSellStationPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
71 if not WoodSellStationPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
72 return false
73 end
74
75 local xmlFile = loadXMLFile("TempXML", xmlFilename)
76
77 self.appearsOnPDA = Utils.getNoNil(getXMLBool(xmlFile, "placeable.woodSellStation#appearsOnPDA"), false)
78 local rawName = Utils.getNoNil(getXMLString(xmlFile, "placeable.woodSellStation#stationName"), "WoodSellStation")
79 self.stationName = g_i18n:convertText(rawName) -- returns input if it cannot be resolved
80
81 local woodSellTrigger = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.woodSellStation#triggerNode"))
82 if woodSellTrigger == nil then
83 g_logManager:xmlWarning(xmlFilename, "Missing wood trigger node in 'placeable.woodSellStation#triggerNode'!")
84 delete(xmlFile)
85 return false
86 end
87
88 local colMask = getCollisionMask(woodSellTrigger)
89 if bitAND(SplitTypeManager.COLLISIONMASK_TRIGGER, colMask) == 0 then
90 g_logManager:xmlWarning(xmlFilename, "Invalid collision mask for wood trigger 'placeable.woodSellStation#triggerNode'. Bit 24 needs to be set!")
91 delete(xmlFile)
92 return false
93 end
94
95 addTrigger(woodSellTrigger, "woodTriggerCallback", self)
96 self.woodSellTrigger = woodSellTrigger
97
98
99 local sellTrigger = I3DUtil.indexToObject(self.nodeId, getXMLString(xmlFile, "placeable.woodSellStation#sellTrigger"))
100 if sellTrigger == nil then
101 g_logManager:xmlWarning(xmlFilename, "Missing sell trigger in 'placeable.woodSellStation#sellTrigger'!")
102 delete(xmlFile)
103 return false
104 end
105
106 colMask = getCollisionMask(sellTrigger)
107 if bitAND(Player.COLLISIONMASK_TRIGGER, colMask) == 0 then
108 g_logManager:xmlWarning(xmlFilename, "Invalid collision mask for sell trigger 'placeable.woodSellStation#triggerNode'. Bit 20 needs to be set!")
109 delete(xmlFile)
110 return false
111 end
112
113 if self.appearsOnPDA then
114 local mapPosition = self.woodSellTrigger
115 local mapPositionIndex = getUserAttribute(self.woodSellTrigger, "mapPositionIndex")
116 if mapPositionIndex ~= nil then
117 mapPosition = I3DUtil.indexToObject(self.woodSellTrigger, mapPositionIndex)
118 if mapPosition == nil then
119 mapPosition = self.woodSellTrigger
120 end
121 end
122 local filenames = nil
123 local imageUVs = getNormalizedUVs(MapHotspot.UV.SELLING_POINT)
124 local x, _, z = getWorldTranslation(mapPosition)
125
126 local hotspotTextOffset = Utils.getNoNil(getXMLString(xmlFile, "placeable.woodSellStation#hotspotTextOffset"), "0px 0px")
127
128 self.mapHotspot = MapHotspot:new("woodSellStation", MapHotspot.CATEGORY_TRIGGER)
129 self.mapHotspot:setText(self.stationName)
130 self.mapHotspot:setBorderedImage(nil, imageUVs, {0.9559, 0.5647, 0.0423, 1})
131 self.mapHotspot:setWorldPosition(x, z)
132 self.mapHotspot:setRawTextOffset(hotspotTextOffset)
133
134 g_currentMission:addMapHotspot(self.mapHotspot)
135 end
136
137 addTrigger(sellTrigger, "woodSellTriggerCallback", self)
138 self.sellTrigger = sellTrigger
139
140 self.activateText = g_i18n:getText("action_sellWood")
141 self.objectActivated = false
142
143 self.updateEventListeners = {}
144
145 delete(xmlFile)
146
147 return true
148end

addUpdateEventListener

Description
Add listener to update listeners
Definition
addUpdateEventListener()
Code
205function WoodSellStationPlaceable:addUpdateEventListener(listener)
206 if listener ~= nil then
207 self.updateEventListeners[listener] = listener
208 end
209end

removeUpdateEventListener

Description
Remove listener from update listeners
Definition
removeUpdateEventListener()
Code
213function WoodSellStationPlaceable:removeUpdateEventListener(listener)
214 if listener ~= nil then
215 self.updateEventListeners[listener] = nil
216 end
217end

getIsActivatable

Description
Returns true if wood can be sold
Definition
getIsActivatable()
Return Values
booleanisActivateableis activateable
Code
275function WoodSellStationPlaceable:getIsActivatable()
276 return g_currentMission.controlPlayer
277end

onActivateObject

Description
Called on activate object
Definition
onActivateObject()
Code
285function WoodSellStationPlaceable:onActivateObject()
286 g_currentMission:addActivatableObject(self)
287 self.objectActivated = true
288 self:sellWood(g_currentMission:getFarmId())
289end

BasketTrigger

Description
Class for basket triggers

onCreate

Description
On create basket trigger
Definition
onCreate(integer id)
Arguments
integeridid of trigger node
Code
17function BasketTrigger:onCreate(id)
18 local trigger = BasketTrigger:new();
19 if trigger:load(id) then
20 g_currentMission:addNonUpdateable(trigger);
21 else
22 trigger:delete();
23 end
24end;

new

Description
Creating basket trigger object
Definition
new(table mt)
Arguments
tablemtcustom metatable (optional)
Return Values
tableinstanceinstance of basket trigger object
Code
30function BasketTrigger:new(mt)
31 local self = {};
32 if mt == nil then
33 mt = BasketTrigger_mt;
34 end
35 setmetatable(self, mt);
36
37 self.triggerId = 0;
38 self.nodeId = 0;
39
40 return self;
41end;

load

Description
Load basket trigger
Definition
load(integer nodeId)
Arguments
integernodeIdid of node
Return Values
booleansuccesssuccess
Code
47function BasketTrigger:load(nodeId)
48 self.nodeId = nodeId;
49
50 self.triggerId = I3DUtil.indexToObject(nodeId, getUserAttribute(nodeId, "triggerIndex"));
51 if self.triggerId == nil then
52 self.triggerId = nodeId;
53 end
54 addTrigger(self.triggerId, "triggerCallback", self);
55
56 self.triggerObjects = {};
57
58 self.isEnabled = true;
59
60 return true;
61end;

delete

Description
Delete basket trigger
Definition
delete()
Code
65function BasketTrigger:delete()
66 removeTrigger(self.triggerId);
67end;

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
76function BasketTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
77 if self.isEnabled then
78
79 if onEnter then
80 local object = g_currentMission:getNodeObject(otherActorId);
81 if object.thrownFromPosition ~= nil then
82 self.triggerObjects[otherActorId] = true;
83 end
84
85 elseif onLeave then
86 if self.triggerObjects[otherActorId] then
87 self.triggerObjects[otherActorId] = false;
88
89 local object = g_currentMission:getNodeObject(otherActorId);
90 local x,y,z = worldToLocal(self.triggerId, object.thrownFromPosition[1],object.thrownFromPosition[2],object.thrownFromPosition[3]);
91 local dist = MathUtil.vector3Length(x,y,z);
92 end
93 end;
94 end;
95end;

FillPlane

Description

new

Description
Creates a new instance of the class
Definition
new(table customMt)
Arguments
tablecustomMtmeta table
Return Values
tableselfreturns the instance
Code
23function FillPlane:new(customMt)
24 if customMt == nil then
25 customMt = FillPlane_mt
26 end
27 local self = {}
28 setmetatable(self, customMt)
29
30 self:initDataStructures()
31
32 return self
33end

delete

Description
Destructor
Definition
delete()
Code
37function FillPlane:delete()
38end

initDataStructures

Description
Init class members
Definition
initDataStructures()
Code
42function FillPlane:initDataStructures()
43 self.node = nil
44 self.maxCapacity = 0
45 self.moveMinY = 0
46 self.moveMaxY = 0
47 self.loaded = false
48 self.colorChange = false
49end

load

Description
Loads fill plane
Definition
load(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
56function FillPlane:load(rootNode, xmlFile, xmlNode)
57 local fillPlaneNodeStr = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "node", getXMLString, rootNode)
58
59 if fillPlaneNodeStr ~= nil then
60 local fillPlaneNode = I3DUtil.indexToObject(rootNode, fillPlaneNodeStr)
61
62 if fillPlaneNode ~= nil then
63 self.node = fillPlaneNode
64 self.moveMinY = Utils.getNoNil(XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "minY", getXMLFloat, rootNode), 0)
65 self.moveMaxY = Utils.getNoNil(XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "maxY", getXMLFloat, rootNode), 0)
66 self.colorChange = Utils.getNoNil(XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "colorChange", getXMLBool, rootNode), false)
67 assert(self.moveMinY <= self.moveMaxY)
68 self.loaded = self.node ~= nil
69 local x, _, z = getTranslation(self.node)
70 setTranslation(self.node, x, self.moveMinY, z)
71 end
72 end
73end

setState

Description
Changes fill levels visuals
Definition
setState(table instance)
Arguments
tableinstancetarget to check fillLevel
Return Values
booltrueif level has changed
Code
79function FillPlane:setState(state)
80 if self.loaded then
81 local delta = self.moveMaxY - self.moveMinY
82 local y = math.min(self.moveMinY + delta * state, self.moveMaxY)
83 local x, oldY, z = getTranslation(self.node)
84 setTranslation(self.node, x, y, z)
85
86 return oldY ~= y
87 end
88
89 return false
90end

setColorScale

Description
Sets fill plane color shader
Definition
setColorScale(float[] a)
Arguments
float[]afloat array for r, g, b
Code
95function FillPlane:setColorScale(colorScale)
96 if self.loaded then
97 setShaderParameter(self.node, "colorScale", colorScale[1], colorScale[2], colorScale[3], 0, false)
98 end
99end

FillTrigger

Description
Class for fill triggers

onCreate

Description
On create fill trigger
Definition
onCreate(integer id)
Arguments
integeridid of trigger node
Code
13function FillTrigger:onCreate(id)
14 g_currentMission:addNonUpdateable(FillTrigger:new(id))
15end

new

Description
Create fill trigger object
Definition
new(integer id, table sourceObject, integer fillUnitIndex, table customMt)
Arguments
integeridid of trigger node
tablesourceObjectsourceObject
integerfillUnitIndexfillUnitIndex
tablecustomMtcustom metatable (optional)
Return Values
tableinstanceinstance of gas station trigger
Code
24function FillTrigger:new(id, sourceObject, fillUnitIndex, fillLitersPerSecond, defaultFillType, customMt)
25 local self = {}
26 setmetatable(self, customMt or FillTrigger_mt)
27
28 self.customEnvironment = g_currentMission.loadingMapModName
29
30 self.triggerId = id
31 addTrigger(id, "fillTriggerCallback", self)
32
33 -- place sound at the same position as the trigger
34 self.soundNode = createTransformGroup("fillTriggerSoundNode")
35 link(getParent(id), self.soundNode)
36 setTranslation(self.soundNode, getTranslation(id))
37
38 self.sourceObject = sourceObject
39 self.vehiclesTriggerCount = {}
40 self.fillUnitIndex = fillUnitIndex
41 self.fillLitersPerSecond = fillLitersPerSecond
42 self.appearsOnPDA = Utils.getNoNil(getUserAttribute(id, "appearsOnPDA"), true)
43 self.isEnabled = true
44
45 self.fillTypeIndex = FillType.DIESEL
46
47 if self.appearsOnPDA and sourceObject == nil then
48 local mapPosition = id
49 local mapPositionIndex = getUserAttribute(id, "mapPositionIndex")
50 if mapPositionIndex ~= nil then
51 mapPosition = I3DUtil.indexToObject(id, mapPositionIndex)
52 if mapPosition == nil then
53 mapPosition = id
54 end
55 end
56
57 local x, _, z = getWorldTranslation(mapPosition)
58
59 local fullViewName = Utils.getNoNil(getUserAttribute(id, "stationName"), "map_fuelStation")
60 if g_i18n:hasText(fullViewName, self.customEnvironment) then
61 fullViewName = g_i18n:getText(fullViewName, self.customEnvironment)
62 end
63
64 self.mapHotspot = MapHotspot:new("fuelStation", MapHotspot.CATEGORY_DEFAULT)
65 self.mapHotspot:setText(fullViewName)
66 self.mapHotspot:setWorldPosition(x, z)
67 self.mapHotspot:setBorderedImage(nil, getNormalizedUVs(MapHotspot.UV.GAS_STATION))
68
69 g_currentMission:addMapHotspot(self.mapHotspot)
70 end
71
72 self.moneyChangeId = getMoneyTypeId()
73
74 return self
75end

delete

Description
Delete fill trigger
Definition
delete()
Code
79function FillTrigger:delete()
80 -- remove the gas stations from all vehicles that are triggered by this trigger
81 for vehicle,count in pairs(self.vehiclesTriggerCount) do
82 if count > 0 then
83 if vehicle.removeFillUnitTrigger ~= nil then
84 vehicle:removeFillUnitTrigger(self)
85 end
86 end
87 end
88
89 if self.mapHotspot ~= nil then
90 g_currentMission:removeMapHotspot(self.mapHotspot)
91 self.mapHotspot:delete()
92 end
93
94 g_soundManager:deleteSample(self.sample)
95
96 removeTrigger(self.triggerId)
97end

onVehicleDeleted

Description
Called if vehicle gets out of trigger
Definition
onVehicleDeleted(table vehicle)
Arguments
tablevehiclevehicle
Code
102function FillTrigger:onVehicleDeleted(vehicle)
103 self.vehiclesTriggerCount[vehicle] = nil
104 g_currentMission:showMoneyChange(self.moneyChangeId, g_i18n:getText("finance_purchaseFuel"))
105end

fillVehicle

Description
Fill vehicle
Definition
fillVehicle(table vehicle, float delta)
Arguments
tablevehiclevehicle to fill
floatdeltadelta
Return Values
floatdeltareal delta
Code
112function FillTrigger:fillVehicle(vehicle, delta, dt)
113 if self.fillLitersPerSecond ~= nil then
114 delta = math.max(delta, self.fillLitersPerSecond*0.001*dt)
115 end
116
117 local farmId = vehicle:getActiveFarm()
118
119 if self.sourceObject ~= nil then
120 local sourceFuelFillLevel = self.sourceObject:getFillUnitFillLevel(self.fillUnitIndex)
121 if sourceFuelFillLevel > 0 and g_currentMission.accessHandler:canFarmAccess(farmId, self.sourceObject) then
122 delta = math.min(delta, sourceFuelFillLevel)
123 if delta <= 0 then
124 return 0
125 end
126 else
127 return 0
128 end
129 end
130
131 local fillType = self:getCurrentFillType()
132
133 local fillUnitIndex = vehicle:getFirstValidFillUnitToFill(fillType)
134 if fillUnitIndex == nil then
135 return 0
136 end
137
138 delta = vehicle:addFillUnitFillLevel(farmId, fillUnitIndex, delta, fillType, ToolType.TRIGGER, nil)
139
140 if delta > 0 then
141 if self.sourceObject ~= nil then
142 self.sourceObject:addFillUnitFillLevel(farmId, self.fillUnitIndex, -delta, fillType, ToolType.TRIGGER, nil)
143 else
144 local price = delta * g_currentMission.economyManager:getPricePerLiter(fillType)
145 g_farmManager:getFarmById(farmId).stats:updateStats("expenses", price)
146
147 local userId = g_currentMission:getServerUserId()
148 local user = g_currentMission:getUserByConnection(vehicle:getOwner())
149 if user ~= nil then
150 userId = user.userId
151 end
152
153 g_currentMission:addMoney(-price, farmId, "purchaseFuel")
154 g_currentMission:addMoneyChange(-price, farmId, self.moneyChangeId)
155 end
156 end
157
158 return delta
159end

getIsActivatable

Description
Returns true if is activateable
Definition
getIsActivatable(table vehicle)
Arguments
tablevehiclevehicle
Return Values
booleanisActivateableis activateable
Code
165function FillTrigger:getIsActivatable(vehicle)
166 if self.sourceObject ~= nil then
167 if self.sourceObject:getFillUnitFillLevel(self.fillUnitIndex) > 0 and g_currentMission.accessHandler:canFarmAccess(vehicle:getActiveFarm(), self.sourceObject) then
168 return true
169 end
170 end
171
172 return false
173end

fillTriggerCallback

Description
Trigger callback
Definition
fillTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
182function FillTrigger:fillTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
183 if self.isEnabled and (onEnter or onLeave) then
184 local vehicle = g_currentMission:getNodeObject(otherId)
185 if vehicle ~= nil and vehicle.addFillUnitTrigger ~= nil and vehicle.removeFillUnitTrigger ~= nil and vehicle ~= self and vehicle ~= self.sourceObject then
186 local count = Utils.getNoNil(self.vehiclesTriggerCount[vehicle], 0)
187 if onEnter then
188 local fillType = self:getCurrentFillType()
189 local fillUnitIndex = vehicle:getFirstValidFillUnitToFill(fillType)
190 if fillUnitIndex ~= nil then
191 self.vehiclesTriggerCount[vehicle] = count + 1
192
193 if count == 0 then
194 vehicle:addFillUnitTrigger(self, fillType, fillUnitIndex)
195 end
196 end
197 else
198 self.vehiclesTriggerCount[vehicle] = count - 1
199 if count <= 1 then
200 self.vehiclesTriggerCount[vehicle] = nil
201 vehicle:removeFillUnitTrigger(self)
202 g_currentMission:showMoneyChange(self.moneyChangeId, g_i18n:getText("finance_purchaseFuel"))
203 end
204 end
205 end
206 end
207end

InsideBuildingTrigger

Description
Class for InsideBuildingTriggers

onCreate

Description
On create InsideBuildingTrigger
Definition
onCreate(integer id)
Arguments
integeridid of trigger node
Code
15function InsideBuildingTrigger.onCreate(_, id)
16 local trigger = InsideBuildingTrigger:new()
17 if trigger:load(id) then
18 g_currentMission:addNonUpdateable(trigger)
19 else
20 trigger:delete()
21 end
22end

new

Description
Creating InsideBuildingTrigger object
Definition
new(table customMt)
Arguments
tablecustomMtcustom metatable (optional)
Return Values
tableinstanceinstance of basket trigger object
Code
28function InsideBuildingTrigger:new(customMt)
29 local self = {}
30 setmetatable(self, customMt or InsideBuildingTrigger_mt)
31
32 self.triggerId = 0
33 self.nodeId = 0
34
35 return self
36end

load

Description
Load InsideBuildingTrigger
Definition
load(integer nodeId)
Arguments
integernodeIdid of node
Return Values
booleansuccesssuccess
Code
42function InsideBuildingTrigger:load(nodeId)
43 self.nodeId = nodeId
44
45 self.triggerId = I3DUtil.indexToObject(nodeId, getUserAttribute(nodeId, "triggerIndex"))
46 if self.triggerId == nil then
47 self.triggerId = nodeId
48 end
49 addTrigger(self.triggerId, "insideBuildingTriggerCallback", self)
50
51 self.isEnabled = true
52
53 return true
54end

delete

Description
Delete InsideBuildingTrigger
Definition
delete()
Code
58function InsideBuildingTrigger:delete()
59 removeTrigger(self.triggerId)
60end

insideBuildingTriggerCallback

Description
Trigger callback
Definition
insideBuildingTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
69function InsideBuildingTrigger:insideBuildingTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
70 -- log(g_currentMission.player.rootNode, triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
71 if g_currentMission.player ~= nil and g_currentMission.player.rootNode == otherActorId then
72 if self.isEnabled then
73 if onEnter then
74 g_currentMission:setIsInsideBuilding(true)
75 elseif onLeave then
76 g_currentMission:setIsInsideBuilding(false)
77 end
78 end
79 end
80end

LoadTrigger

Description

farmIdForFillableObject

Description
Get the farm id for given object. If none can be found, SPECTATOR is used.
Definition
farmIdForFillableObject()

LoanTrigger

Description
Class for loan triggers

onCreate

Description
On create loan trigger
Definition
onCreate(integer id)
Arguments
integeridid of trigger node
Code
15function LoanTrigger:onCreate(id)
16 g_currentMission:addNonUpdateable(LoanTrigger:new(id))
17end

new

Description
Create loan trigger object
Definition
new(integer name)
Arguments
integernameid of trigger node
Return Values
tableinstanceinstance
Code
23function LoanTrigger:new(name)
24 local self = {}
25 setmetatable(self, LoanTrigger_mt)
26
27 if g_currentMission:getIsClient() then
28 self.triggerId = name
29 addTrigger(name, "triggerCallback", self)
30 end
31
32 self.loanSymbol = getChildAt(name, 0)
33
34 self.activateText = g_i18n:getText("action_checkFinances")
35
36 self.isEnabled = true
37 self.objectActivated = false
38
39 g_messageCenter:subscribe(MessageType.PLAYER_FARM_CHANGED, self.playerFarmChanged, self)
40
41 self:updateIconVisibility()
42
43 return self
44end

delete

Description
Delete loan trigger
Definition
delete()
Code
48function LoanTrigger:delete()
49 g_messageCenter:unsubscribeAll(self)
50
51 if self.triggerId ~= nil then
52 removeTrigger(self.triggerId)
53 end
54 self.loanSymbol = nil
55 g_currentMission:removeActivatableObject(self)
56end

getIsActivatable

Description
Returns true if is activateable
Definition
getIsActivatable()
Return Values
booleanisActivateableis activateable
Code
61function LoanTrigger:getIsActivatable()
62 return self.isEnabled and g_currentMission.controlPlayer and g_currentMission:getFarmId() ~= FarmManager.SPECTATOR_FARM_ID
63end

onActivateObject

Description
Called on activate object
Definition
onActivateObject()
Code
71function LoanTrigger:onActivateObject()
72 g_gui:showGui("InGameMenu")
73 g_messageCenter:publish(MessageType.GUI_INGAME_OPEN_FINANCES_SCREEN)
74
75 g_currentMission:addActivatableObject(self)
76 self.objectActivated = true
77end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
86function LoanTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
87 if self.isEnabled and (not g_isPresentationVersion or g_isPresentationVersionShopEnabled) and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then
88 if onEnter or onLeave then
89 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
90 if onEnter then
91 if not self.objectActivated then
92 g_currentMission:addActivatableObject(self)
93 self.objectActivated = true
94 end
95 else
96 if self.objectActivated then
97 g_currentMission:removeActivatableObject(self)
98 self.objectActivated = false
99 end
100 end
101 end
102 end
103 end
104end

updateIconVisibility

Description
Turn the icon on or off depending on the current game and the players farm
Definition
updateIconVisibility()

RainDropFactorTrigger

Description
Class for RainDropFactorTriggers

onCreate

Description
On create RainDropFactorTrigger
Definition
onCreate(integer id)
Arguments
integeridid of trigger node
Code
15function RainDropFactorTrigger:onCreate(id)
16 local trigger = RainDropFactorTrigger:new();
17 if trigger:load(id) then
18 g_currentMission:addNonUpdateable(trigger);
19 else
20 trigger:delete();
21 end
22end;

new

Description
Creating RainDropFactorTrigger object
Definition
new(table mt)
Arguments
tablemtcustom metatable (optional)
Return Values
tableinstanceinstance of basket trigger object
Code
28function RainDropFactorTrigger:new(mt)
29 local self = {};
30 if mt == nil then
31 mt = RainDropFactorTrigger_mt;
32 end
33 setmetatable(self, mt);
34
35 self.triggerId = 0;
36 self.nodeId = 0;
37
38 return self;
39end;

load

Description
Load RainDropFactorTrigger
Definition
load(integer nodeId)
Arguments
integernodeIdid of node
Return Values
booleansuccesssuccess
Code
45function RainDropFactorTrigger:load(nodeId)
46 self.nodeId = nodeId;
47
48 self.triggerId = I3DUtil.indexToObject(nodeId, getUserAttribute(nodeId, "triggerIndex"));
49 if self.triggerId == nil then
50 self.triggerId = nodeId;
51 end
52 addTrigger(self.triggerId, "triggerCallback", self);
53
54 self.triggerObjects = {};
55
56 self.isEnabled = true;
57
58 return true;
59end;

delete

Description
Delete RainDropFactorTrigger
Definition
delete()
Code
63function RainDropFactorTrigger:delete()
64 removeTrigger(self.triggerId);
65end;

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
74function RainDropFactorTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
75 if self.isEnabled then
76 if onEnter then
77 if g_currentMission.environment ~= nil then
78-- g_currentMission.environment.globalRainDropFactor = 0.0;
79 end
80 elseif onLeave then
81 if g_currentMission.environment ~= nil then
82-- g_currentMission.environment.globalRainDropFactor = 1.0;
83 end
84 end;
85 end;
86end;

ShopTrigger

Description
Class for shop triggers to open shop gui

onCreate

Description
On create shop trigger
Definition
onCreate(integer id)
Arguments
integeridtrigger node id
Code
15function ShopTrigger:onCreate(id)
16 g_currentMission:addNonUpdateable(ShopTrigger:new(id))
17end

new

Description
Creating shop trigger object
Definition
new(integer name)
Arguments
integernametrigger node id
Return Values
tableinstanceinstance of object
Code
23function ShopTrigger:new(name)
24 local self = {}
25 setmetatable(self, ShopTrigger_mt)
26
27 if g_currentMission:getIsClient() then
28 self.triggerId = name
29 addTrigger(name, "triggerCallback", self)
30 end
31
32 self.shopSymbol = getChildAt(name, 0)
33 self.shopPlayerSpawn = getChildAt(name, 1)
34
35 self.objectActivated = false
36 self.isEnabled = true
37
38 g_messageCenter:subscribe(MessageType.PLAYER_FARM_CHANGED, self.playerFarmChanged, self)
39
40 self:updateIconVisibility()
41
42 self.activateText = g_i18n:getText("action_activateShop")
43
44 return self
45end

delete

Description
Deleting shop trigger
Definition
delete()
Code
49function ShopTrigger:delete()
50 g_messageCenter:unsubscribeAll(self)
51 if self.triggerId ~= nil then
52 removeTrigger(self.triggerId)
53 end
54 self.shopSymbol = nil
55 g_currentMission:removeActivatableObject(self)
56end

getIsActivatable

Description
Returns true if shop can be opened
Definition
getIsActivatable()
Return Values
booleanisActivateableis activateable
Code
61function ShopTrigger:getIsActivatable()
62 return self.isEnabled and g_currentMission.controlPlayer and g_currentMission:getFarmId() ~= FarmManager.SPECTATOR_FARM_ID
63end

onActivateObject

Description
Called on activate object
Definition
onActivateObject()
Code
71function ShopTrigger:onActivateObject()
72 g_currentMission:addActivatableObject(self)
73 self.objectActivated = true
74
75 local inGameMenu = g_gui:getScreenInstanceByClass(InGameMenu)
76 inGameMenu:setMode(InGameMenu.MODE_SHOP)
77 g_gui:changeScreen(nil, InGameMenu)
78
79 local x,y,z = getWorldTranslation(self.shopPlayerSpawn)
80 local dx, _, dz = localDirectionToWorld(self.shopPlayerSpawn, 0, 0, -1)
81 g_currentMission.player:moveToAbsolute(x,y,z)
82 g_currentMission.player.rotY = MathUtil.getYRotationFromDirection(dx, dz)
83end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
92function ShopTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
93 if self.isEnabled and (not g_isPresentationVersion or g_isPresentationVersionShopEnabled) and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then
94 if onEnter or onLeave then
95 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
96 if onEnter then
97 if not self.objectActivated then
98 g_currentMission:addActivatableObject(self)
99 self.objectActivated = true
100 end
101 else
102 if self.objectActivated then
103 g_currentMission:removeActivatableObject(self)
104 self.objectActivated = false
105 end
106 end
107 end
108 end
109 end
110end

updateIconVisibility

Description
Turn the icon on or off depending on the current game and the players farm
Definition
updateIconVisibility()

TransportMissionTrigger

Description
Class for transport mission triggers

onCreate

Description
On create mission trigger
Definition
onCreate(integer id)
Arguments
integeridtrigger node id
Code
19function TransportMissionTrigger:onCreate(id)
20 g_currentMission:addNonUpdateable(TransportMissionTrigger:new(id))
21end

new

Description
Creating mission trigger object
Definition
new(integer name)
Arguments
integernametrigger node id
Return Values
tableinstanceinstance of object
Code
27function TransportMissionTrigger:new(id)
28 local self = {}
29 setmetatable(self, TransportMissionTrigger_mt)
30
31 self.triggerId = id
32 self.index = getUserAttribute(self.triggerId, "index")
33
34 addTrigger(id, "triggerCallback", self)
35
36 self.isEnabled = true
37
38 g_missionManager:addTransportMissionTrigger(self)
39
40 -- Hide until needed
41 self:setMission(nil)
42
43 return self
44end

delete

Description
Deleting shop trigger
Definition
delete()
Code
48function TransportMissionTrigger:delete()
49 removeTrigger(self.triggerId)
50
51 g_missionManager:removeTransportMissionTrigger(self)
52end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
72function TransportMissionTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
73 if self.isEnabled and self.mission ~= nil then
74 if onEnter then
75 self.mission:objectEnteredTrigger(self, otherId)
76 elseif onLeave then
77 self.mission:objectLeftTrigger(self, otherId)
78 end
79 end
80end

UnloadFeedingTrough

Description

new

Description
Creates a new instance of the class
Definition
new(bool isServer, bool isClient, table customMt)
Arguments
boolisServertrue if we are server
boolisClienttrue if we are client
tablecustomMtmeta table
Return Values
tableselfreturns the instance
Code
25function UnloadFeedingTrough:new(isServer, isClient, customMt)
26 local self = UnloadTrigger:new(isServer, isClient, customMt or UnloadFeedingTrough_mt)
27
28 self.animalPlaces = {}
29
30 return self
31end

load

Description
Loads elements of the class
Definition
load(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Return Values
boolreturntrue if successful
Code
39function UnloadFeedingTrough:load(rootNode, xmlFile, xmlNode, target)
40 local returnValue = UnloadFeedingTrough:superClass().load(self, rootNode, xmlFile, xmlNode, target)
41
42 if returnValue then
43 self:loadAnimalPlaces(rootNode, xmlFile, xmlNode)
44 end
45 return returnValue
46end

loadAnimalPlaces

Description
Loads animal places
Definition
loadAnimalPlaces(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
53function UnloadFeedingTrough:loadAnimalPlaces(rootNode, xmlFile, xmlNode)
54 -- print(string.format("-- [UnloadFeedingTrough:loadAnimalPlaces] rootNode(%s) xmlFile(%s) xmlNode(%s)", tostring(rootNode), tostring(xmlFile), tostring(xmlNode)))
55 local animalPlacesNode = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "animalPlacesNode", getXMLString, rootNode)
56 if animalPlacesNode ~= nil then
57 local animalPlaces = I3DUtil.indexToObject(rootNode, animalPlacesNode)
58 -- print(string.format("-- [UnloadFeedingTrough:loadAnimalPlaces] animalPlacesNode(%s) animalPlaces(%s)", tostring(animalPlacesNode), tostring(animalPlaces)))
59 if animalPlaces ~= nil and self.target~= nil and self.target.husbandryId ~= nil then
60 for i = 1, getNumOfChildren(animalPlaces) do
61 local animalPlaceId = getChildAt(animalPlaces, i - 1)
62 local animalPlace = addFeedingPlace(self.target.husbandryId, animalPlaceId, 0.0)
63 table.insert(self.animalPlaces, animalPlace)
64 end
65 end
66 end
67end

loadFillTypes

Description
Overriding Unload Trigger method with empty method. The animal husbandry module is taking care of setting up the filltypes
Definition
loadFillTypes(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
74function UnloadFeedingTrough:loadFillTypes(rootNode, xmlFile, xmlNode)
75end

initFillTypesFromFoodGroups

Description
Setup fillTypes from animal food groups
Definition
initFillTypesFromFoodGroups(table foodGroups)
Arguments
tablefoodGroups
Code
81function UnloadFeedingTrough:initFillTypesFromFoodGroups(foodGroups)
82 self.fillTypes = {}
83 for _, foodGroup in pairs(foodGroups) do
84 for _, fillTypeIndex in pairs(foodGroup.fillTypes) do
85 self.fillTypes[fillTypeIndex] = true
86 end
87 end
88end

addFillUnitFillLevel

Description
Changes fill levels from a tool
Definition
addFillUnitFillLevel(float deltaFillLevel, integer fillType, table fillInfo, integer toolType)
Arguments
floatdeltaFillLevel
integerfillType
tablefillInfo
integertoolType
Return Values
floatreturnsthe change delta
Code
101function UnloadFeedingTrough:addFillUnitFillLevel(farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData)
102 local foodMixture = g_animalFoodManager:getFoodMixtureByFillType(fillTypeIndex)
103 local delta = 0
104 if foodMixture ~= nil then
105 for _, ingredient in ipairs(foodMixture.ingredients) do
106 local ingredientFillType = ingredient.fillTypes[1]
107 local ingredientFillLevel = fillLevelDelta * ingredient.weight
108 delta = delta + UnloadFeedingTrough:superClass().addFillUnitFillLevel(self, farmId, fillUnitIndex, ingredientFillLevel, ingredientFillType, toolType, fillPositionData)
109 end
110 else
111 delta = UnloadFeedingTrough:superClass().addFillUnitFillLevel(self, farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData)
112 end
113
114 self:updateAnimalPlaces(delta)
115 return delta
116end

updateAnimalPlaces

Description
Changes animal places visuals
Definition
updateAnimalPlaces()
Code
120function UnloadFeedingTrough:updateAnimalPlaces(delta)
121 if delta ~= nil and delta > 0 then
122 for _, animalPlace in pairs(self.animalPlaces) do
123 updateFeedingPlace(self.target.husbandryId, animalPlace, delta)
124 end
125 end
126end

UnloadTrigger

Description

new

Description
Creates a new instance of the class
Definition
new(bool isServer, bool isClient, table customMt)
Arguments
boolisServertrue if we are server
boolisClienttrue if we are client
tablecustomMtmeta table
Return Values
tableselfreturns the instance
Code
32function UnloadTrigger:new(isServer, isClient, customMt)
33 local self = Object:new(isServer, isClient, customMt or UnloadTrigger_mt)
34
35 self.baleTriggerNode = nil
36 self.balesInTrigger = {}
37 self.fillTypes = {}
38 self.avoidFillTypes = {}
39 self.acceptedToolTypes = {}
40
41 return self
42end

load

Description
Loads elements of the class
Definition
load(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Return Values
boolreturntrue if successful
Code
50function UnloadTrigger:load(rootNode, xmlFile, xmlNode, target)
51 self:loadBaleTrigger(rootNode, xmlFile, xmlNode)
52
53 local exactFillRootNode = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "exactFillRootNode", getXMLString, rootNode)
54 self.exactFillRootNode = I3DUtil.indexToObject(rootNode, exactFillRootNode)
55
56 if self.baleTriggerNode == nil and self.exactFillRootNode == nil then
57 g_logManager:warning("Missing exactFillRootNode or baleTrigger for unloadTrigger")
58 return false
59 end
60
61 if self.exactFillRootNode ~= nil then
62 local colMask = getCollisionMask(self.exactFillRootNode)
63 if bitAND(FillUnit.EXACTFILLROOTNODE_MASK, colMask) == 0 then
64 g_logManager:warning("Invalid exactFillRootNode collision mask for unloadTrigger. Bit 30 needs to be set!")
65 return false
66 end
67
68 g_currentMission:addNodeObject(self.exactFillRootNode, self)
69 end
70
71 if target ~= nil then
72 self:setTarget(target)
73 end
74
75 self:loadFillTypes(rootNode, xmlFile, xmlNode)
76 self:loadAcceptedToolType(rootNode, xmlFile, xmlNode)
77 self:loadAvoidFillTypes(rootNode, xmlFile, xmlNode)
78 self.isEnabled = true
79
80 return true
81end

loadAcceptedToolType

Description
Loads accepted tool type
Definition
loadAcceptedToolType(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
88function UnloadTrigger:loadAcceptedToolType(rootNode, xmlFile, xmlNode)
89 local acceptedToolTypeNames = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "acceptedToolTypes", getXMLString, rootNode)
90 local acceptedToolTypes = StringUtil.getVectorFromString(acceptedToolTypeNames)
91
92 if acceptedToolTypes ~= nil then
93 for _,acceptedToolType in pairs(acceptedToolTypes) do
94 local toolTypeInt = g_toolTypeManager:getToolTypeIndexByName(acceptedToolType)
95 self.acceptedToolTypes[toolTypeInt] = true
96 end
97 else
98 self.acceptedToolTypes = nil
99 end
100end

loadAvoidFillTypes

Description
Loads avoid fill Types
Definition
loadAvoidFillTypes(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
107function UnloadTrigger:loadAvoidFillTypes(rootNode, xmlFile, xmlNode)
108 local avoidFillTypeCategories = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "avoidFillTypeCategories", getXMLString, rootNode)
109 local avoidFillTypeNames = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "avoidFillTypes", getXMLString, rootNode)
110 local avoidFillTypes = nil
111
112 if avoidFillTypeCategories ~= nil and avoidFillTypeNames == nil then
113 avoidFillTypes = g_fillTypeManager:getFillTypesByCategoryNames(avoidFillTypeCategories, "Warning: UnloadTrigger has invalid avoidFillTypeCategory '%s'.")
114 elseif avoidFillTypeCategories == nil and avoidFillTypeNames ~= nil then
115 avoidFillTypes = g_fillTypeManager:getFillTypesByNames(avoidFillTypeNames, "Warning: UnloadTrigger has invalid avoidFillType '%s'.")
116 end
117 if avoidFillTypes ~= nil then
118 for _,fillType in pairs(avoidFillTypes) do
119 self.avoidFillTypes[fillType] = true
120 end
121 else
122 self.avoidFillTypes = nil
123 end
124end

loadFillTypes

Description
Loads fill Types
Definition
loadFillTypes(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
131function UnloadTrigger:loadFillTypes(rootNode, xmlFile, xmlNode)
132 local fillTypeCategories = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "fillTypeCategories", getXMLString, rootNode)
133 local fillTypeNames = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "fillTypes", getXMLString, rootNode)
134 local fillTypes = nil
135
136 if fillTypeCategories ~= nil and fillTypeNames == nil then
137 fillTypes = g_fillTypeManager:getFillTypesByCategoryNames(fillTypeCategories, "Warning: UnloadTrigger has invalid fillTypeCategory '%s'.")
138 elseif fillTypeNames ~= nil then
139 fillTypes = g_fillTypeManager:getFillTypesByNames(fillTypeNames, "Warning: UnloadTrigger has invalid fillType '%s'.")
140 end
141 if fillTypes ~= nil then
142 for _, fillType in pairs(fillTypes) do
143 self.fillTypes[fillType] = true
144 end
145 else
146 self.fillTypes = nil
147 end
148end

loadBaleTrigger

Description
Loads bale trigger
Definition
loadBaleTrigger(table rootNode, string xmlFile, string xmlNode)
Arguments
tablerootNodeof the object
stringxmlFilefile to read
stringxmlNodexmlNode to read from
Code
155function UnloadTrigger:loadBaleTrigger(rootNode, xmlFile, xmlNode)
156 local baleTriggerNode = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "baleTriggerIndex", getXMLString, rootNode)
157 if baleTriggerNode ~= nil then
158 g_logManager:warning("'baleTriggerIndex' is not supported anymore for unloadTrigger! Please use 'baleTriggerNode' instead!")
159 end
160
161 baleTriggerNode = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "baleTriggerNode", getXMLString, rootNode)
162
163 if baleTriggerNode ~= nil then
164 self.baleTriggerNode = I3DUtil.indexToObject(rootNode, baleTriggerNode)
165 if self.baleTriggerNode ~= nil then
166 addTrigger(self.baleTriggerNode, "baleTriggerCallback", self)
167 end
168 end
169
170 local baleDeleteLitersPerSecond = XMLUtil.getValueFromXMLFileOrUserAttribute(xmlFile, xmlNode, "baleDeleteLitersPerSecond", getXMLInt, rootNode)
171 if baleDeleteLitersPerSecond ~= nil then
172 self.baleDeleteLitersPerMS = baleDeleteLitersPerSecond * 0.0001
173 end
174end

delete

Description
Delete instance
Definition
delete()
Code
178function UnloadTrigger:delete()
179 if self.baleTriggerNode ~= nil and self.baleTriggerNode ~= 0 then
180 removeTrigger(self.baleTriggerNode)
181 self.baleTriggerNode = 0
182 end
183
184 UnloadTrigger:superClass().delete(self)
185end

setTarget

Description
Connects object using the trigger to the trigger
Definition
setTarget(table object)
Arguments
tableobjecttarget on which the unload trigger is attached
Code
190function UnloadTrigger:setTarget(object)
191 assert(object.getIsFillTypeAllowed ~= nil)
192 assert(object.getIsToolTypeAllowed ~= nil)
193 assert(object.addFillLevelFromTool ~= nil)
194 assert(object.getFreeCapacity ~= nil)
195
196 self.target = object
197end

update

Description
Update method
Definition
update(float dt)
Arguments
floatdtdelta time
Code
206function UnloadTrigger:update(dt)
207 UnloadTrigger:superClass().update(self, dt)
208
209 self:updateBales(dt)
210end

updateBales

Description
Update bale mechanics
Definition
updateBales(float dt)
Arguments
floatdtdelta time
Code
215function UnloadTrigger:updateBales(dt)
216 for index, bale in ipairs(self.balesInTrigger) do
217 if bale ~= nil and bale.nodeId ~= 0 then
218 if bale.dynamicMountJointIndex == nil then
219 local fillType = bale:getFillType()
220 local fillLevel = bale:getFillLevel()
221 local fillInfo = nil
222
223 local delta = bale:getFillLevel()
224 if self.baleDeleteLitersPerMS ~= nil then
225 delta = self.baleDeleteLitersPerMS * dt
226 end
227
228 if delta > 0 then
229 self.target:addFillLevelFromTool(bale:getOwnerFarmId(), delta, fillType, fillInfo, ToolType.BALE)
230 bale:setFillLevel(fillLevel - delta)
231 local newFillLevel = bale:getFillLevel()
232 if newFillLevel < 0.01 then
233 bale:delete()
234 table.remove(self.balesInTrigger, index)
235 break
236 end
237 end
238 end
239 else
240 table.remove(self.balesInTrigger, index)
241 end
242 end
243
244 if #self.balesInTrigger > 0 then
245 self:raiseActive()
246 end
247end

getFillUnitIndexFromNode

Description
Returns default value '1'
Definition
getFillUnitIndexFromNode(integer node)
Arguments
integernodescenegraph node
Code
252function UnloadTrigger:getFillUnitIndexFromNode(node)
253 return 1
254end

getFillUnitExactFillRootNode

Description
Returns exactFillRootNode
Definition
getFillUnitExactFillRootNode(integer fillUnitIndex)
Arguments
integerfillUnitIndexindex of fillunit
Code
259function UnloadTrigger:getFillUnitExactFillRootNode(fillUnitIndex)
260 return self.exactFillRootNode
261end

addFillUnitFillLevel

Description
Increase fill level
Definition
addFillUnitFillLevel(integer fillUnitIndex, float fillLevelDelta, integer fillTypeIndex, table toolType, table fillPositionData)
Arguments
integerfillUnitIndex
floatfillLevelDelta
integerfillTypeIndex
tabletoolType
tablefillPositionData
Return Values
Code
271function UnloadTrigger:addFillUnitFillLevel(farmId, fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData)
272 local applied = self.target:addFillLevelFromTool(farmId, fillLevelDelta, fillTypeIndex, fillPositionData, toolType)
273 return applied
274end

getFillUnitAllowsFillType

Description
Checks if fill type is allowed
Definition
getFillUnitAllowsFillType(integer fillUnitIndex, integer fillType)
Arguments
integerfillUnitIndex
integerfillType
Return Values
booltrueif allowed
Code
290function UnloadTrigger:getFillUnitAllowsFillType(fillUnitIndex, fillType)
291 return self:getIsFillTypeAllowed(fillType)
292end

getIsFillTypeAllowed

Description
Checks if fillType is allowed
Definition
getIsFillTypeAllowed(integer fillType)
Arguments
integerfillType
Return Values
booleanisAllowedtrue if fillType is supported else false
Code
298function UnloadTrigger:getIsFillTypeAllowed(fillType)
299 return self:getIsFillTypeSupported(fillType) and self:getFillUnitFreeCapacity(1, fillType) > 0
300end

getIsFillTypeSupported

Description
Checks if fillType is supported
Definition
getIsFillTypeSupported(integer fillType)
Arguments
integerfillType
Return Values
booleanisSupportedtrue if fillType is supported else false
Code
306function UnloadTrigger:getIsFillTypeSupported(fillType)
307 local accepted = true
308
309 if self.target ~= nil then
310 if not self.target:getIsFillTypeAllowed(fillType) then
311 accepted = false
312 end
313 else
314 if self.fillTypes ~= nil then
315 if not self.fillTypes[fillType] then
316 accepted = false
317 end
318 end
319 end
320
321 if self.avoidFillTypes ~= nil then
322 if self.avoidFillTypes[fillType] then
323 accepted = false
324 end
325 end
326
327 return accepted
328end

getFillUnitFreeCapacity

Description
Returns the free capacity
Definition
getFillUnitFreeCapacity(integer fillUnitIndex, integer fillTypeIndex)
Arguments
integerfillUnitIndexfill unit index
integerfillTypeIndexfill type index
Return Values
floatfreeCapacityfree capacity
Code
343function UnloadTrigger:getFillUnitFreeCapacity(fillUnitIndex, fillTypeIndex, farmId)
344 if self.target.getFreeCapacity ~= nil then
345 return self.target:getFreeCapacity(fillTypeIndex, farmId)
346 end
347 return 0
348end

getIsToolTypeAllowed

Description
Checks if toolType is allowed
Definition
getIsToolTypeAllowed(integer toolType)
Arguments
integertoolType
Return Values
booleanisAllowedtrue if toolType is allowed else false
Code
354function UnloadTrigger:getIsToolTypeAllowed(toolType)
355 local accepted = true
356
357 if self.acceptedToolTypes ~= nil then
358 if self.acceptedToolTypes[toolType] ~= true then
359 accepted = false
360 end
361 end
362
363 if accepted then
364 return self.target:getIsToolTypeAllowed(toolType)
365 else
366 return false
367 end
368end

baleTriggerCallback

Description
Callback method for the bale trigger
Definition
baleTriggerCallback(integer triggerId, integer otherId, bool onEnter, bool onLeave, bool onStay, integer otherShapeId)
Arguments
integertriggerId
integerotherId
boolonEnter
boolonLeave
boolonStay
integerotherShapeId
Code
378function UnloadTrigger:baleTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId)
379 if self.isEnabled then
380 local object = g_currentMission:getNodeObject(otherId)
381 if object ~= nil and object:isa(Bale) then
382 if onEnter then
383 local fillType = object:getFillType()
384
385 if self.target:getIsFillTypeAllowed(fillType) and self.target:getIsToolTypeAllowed(ToolType.BALE) then
386 if self.target:getFreeCapacity(fillType) > 0 then
387 self:raiseActive()
388 table.insert(self.balesInTrigger, object)
389 end
390 end
391
392 if self.fillTypes ~= nil and self.fillTypes[fillType] ~= true then
393 return
394 end
395 if self.avoidFillTypes ~= nil and self.avoidFillTypes[fillType] == true then
396 return
397 end
398 if self.acceptedToolTypes ~= nil and self.acceptedToolTypes[ToolType.BALE] ~= true then
399 return
400 end
401
402 if self.target:getIsFillTypeAllowed(fillType) and self.target:getIsToolTypeAllowed(ToolType.BALE) then
403 self:raiseActive()
404 table.insert(self.balesInTrigger, object)
405 end
406 elseif onLeave then
407 for index,bale in ipairs(self.balesInTrigger) do
408 if bale == object then
409 table.remove(self.balesInTrigger, index)
410 break
411 end
412 end
413 end
414 end
415 end
416end

WeighStation

Description
Class for weigh stations

onCreate

Description
On create weigh station
Definition
onCreate(integer id)
Arguments
integeridid of weigh station node
Code
13function WeighStation:onCreate(id)
14 g_currentMission:addNonUpdateable(WeighStation:new(id))
15end

new

Description
Create new weigh station object
Definition
new(integer trigger)
Arguments
integertriggerid id of trigger node
Return Values
tableinstanceinstance of object
Code
21function WeighStation:new(triggerId)
22 local self = {}
23 setmetatable(self, WeighStation_mt)
24
25 local nodeId = triggerId
26 self.triggerId = triggerId
27 addTrigger(triggerId, "triggerCallback", self)
28
29 self.isEnabled = true
30 self.triggerVehicles = {}
31
32 local weightDisplayIndex = getUserAttribute(nodeId, "weightDisplayIndex")
33 if weightDisplayIndex ~= nil then
34 self.displayNumbers = I3DUtil.indexToObject(nodeId, weightDisplayIndex)
35 end
36
37 return self
38end

delete

Description
Delete weigh station
Definition
delete()
Code
42function WeighStation:delete()
43 if self.triggerId ~= nil then
44 removeTrigger(self.triggerId)
45 self.triggerId = nil
46 end
47end

updateDisplayNumbers

Description
Write new mass into the display
Definition
updateDisplayNumbers(float mass)
Arguments
floatmassmass
Code
52function WeighStation:updateDisplayNumbers(mass)
53 if self.displayNumbers ~= nil then
54 I3DUtil.setNumberShaderByValue(self.displayNumbers, math.floor(mass), 0)
55 end
56end

updateWeight

Description
Get mass of vehicles in trigger and update display
Definition
updateWeight()
Code
60function WeighStation:updateWeight()
61 local mass = 0
62 for vehicle, _ in pairs(self.triggerVehicles) do
63 mass = mass + vehicle:getTotalMass()
64 end
65 self:updateDisplayNumbers(mass*1000)
66end

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
Code
75function WeighStation:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
76 if self.isEnabled and (onEnter or onLeave) then
77 local vehicle = g_currentMission.nodeToObject[otherId]
78 if onEnter then
79 if vehicle ~= nil then
80 if self.triggerVehicles[vehicle] == nil then
81 self.triggerVehicles[vehicle] = 0
82 end
83 self.triggerVehicles[vehicle] = self.triggerVehicles[vehicle] + 1
84 end
85 else
86 if vehicle ~= nil then
87 self.triggerVehicles[vehicle] = self.triggerVehicles[vehicle] - 1
88 if self.triggerVehicles[vehicle] == 0 then
89 self.triggerVehicles[vehicle] = nil
90 end
91 end
92 end
93
94 self:updateWeight()
95 end
96end

ConfigurationUtil

Description
Vehicle configuration util class

addBoughtConfiguration

Description
Add bought configuration
Definition
addBoughtConfiguration(string name, integer id)
Arguments
stringnameof bought configuration type
integeridid of bought configuration
Code
23function ConfigurationUtil.addBoughtConfiguration(object, name, id)
24 if g_configurationManager:getConfigurationIndexByName(name) ~= nil then
25 if object.boughtConfigurations[name] == nil then
26 object.boughtConfigurations[name] = {}
27 end
28 object.boughtConfigurations[name][id] = true
29 end
30end

hasBoughtConfiguration

Description
Returns true if configuration has been bought
Definition
hasBoughtConfiguration(string name, integer id)
Arguments
stringnameof bought configuration type
integeridid of bought configuration
Return Values
booleanconfigurationHasBeenBoughtconfiguration has been bought
Code
37function ConfigurationUtil.hasBoughtConfiguration(object, name, id)
38 if object.boughtConfigurations[name] ~= nil and object.boughtConfigurations[name][id] then
39 return true
40 end
41 return false
42end

setConfiguration

Description
Set configuration value
Definition
setConfiguration(string name, integer id)
Arguments
stringnamename of configuration type
integeridid of configuration value
Code
48function ConfigurationUtil.setConfiguration(object, name, id)
49 object.configurations[name] = id
50end

getColorByConfigId

Description
Returns color of config id
Definition
getColorByConfigId(string configName, integer configId)
Arguments
stringconfigNamename if config
integerconfigIdid of config to get color
Return Values
tablecolorcolor (r, g, b)
Code
58function ConfigurationUtil.getColorByConfigId(object, configName, configId)
59 local configId = object.configurations[configName]
60 if configId ~= nil then
61 local item = g_storeManager:getItemByXMLFilename(object.configFileName)
62 local config = item.configurations[configName][configId]
63 if config ~= nil then
64 return config.color
65 end
66 end
67
68 return nil
69end

getMaterialByConfigId

Description
Returns material of config id
Definition
getMaterialByConfigId(string configName, integer configId)
Arguments
stringconfigNamename if config
integerconfigIdid of config to get color
Return Values
integermaterialmaterial
Code
76function ConfigurationUtil.getMaterialByConfigId(object, configName, configId)
77 local configId = object.configurations[configName]
78 if configId ~= nil then
79 local item = g_storeManager:getItemByXMLFilename(object.configFileName)
80 local config = item.configurations[configName][configId]
81 if config ~= nil then
82 return config.material
83 end
84 end
85
86 return nil
87end

applyDesign

Description
Apply design config
Definition
applyDesign(integer xmlFile, integer configDesignId)
Arguments
integerxmlFileid of xml object
integerconfigDesignIdid of design to apply
Code
93function ConfigurationUtil.applyDesign(object, xmlFile, configDesignId)
94 local designKey = string.format("vehicle.designConfigurations.designConfiguration(%d)", configDesignId-1)
95 if not hasXMLProperty(xmlFile, designKey) then
96 print("Warning: Invalid design configuration " .. configDesignId);
97 return
98 end
99 local i = 0
100 while true do
101 local materialKey = string.format(designKey..".material(%d)", i)
102 if not hasXMLProperty(xmlFile, materialKey) then
103 break
104 end
105 local baseMaterialNode = I3DUtil.indexToObject(object.components, getXMLString(xmlFile, materialKey.."#node"), object.i3dMappings);
106 local refMaterialNode = I3DUtil.indexToObject(object.components, getXMLString(xmlFile, materialKey.."#refNode"), object.i3dMappings);
107 if baseMaterialNode ~= nil and refMaterialNode ~= nil then
108 local oldMaterial = getMaterial(baseMaterialNode, 0)
109 local newMaterial = getMaterial(refMaterialNode, 0)
110 for _, component in pairs(object.components) do
111 ConfigurationUtil.replaceMaterialRec(object, component.node, oldMaterial, newMaterial);
112 end;
113 end
114
115 local materialName = getXMLString(xmlFile, materialKey .. "#name")
116 if materialName ~= nil then
117 local shaderParameterName = getXMLString(xmlFile, materialKey .. "#shaderParameter")
118 if shaderParameterName ~= nil then
119 local colorStr = getXMLString(xmlFile, materialKey.."#color")
120 if colorStr ~= nil then
121 local color = g_brandColorManager:getBrandColorByName(colorStr)
122 if color == nil then
123 color = ConfigurationUtil.getColorFromString(colorStr)
124 end
125 if color ~= nil then
126 local materialId = getXMLInt(xmlFile, materialKey.."#materialId")
127 if object.setBaseMaterialColor ~= nil then
128 object:setBaseMaterialColor(materialName, shaderParameterName, color, materialId)
129 end
130 end
131 end
132 end
133 end
134
135 i = i + 1
136 end
137 ObjectChangeUtil.updateObjectChanges(xmlFile, "vehicle.designConfigurations.designConfiguration", configDesignId, object.components, object);
138end

replaceMaterialRec

Description
Replace material of node
Definition
replaceMaterialRec(integer node, integer oldMaterial, integer newMaterial)
Arguments
integernodeid of node
integeroldMaterialid of old material
integernewMaterialid of new material
Code
145function ConfigurationUtil.replaceMaterialRec(object, node, oldMaterial, newMaterial)
146 if getHasClassId(node, ClassIds.SHAPE) then
147 local nodeMaterial = getMaterial(node, 0);
148 if nodeMaterial == oldMaterial then
149 setMaterial(node, newMaterial, 0)
150 end
151 end;
152
153 local numChildren = getNumOfChildren(node);
154 if numChildren > 0 then
155 for i=0, numChildren-1 do
156 ConfigurationUtil.replaceMaterialRec(object, getChildAt(node, i), oldMaterial, newMaterial)
157 end;
158 end;
159end

setColor

Description
Sets color of vehicle
Definition
setColor(integer xmlFile, string configName, integer configColorId)
Arguments
integerxmlFileid of xml object
stringconfigNamename of config
integerconfigColorIdid of config color to use
Code
166function ConfigurationUtil.setColor(object, xmlFile, configName, configColorId)
167 local color = ConfigurationUtil.getColorByConfigId(object, configName, configColorId)
168 if color ~= nil then
169 local r,g,b,a = unpack(color);
170 local i = 0;
171 while true do
172 local colorKey = string.format("vehicle.%sConfigurations.colorNode(%d)", configName, i)
173 if not hasXMLProperty(xmlFile, colorKey) then
174 break;
175 end
176
177 local node = I3DUtil.indexToObject(object.components, getXMLString(xmlFile, colorKey .. "#node"), object.i3dMappings);
178 if node ~= nil then
179 if getHasClassId(node, ClassIds.SHAPE) then
180 if Utils.getNoNil(getXMLBool(xmlFile, colorKey .. "#recursive"), false) then
181 I3DUtil.setShaderParameterRec(node, "colorScale", r, g, b, a);
182 else
183 setShaderParameter(node, "colorScale", r, g, b, a, false);
184 end
185 else
186 print("Warning: Could not set vehicle color to '"..getName(node).."' because node is not a shape!")
187 end
188 end
189 i = i + 1;
190 end
191 end
192end

getConfigurationValue

Description
Get value of configuration
Definition
getConfigurationValue(integer xmlFile, string key, string subKey, string param, function xmlFunc, any_type defaultValue, string fallbackConfigKey, string fallbackOldgKey)
Arguments
integerxmlFileid of xml object
stringkeykey
stringsubKeysub key
stringparamparameter
functionxmlFuncxml function
any_typedefaultValuedefault value
stringfallbackConfigKeyfallback config key
stringfallbackOldgKeyfallback old key
Return Values
any_typevaluevalue of config
Code
205function ConfigurationUtil.getConfigurationValue(xmlFile, key, subKey, param, xmlFunc, defaultValue, fallbackConfigKey, fallbackOldKey)
206 if type(subKey) == "table" then
207 printCallstack();
208 end
209 local value = nil;
210 if key ~= nil then
211 value = xmlFunc(xmlFile, key..subKey..param);
212 end;
213
214 if value == nil and fallbackConfigKey ~= nil then
215 value = xmlFunc(xmlFile, fallbackConfigKey..subKey..param); -- Check for default configuration (xml index 0)
216 end;
217 if value == nil and fallbackOldKey ~= nil then
218 value = xmlFunc(xmlFile, fallbackOldKey..subKey..param); -- Fallback to old xml setup
219 end;
220 return Utils.getNoNil(value, defaultValue); -- using default value
221end;

getXMLConfigurationKey

Description
Get xml configuration key
Definition
getXMLConfigurationKey(integer xmlFile, integer index, string key, string defaultKey, string configurationKey)
Arguments
integerxmlFileid of xml object
integerindexindex
stringkeykey
stringdefaultKeydefault key
stringconfigurationKeyconfiguration key
Return Values
stringconfigKeykey of configuration
integerconfigIndexindex of configuration
Code
232function ConfigurationUtil.getXMLConfigurationKey(xmlFile, index, key, defaultKey, configurationKey)
233 local configIndex = Utils.getNoNil(index, 1);
234 local configKey = string.format(key.."(%d)", configIndex-1);
235 if index ~= nil and not hasXMLProperty(xmlFile, configKey) then
236 print("Warning: Invalid "..configurationKey.." index '"..tostring(index).."' in '"..key.."'. Using default "..configurationKey.." settings instead!");
237 end;
238
239 if not hasXMLProperty(xmlFile, configKey) then
240 configKey = key.."(0)";
241 end;
242 if not hasXMLProperty(xmlFile, configKey) then
243 configKey = defaultKey;
244 end;
245
246 return configKey, configIndex;
247end;

getConfigColorSingleItemLoad

Description
Get config color single item load
Definition
getConfigColorSingleItemLoad(integer xmlFile, string baseXMLName, string baseDir, string customEnvironment, boolean isMod, table configItem)
Arguments
integerxmlFileid of xml object
stringbaseXMLNamebase xml name
stringbaseDirbase directory
stringcustomEnvironmentcustom environment
booleanisModis mod
tableconfigItemconfig item
Code
257function ConfigurationUtil.getConfigColorSingleItemLoad(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem)
258
259 local colorStr = Utils.getNoNil(getXMLString(xmlFile, baseXMLName.."#color"), "1 1 1 1")
260 local color = g_brandColorManager:getBrandColorByName(colorStr)
261 if color == nil then
262 color = ConfigurationUtil.getColorFromString(colorStr)
263 end
264
265 configItem.color = color
266 configItem.material = getXMLInt(xmlFile, baseXMLName.."#material")
267
268 configItem.name = XMLUtil.getXMLI18NValue(xmlFile, baseXMLName.."#name", getXMLString, "", "", customEnvironment, false)
269end

getConfigColorPostLoad

Description
Get config color post load
Definition
getConfigColorPostLoad(integer xmlFile, string baseKey, string baseDir, string customEnvironment, boolean isMod, table configurationItems)
Arguments
integerxmlFileid of xml object
stringbaseKeybase key
stringbaseDirbase directory
stringcustomEnvironmentcustom environment
booleanisModis mod
tableconfigurationItemsconfig items
Code
279function ConfigurationUtil.getConfigColorPostLoad(xmlFile, baseKey, baseDir, customEnvironment, isMod, configurationItems, storeItem)
280 local defaultColorIndex = getXMLInt(xmlFile, baseKey.."#defaultColorIndex")
281
282 if Utils.getNoNil(getXMLBool(xmlFile, baseKey.."#useDefaultColors"), false) then
283 local price = Utils.getNoNil(getXMLInt(xmlFile, baseKey.."#price"), 1000);
284
285 for i, color in pairs(g_vehicleColors) do
286 local configItem = StoreItemUtil.addConfigurationItem(configurationItems, "", "", price, 0, false)
287 if color.r ~= nil and color.g ~= nil and color.b ~= nil then
288 configItem.color = {color.r, color.g, color.b, 1}
289 elseif color.brandColor ~= nil then
290 configItem.color = g_brandColorManager:getBrandColorByName(color.brandColor)
291
292 if configItem.color == nil then
293 configItem.color = {1, 1, 1, 1}
294 g_logManager:warning("Unable to find brandColor '%s' in g_vehicleColors", color.brandColor)
295 end
296 end
297
298 configItem.name = g_i18n:convertText(color.name)
299
300 if i == defaultColorIndex then
301 configItem.isDefault = true
302 configItem.price = 0
303 end
304 end
305 end;
306
307 if defaultColorIndex == nil then
308 local defaultIsDefined = false
309 for _, item in ipairs(configurationItems) do
310 if item.isDefault ~= nil and item.isDefault then
311 defaultIsDefined = true
312 end
313 end
314
315 if not defaultIsDefined then
316 if #configurationItems > 0 then
317 configurationItems[1].isDefault = true
318 configurationItems[1].price = 0
319 end
320 end
321 end
322end;

getStoreAddtionalConfigData

Description
Get store additional config data
Definition
getStoreAddtionalConfigData(integer xmlFile, string baseXMLName, string baseDir, string customEnvironment, boolean isMod, table configItem)
Arguments
integerxmlFileid of xml object
stringbaseXMLNamebase xml name
stringbaseDirbase directory
stringcustomEnvironmentcustom environment
booleanisModis mod
tableconfigItemconfig item
Code
338function ConfigurationUtil.getStoreAddtionalConfigData(xmlFile, baseXMLName, baseDir, customEnvironment, isMod, configItem)
339 configItem.vehicleType = getXMLString(xmlFile, baseXMLName.."#vehicleType")
340end

getColorFromString

Description
Get color from string
Definition
getColorFromString(string colorString)
Arguments
stringcolorStringcolor rgba string or brand color identifier
Return Values
tablecolorcolor (r, g, b)
Code
346function ConfigurationUtil.getColorFromString(colorString)
347 if colorString ~= nil then
348 local colorVector = g_brandColorManager:getBrandColorByName(colorString) or {StringUtil.getVectorFromString(colorString)}
349
350 if colorVector == nil or #colorVector < 3 or #colorVector > 4 then
351 print("Error: Invalid color string '" .. colorString .. "'")
352 return nil
353 end
354 return colorVector;
355 end
356 return nil;
357end

DebugUtil

Description
DebugUtil

drawDebugNode

Description
Draws a debug node and optional a text at world position of given node
Definition
drawDebugNode(integer id, string text)
Arguments
integeridnode id
stringtexttext

drawDebugCircle

Description
Draw debug circle
Definition
drawDebugCircle(float x, float y, float z, float radius, integer steps)
Arguments
floatxworld x position
floatyworld y position
floatzworld z position
floatradiusradius
integerstepssteps

drawDebugCubeAtWorldPos

Description
Draw debug cube at world position
Definition
drawDebugCubeAtWorldPos(float x, float y, float z, float dirX, float dirY, float dirZ, float upX, float upY, float upZ, float sizeX, float sizeY, float sizeZ, float r, float g, float b)
Arguments
floatxworld x center position
floatyworld y center position
floatzworld z center position
floatdirXx direction
floatdirYy direction
floatdirZz direction
floatupXx up of vector
floatupYy up of vector
floatupZz up of vector
floatsizeXx size
floatsizeYy size
floatsizeZz size
floatrred value
floatggreen value
floatbblue value

drawDebugCube

Description
Draw debug cube at given node
Definition
drawDebugCube(integer id, float sizeX, float sizeY, float sizeZ, float r, float g, float b)
Arguments
integeridnode id
floatsizeXx size
floatsizeYy size
floatsizeZz size
floatrred value
floatggreen value
floatbblue value

drawSimpleDebugCube

Description
Draw debug cube
Definition
drawSimpleDebugCube(float x, float y, float z, float width, float red, float green, float blue)
Arguments
floatxworld x center position
floatyworld y center position
floatzworld z center position
floatwidth
floatred
floatgreen
floatblue

drawDebugReferenceAxisFromNode

Description
Draw debug reference axis fom Node
Definition
drawDebugReferenceAxisFromNode(node to)
Arguments
nodetodraw a reference axis from

drawDebugReferenceAxis

Description
Draw debug reference axis
Definition
drawDebugReferenceAxis(float x, float y, float z, float up, float up, float up, float direction, float direction, float direction)
Arguments
floatxworld x center position
floatyworld y center position
floatzworld z center position
floatupx
floatupy
floatupz
floatdirectionx
floatdirectiony
floatdirectionz

drawDebugParallelogram

Description
Draw debug parallelogram
Definition
drawDebugParallelogram(float x, float z, float widthX, float widthZ, float heightX, float heightZ, float heightOffset, float r, float g, float b, float a)
Arguments
floatxworld x center position
floatzworld z center position
floatwidthXwidthX
floatwidthZwidthZ
floatheightXheightX
floatheightZheightZ
floatheightOffsetheightOffset
floatrred
floatggreen
floatbblue
floataalpha

printTableRecursively

Description
Print a table recursively
Definition
printTableRecursively(table inputTable, string inputIndent, integer depth, integer maxDepth)
Arguments
tableinputTabletable to print
stringinputIndentinput indent
integerdepthcurrent depth
integermaxDepthmax depth

printCallingFunctionLocation

Description
Print the script call location of a function call which uses this function.
Definition
printCallingFunctionLocation()

FSDensityMapUtil

Description
FSDensityMapUtil

cutFruitArea

Description
Cut fruit area
Definition
cutFruitArea(integer fruitId, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, boolean destroySpray, boolean destroySeedingWidth, boolean useMinForageState)
Arguments
integerfruitIdfruit id
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
booleandestroySpraydestroy spray
booleandestroySeedingWidthdestroy seeding width
booleanuseMinForageStateuse min forange state
Return Values
integerharvestPixelsSumharvest of pixels sum
integerharvestNumPixelsharvest number of pixels
floatsprayFactorspray factor
floatplowFactorplow factor
floatlimeFactorlime factor
floatweedFactorweed factor
integergrowthStategrowth state
floatmaxAreamax area

getFruitArea

Description
Get fruit area
Definition
getFruitArea(integer fruitId, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, boolean allowPreparing, boolean useMinForageState)
Arguments
integerfruitIdfruit id
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
booleanallowPreparingallow preparing
booleanuseMinForageStateuse min forage state
Return Values
integerretret
integertotaltotal

updateRollerArea

Description
Update roller area
Definition
updateRollerArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
Return Values
integerchangedValuechanged value

updateCultivatorArea

Description
Update cultivator area
Definition
updateCultivatorArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, boolean createField, boolean commonForced, float angle, integer blockedSprayType)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
booleancreateFieldcreateField
booleancommonForcedcommon createField
floatangleangle
integerblockedSprayTypeblockedSprayType
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area

updatePlowArea

Description
Update plow area
Definition
updatePlowArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, boolean forced, boolean commonForced, float angle)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
booleanforcedforced
booleancommonForcedcommon forced
floatangleangle
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area pixles

updateDestroyCommonArea

Description
Update destroy common area
Definition
updateDestroyCommonArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, boolean limitToField)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
booleanlimitToFieldlimit to field

updateSprayArea

Description
Update spray area
Definition
updateSprayArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, integer sprayTypeIndex)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
integersprayTypeIndexspray type index
Return Values
integernumPixelsnumber of pixels
integertotalNumPixelstotal number of pixels

updateHerbicideArea

Description
Update herbicide area
Definition
updateHerbicideArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
Return Values
integernumPixelsnumber of pixels
integertotalNumPixelstotal number of pixels

updateWeederArea

Description
Update weeder area
Definition
updateWeederArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
Return Values
integernumPixelsnumber of pixels

removeWeedArea

Description
Remove weed area
Definition
removeWeedArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, integer maxGrowthState)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
integermaxGrowthStatemax growth state of the weed

setWeedArea

Description
Set weed area
Definition
setWeedArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, integer value)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
integervaluestate of the weed

resetSprayArea

Description
Reset spray area
Definition
resetSprayArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, boolean force)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
booleanforceforce

updateSowingArea

Description
Update sowing area
Definition
updateSowingArea(integer fruitId, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, float angle, integer growthState)
Arguments
integerfruitIdfruit id
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
floatangleangle
integergrowthStatefruit growth state value
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area pixels

updateDirectSowingArea

Description
Update direct sowing area
Definition
updateDirectSowingArea(integer fruitId, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, float angle, integer growthState)
Arguments
integerfruitIdfruit id
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
floatangleangle
integergrowthStatefruit growth state value
Return Values
integerchangedAreachanged area pixels
integertotalAreatotal area pixels

updateFruitPreparerArea

Description
Update fruit preparer area
Definition
updateFruitPreparerArea(integer fruitId, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, float startDropWorldX, float startDropWorldZ, float widthDropWorldX, float widthDropWorldZ, float heightDropWorldX, float heightDropWorldZ)
Arguments
integerfruitIdfruit id
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z
floatstartDropWorldXstart drop world X
floatstartDropWorldZstart drop world Z
floatwidthDropWorldXwidth drop world X
floatwidthDropWorldZwidth drop world Z
floatheightDropWorldXheight drop world X
floatheightDropWorldZheight drop world Z
Return Values
integernumChangedPixelsnumber of changed pixels

eraseTireTrack

Description
Erase tire track on given parallelogram
Definition
eraseTireTrack(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ)
Arguments
floatstartWorldXstart world X
floatstartWorldZstart world Z
floatwidthWorldXwidth world X
floatwidthWorldZwidth world Z
floatheightWorldXheight world X
floatheightWorldZheight world Z

getTireTrackColorFromDensityBits

Description
Returns tire track color from given density bits
Definition
getTireTrackColorFromDensityBits(integer densityBits)
Arguments
integerdensityBitsdensity bits
Return Values
tablecolortire track color

FSMUtil

Description

create

Description
Creates an instance of SimpleStateMachine; consumer is responsible for deletion of instance.
Definition
create()
Code
15function FSMUtil.create()
16 local fsm = SimpleStateMachine:new()
17 return fsm
18end

GameSettings

Description
Class handling global settings. Global instance is g_gameSettings

new

Description
Create a new instance
Definition
new(table customMt, table messageCenter)
Arguments
tablecustomMtSub-class meta table
tablemessageCenterMessageCenter reference for settings change notifications

getValue

Description
Returns the setting value with the given name
Settings in the game:
-maxNumMirrors
-lightsProfile
-realBeaconLights
-motorStopTimerDuration
-uiScale
-fovY
-isTrainTabbable
-radioVehicleOnly
-radioIsActive
-useColorblindMode
-easyArmControl
-useMiles
-showTriggerMarker
-resetCamera
-useWorldCamera
-invertYLook
-showHelpIcons
-showHelpMenu
-radioVolume
-vehicleVolume
-environmentVolume
-cameraSensitivity
-vehicleArmSensitivity
-ingameMapState
-ingameMapFilter
-moneyUnit
-masterVolume
-musicVolume
Definition
getValue(string name)
Arguments
stringnamename of the setting
Return Values
mixedvalueValue of the setting. The type depends on the setting

setValue

Description
Changed the setting value with the given name
Definition
setValue(string name, mixed value, boolean doSave)
Arguments
stringnamename of the setting
mixedvaluevalue to set the setting to
booleandoSaveIf true, the settings are saved persistently, otherwise it will only be saved when another call triggers it
Return Values
booleansuccessfulReturns true, if the setting was changed

HTMLUtil

Description

encodeToHTML

Description
Returns a html encoded string
Definition
encodeToHTML(string str, boolean inCData)
Arguments
stringstrinput string
booleaninCDatatrue if text is in cdata element
Return Values
stringencodedStringthe encoded string

decodeFromHTML

Description
Returns a html decoded string
Definition
decodeFromHTML(string str)
Arguments
stringstrinput string
Return Values
stringdecodedStringthe decoded string

ListUtil

Description

copyTable

Description
Returns a copy of the given table. It's not a deep copy!
Definition
copyTable(table sourceTable)
Arguments
tablesourceTablethe source table
Return Values
tablecopythe copied table

copyTableRecursively

Description
Returns a full copy of the given table, including all child tables
Definition
copyTableRecursively(table sourceTable)
Arguments
tablesourceTablethe source table
Return Values
tablecopythe copied table

addElementToList

Description
Adds an element to the list if element is not part of the list
Definition
addElementToList(table list, table element)
Arguments
tablelista list
tableelementan element

removeElementFromList

Description
Removes an element from a given list
Definition
removeElementFromList(table list, table element)
Arguments
tablelista list
tableelementan element

hasListElement

Description
Checks if list contains an element
Definition
hasListElement(table list, table element)
Arguments
tablelista list
tableelementan element
Return Values
booleanisElementOfListtrue if element is part of the list, else false

findListElementFirstIndex

Description
Gets the index of the first occurrence
Definition
findListElementFirstIndex(table list, table element, object defaultReturn)
Arguments
tablelista list
tableelementan element
objectdefaultReturna default return value
Return Values
integerindexindex of first occurrence

areListsEqual

Description
Checks if two lists are equal
Definition
areListsEqual(table list1, table list2, boolean orderIndependent)
Arguments
tablelist1list one
tablelist2list two
booleanorderIndependenttrue the order of the elements has to be the same
Return Values
booleanareEqualtrue if lists are equal, else false

getRandomElement

Description
Gets a random element from given list
Definition
getRandomElement(table list)
Arguments
tablelistlist to get element from
Return Values
anyvaluevalue of the random element

listToSet

Description
Converts a list to a set
Definition
listToSet(table list)
Arguments
tablelista list
Return Values
tablesetthe converted set

setToList

Description
Converts a set to a list
Definition
setToList(table set)
Arguments
tableseta set
Return Values
tablelistthe converted list

setToHash

Description
Converts a set to a hash
Definition
setToHash(table set)
Arguments
tableseta set
Return Values
tablehashthe converted hash

areSetsEqual

Description
Checks if two sets are equal
Definition
areSetsEqual(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
booleanareEqualtrue if sets are equal, else false

isSubset

Description
Checks if set1 is a subset of set2
Definition
isSubset(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
booleanisSubsettrue if set1 is a subset of set2

isRealSubset

Description
Checks if set1 is a real subset of set2
Definition
isRealSubset(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
booleanisSubsettrue if set1 is a real subset of set2

hasSetIntersection

Description
Checks if set1 and set2 have an intersection
Definition
hasSetIntersection(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
booleanhasIntersectiontrue if set1 and set2 have an intersection

getSetIntersection

Description
Gets the intersection of two sets
Definition
getSetIntersection(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
tableintersectionthe intersection of both sets

getSetSubtraction

Description
Gets the substraction of two sets
Definition
getSetSubtraction(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
tablesubstractionthe substraction of both set

getSetUnion

Description
Gets the union of two sets
Definition
getSetUnion(table set1, table set2)
Arguments
tableset1set one
tableset2set two
Return Values
tableunionthe union of both sets

filter

Description
Filters a list. Returns a copy (see functional programming)
Definition
filter(table list, function closure)
Arguments
tablelistlist to filter
functionclosurefilter
Return Values
tablefilteredlist (non-deep copy)

ifilter

Description
Filters a list. Returns a copy (see functional programming). Indexed version.
Definition
ifilter(table list, function closure)
Arguments
tablelistindexed list to filter
functionclosurefilter
Return Values
tablefilteredlist (non-deep copy)

MathUtil

Description

sign

Description
Returns the sign of the given value
Definition
sign(float x)
Arguments
floatxa value
Return Values
integersignthe sign of the value

isNan

Description
Returns of the given value is nan
Definition
isNan(float value)
Arguments
floatvaluea value
Return Values
booleantrueif value is nan else false

round

Description
Returns the rounded value
Definition
round(float value, float precision)
Arguments
floatvaluea value
floatprecisiona precision
Return Values
numberrountedvalue

degToRad

Description
Returns the radian value of a given angle in degress
Definition
degToRad(float degValue)
Arguments
floatdegValueangle in degrees
Return Values
floatvalueradian angle

lerp

Description
Returns interpolated value between two given values
Definition
lerp(float v1, float v2, float alpha)
Arguments
floatv1start value
floatv2end value
floatalphaalpha
Return Values
floatvalueinterpolated value

lerp3

Description
Returns interpolated value between two vectors
Definition
lerp3(float x1, float y1, float z1, float x2, float y2, float z2, float alpha)
Arguments
floatx1start x value
floaty1start y value
floatz1start z value
floatx2end x value
floaty2end y value
floatz2end z value
floatalphaalpha
Return Values
floatvalueinterpolated value

inverseLerp

Description
Returns alpha based on current value
Definition
inverseLerp(float v1, float v2, float cv)
Arguments
floatv1start value
floatv2end value
floatcvcurrent value
Return Values
floatalphaalpha

clamp

Description
Returns value between given min and max
Definition
clamp(float value, float minVal, float maxVal)
Arguments
floatvalueto clamp
floatminValmin value
floatmaxValmax value
Return Values
floatvaluevalue

getIsOutOfBounds

Description
Returns true if the value is out of the given range
Definition
getIsOutOfBounds(float value, float limit1, float limit2)
Arguments
floatvaluevalue
floatlimit1limit 1
floatlimit2limit 2
Return Values
floatisOutOfBoundsis out of bounds

getFlooredPercent

Description
Returns the floored percent
Definition
getFlooredPercent(float value, float maxValue)
Arguments
floatvaluea value
floatmaxValuemax value
Return Values
floatvaluethe floored percent value

getFlooredBounded

Description
Returns the floored clamped value
Definition
getFlooredBounded(float value, float minValue, float maxValue)
Arguments
floatvaluea value
floatminValuemin value
floatmaxValuemax value
Return Values
floatvaluethe floored clamped value

getValidLimit

Description
Returns a valid limit in the range of -pi to pi
Definition
getValidLimit(float limit)
Arguments
floatlimita radian angle
Return Values
floatanglethe resized angle in the range -pi to pi

getAngleDifference

Description
Returns the difference between two rad angles
Definition
getAngleDifference(float alpha, float beta)
Arguments
floatalphaa radian angle
floatbetaa radian angle
Return Values
floatanglethe radian difference in range -pi to pi

vector2Length

Description
Returns length of 2d vector
Definition
vector2Length(float x, float y)
Arguments
floatxx
floatyy
Return Values
floatlengthlength

vector2LengthSq

Description
Returns squared length of 2d vector
Definition
vector2LengthSq(float x, float y)
Arguments
floatxx
floatyy
Return Values
floatlengthsquare length

vector2Normalize

Description
Returns normalized vector
Definition
vector2Normalize(float x, float y)
Arguments
floatxx
floatyy
Return Values
floatxnormalized x
floatynormalized y

vector3Length

Description
Returns length of 3d vector
Definition
vector3Length(float x, float y, float z)
Arguments
floatxx
floatyy
floatzz
Return Values
floatlengthlength

vector3LengthSq

Description
Returns squared length of 3d vector
Definition
vector3LengthSq(float x, float y, float z)
Arguments
floatxx
floatyy
floatzz
Return Values
floatlengthsquare length

vector3Normalize

Description
Returns normalized vector
Definition
vector3Normalize(float x, float y, float z)
Arguments
floatxx
floatyy
floatzz
Return Values
floatxnormalized x
floatynormalized y
floatznormalized z

vector3SetLength

Description
Returns a scaled vector
Definition
vector3SetLength(float x, float y, float z, float length)
Arguments
floatxx
floatyy
floatzz
floatlengthscale length
Return Values
floatxscaled x
floatyscaled y
floatzscaled z

vector3Clamp

Description
Returns a clamped vector based on min and max vector length
Definition
vector3Clamp(float x, float y, float z, float minVal, float maxVal)
Arguments
floatxx
floatyy
floatzz
floatminValmin length
floatmaxValmax length
Return Values
floatxclamped x
floatyclamped y
floatzclamped z

vector3Lerp

Description
Returns a linear interpolated vector based on given alpha
Definition
vector3Lerp(float x1, float y1, float z1, float x2, float y2, float z2, float alpha)
Arguments
floatx1x1
floaty1y1
floatz1z1
floatx2x2
floaty2y2
floatz2z2
floatalphaalpha value
Return Values
floatxinterpolated x
floatyinterpolated y
floatzinterpolated z

vector3ArrayLerp

Description
Returns a linear interpolated vector based on given alpha
Definition
vector3ArrayLerp(table v1, table v2, float alpha)
Arguments
tablev1vector1
tablev2vector2
floatalphaalpha value
Return Values
floatxinterpolated x
floatyinterpolated y
floatzinterpolated z

vector3Transformation

Description
Transform a vector by matrix multiplication, the matrix is given row by row
Definition
vector3Transformation(float x, float y, float z, float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)
Arguments
floatxx
floatyy
floatzz
floatm11m11
floatm12m12
floatm13m13
floatm21m21
floatm22m22
floatm23m23
floatm31m31
floatm32m32
floatm33m33
Return Values
floatxtransformed x
floatytransformed y
floatztransformed z

dotProduct

Description
Returns the dot product of 2 vectors
Definition
dotProduct(float ax, float ay, float az, float bx, float by, float bz)
Arguments
floataxax
floatayay
floatazaz
floatbxbx
floatbyby
floatbzbz
Return Values
dotthedot product

crossProduct

Description
Returns the cross product of 2 vectors
Definition
crossProduct(float ax, float ay, float az, float bx, float by, float bz)
Arguments
floataxax
floatayay
floatazaz
floatbxbx
floatbyby
floatbzbz
Return Values
floatxx
floatyy
floatzz

getYRotationFromDirection

Description
Returns the angle to rotate from the z axis around the y axis (if x==0, the angle is 0 or 180°). This is unlike the default specification, where the rotation is 0 at the x axis
Definition
getYRotationFromDirection(float dx, float dz)
Arguments
floatdxdx
floatdzdz
Return Values
floatyrotation

getDirectionFromYRotation

Description
Returns the x and z direction based on the given y rotation
Definition
getDirectionFromYRotation(float rotY)
Arguments
floatrotYy rotation
Return Values
floatxx direction
floatzz direction

getRotationLimitedVector2

Description
Returns an 2d vector limited by min and max rotation
Definition
getRotationLimitedVector2(float x, float y, float minRot, float maxRot)
Arguments
floatxx direction
floatyy direction
floatminRotmin rot
floatmaxRotmax rot
Return Values
floatxlimited x direction
floatzlimited z direction

projectOnLine

Description
Returns the projected point on a given line
Definition
projectOnLine(float px, float pz, float lineX, float lineX, float normlineDirX, float normlineDirZ)
Arguments
floatpxx position
floatpzz position
floatlineXx position
floatlineXx position
floatnormlineDirXnormalized x direction
floatnormlineDirZnormalized z direction
Return Values
floatxx position
floatxz position

getProjectOnLineParameter

Description
Returns the dot product on a given line
Definition
getProjectOnLineParameter(float px, float pz, float lineX, float lineZ, float normlineDirX, float normlineDirZ)
Arguments
floatpxx position
floatpzz position
floatlineXx position
floatlineZx position
floatnormlineDirXnormalized x direction
floatnormlineDirZnormalized z direction
Return Values
floatdotproduct

quaternionMult

Description
Returns the multiplication of two quaternions
Definition
quaternionMult(float x, float y, float z, float w, float x1, float y1, float z1, float w1)
Arguments
floatxx1
floatyy1
floatzz1
floatww1
floatx1x2
floaty1y2
floatz1z2
floatw1w2
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

quaternionNormalized

Description
Returns the normalized quaternion
Definition
quaternionNormalized(float x, float y, float z, float w)
Arguments
floatxx
floatyy
floatzz
floatww
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

slerpQuaternion

Description
Returns the linear interpolated quaternion
Definition
slerpQuaternion(float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, float t)
Arguments
floatx1x1
floaty1y1
floatz1z1
floatw1w1
floatx2x2
floaty2y2
floatz2z2
floatw2w2
floattinterpolation value
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

normalizeRotationForShortestPath

Description
Returns normalized rotation for the shortest path from current rotation to target rotation
Definition
normalizeRotationForShortestPath(float targetRotation, float curRotation)
Arguments
floattargetRotationthe target rotation
floatcurRotationthe current rotation
Return Values
floatrotationthe final rotation

nlerpQuaternionShortestPath

Description
Returns the normalized shortest path from current quaternion to target quaternion
Definition
nlerpQuaternionShortestPath(float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, float t)
Arguments
floatx1x1
floaty1y1
floatz1z1
floatw1w1
floatx2x2
floaty2y2
floatz2z2
floatw2w2
floattalpha
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

slerpQuaternionShortestPath

Description
Returns the shortest path from current quaternion to target quaternion
Definition
slerpQuaternionShortestPath(float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, float t)
Arguments
floatx1x1
floaty1y1
floatz1z1
floatw1w1
floatx2x2
floaty2y2
floatz2z2
floatw2w2
floattalpha
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

quaternionMadShortestPath

Description
Returns the shortest path from current quaternion to target quaternion (mad = multiply and add)
Definition
quaternionMadShortestPath(float x, float y, float z, float w, float x1, float y1, float z1, float w1, float t)
Arguments
floatxx1
floatyy1
floatzz1
floatww1
floatx1x2
floaty1y2
floatz1z2
floatw1w2
floattalpha
Return Values
floatxx part of quaternion
floatyy part of quaternion
floatzz part of quaternion
floatww part of quaternion

getDistanceToRectangle2D

Description
Returns the distance to a rectangle
Definition
getDistanceToRectangle2D(float posX, float posZ, float sx, float sz, float dx, float dz, float length, float widthHalf)
Arguments
floatposXx position
floatposZz position
floatsxx position of rectangle
floatszz position of rectangle
floatdxx direction of rectangle
floatdzz direction of rectangle
floatlengthlength of rectangle
floatwidthHalfhalf width of rectangle
Return Values
floatdistancedistance to rectangle

getSignedDistanceToLineSegment2D

Description
Returns the distance to a line segment
Definition
getSignedDistanceToLineSegment2D(float x, float z, float sx, float sz, float dx, float dz, float length)
Arguments
floatxx position
floatzz position
floatsxx position of rectangle
floatszz position of rectangle
floatdxx direction of rectangle
floatdzz direction of rectangle
floatlengthlength of rectangle
Return Values
floatdistancedistance to line segment

getLineLineIntersection2D

Description
Returns the line-line intersection point
Definition
getLineLineIntersection2D(float x1, float z1, float dirX1, float dirZ1, float x2, float z2, float dirX2, float dirZ2)
Arguments
floatx1x1 position
floatz1z1 position
floatdirX1line1 x direction
floatdirZ1line1 z direction
floatx2x2 position
floatz2z2 position
floatdirX2line2 x direction
floatdirZ2line2 z direction
Return Values
booleanhasIntersectiontrue if both lines intersect
floatt1x position
floatt2z position

hasRectangleLineIntersection2D

Description
Returns if rectangle and line have intersection
Definition
hasRectangleLineIntersection2D(float x1, float z1, float dirX1, float dirZ1, float dirX2, float dirZ2, float x3, float z3, float dirX3, float dirZ3)
Arguments
floatx1x1 position
floatz1z1 position
floatdirX1rectangle x1 direction
floatdirZ1rectangle z1 direction
floatdirX2rectangle x2 direction
floatdirZ2rectangle z2 direction
floatx3line x position
floatz3line z position
floatdirX3line x direction
floatdirZ3line z direction
Return Values
booleanhasIntersectiontrue if the line segment is completly in the rectangle OR if it intersects with one of the four rectangle sides

getCircleCircleIntersection

Description
Returns circle-circle intersection points
Definition
getCircleCircleIntersection(float x1, float y1, float r1, float x2, float y2, float r2)
Arguments
floatx1x1 position
floaty1y1 position
floatr1radius 1
floatx2x2 position
floaty2y2 position
floatr2radius 2
Return Values
floatpos1Xx pos of intersection 1, else nil
floatpos1Yy pos of intersection 1, else nil
floatpos2Xx pos of intersection 2, else nil
floatpos2Zz pos of intersection 2, else nil

hasSphereSphereIntersection

Description
Returns if 2 spheres have an intersection
Definition
hasSphereSphereIntersection(float x1, float y1, float z1, float r1, float x2, float y2, float z2, float r2)
Arguments
floatx1x1 position
floaty1y1 position
floatz1z1 position
floatr1radius 1
floatx2x2 position
floaty2y2 position
floatz2z2 position
floatr2radius 2
Return Values
booleanhasIntersectiontrue if spheres have an intersection else false

areaToHa

Description
Converts a area to hectars
Definition
areaToHa(float area, float pixelToSqm)
Arguments
floatareaarea
floatpixelToSqmpixel density
Return Values
floatareaarea in hectars

inchToM

Description
Converts an inch distance to meters
Definition
inchToM(inchValue the)
Arguments
inchValuetheinch value to convert

mToInch

Description
Converts an meter distance to inch
Definition
mToInch(float meterValue)
Arguments
floatmeterValuethe meter value to convert

getBrightnessFromColor

Description
Returns the brightness of a color [0..1]
Definition
getBrightnessFromColor(float r, float g, float b)
Arguments
floatrred value
floatggreen value
floatbblue value
Return Values
floatbrightnessbrightness

ObjectChangeUtil

Description
ObjectChangeUtil

loadObjectChangeFromXML

Description
Load object change from xml
Definition
loadObjectChangeFromXML(integer xmlFile, string key, table objects, integer rootNode, table parent)
Arguments
integerxmlFilefile id of xml file
stringkeykey
tableobjectstable to insert loaded objects
integerrootNodeid of root node
tableparentparent
Code
14function ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, key, objects, rootNode, parent)
15 local i = 0
16 while true do
17 local nodeKey = string.format(key .. ".objectChange(%d)", i)
18 if not hasXMLProperty(xmlFile, nodeKey) then
19 break
20 end
21 local node = I3DUtil.indexToObject(rootNode, getXMLString(xmlFile, nodeKey .. "#node"), parent.i3dMappings)
22 if node ~= nil then
23 local object = {}
24 object.node = node
25 ObjectChangeUtil.loadValuesFromXML(xmlFile, nodeKey, node, object, parent)
26 table.insert(objects, object)
27 end
28 i = i + 1
29 end
30end

loadValuesFromXML

Description
Load object values from xml
Definition
loadValuesFromXML(integer xmlFile, string key, integer node, table object, table parent)
Arguments
integerxmlFilefile id of xml file
stringkeykey
integernodenode id to load from
tableobjecttable to insert loaded data
tableparentparent
Code
39function ObjectChangeUtil.loadValuesFromXML(xmlFile, key, node, object, parent)
40 object.visibilityActive = getXMLBool(xmlFile, key.."#visibilityActive")
41 object.visibilityInactive = getXMLBool(xmlFile, key.."#visibilityInactive")
42 object.translationActive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#translationActive"), 3)
43 object.translationInactive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#translationInactive"), 3)
44 object.rotationActive = StringUtil.getRadiansFromString(getXMLString(xmlFile, key.."#rotationActive"), 3)
45 object.rotationInactive = StringUtil.getRadiansFromString(getXMLString(xmlFile, key.."#rotationInactive"), 3)
46 object.scaleActive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#scaleActive"), 3)
47 object.scaleInactive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#scaleInactive"), 3)
48
49 XMLUtil.checkDeprecatedXMLElements(xmlFile, "", key.."#collisionActive", key.."#compoundChildActive or #rigidBodyTypeActive") --FS17 to FS19
50 XMLUtil.checkDeprecatedXMLElements(xmlFile, "", key.."#collisionInactive", key.."#compoundChildInactive or #rigidBodyTypeInactive") --FS17 to FS19
51
52 object.massActive = nil
53 object.massInactive = nil
54 local massActive = getXMLFloat(xmlFile, key.."#massActive")
55 if massActive ~= nil then
56 object.massActive = massActive / 1000
57 end
58 local massInactive = getXMLFloat(xmlFile, key.."#massInactive")
59 if massInactive ~= nil then
60 object.massInactive = massInactive / 1000
61 end
62 object.centerOfMassActive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#centerOfMassActive"), 3)
63 object.centerOfMassInactive = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#centerOfMassInactive"), 3)
64 object.compoundChildActive = getXMLBool(xmlFile, key.."#compoundChildActive")
65 object.compoundChildInactive = getXMLBool(xmlFile, key.."#compoundChildInactive")
66 object.rigidBodyTypeActive = getXMLString(xmlFile, key.."#rigidBodyTypeActive")
67 object.rigidBodyTypeInactive = getXMLString(xmlFile, key.."#rigidBodyTypeInactive")
68
69 if object.rigidBodyTypeActive ~= nil then
70 local t = object.rigidBodyTypeActive
71 if t ~= "Static" and t ~= "Dynamic" and t ~= "Kinematic" and t ~= "NoRigidBody" then
72 g_logManager:warning("Invalid rigidBodyTypeActive '%s' for object change node '%s'. Use 'Static', 'Dynamic', 'Kinematic' or 'NoRigidBody'!", t, key)
73 object.rigidBodyTypeActive = nil
74 end
75 end
76 if object.rigidBodyTypeInactive ~= nil then
77 local t = object.rigidBodyTypeInactive
78 if t ~= "Static" and t ~= "Dynamic" and t ~= "Kinematic" and t ~= "NoRigidBody" then
79 g_logManager:warning("Invalid rigidBodyTypeInactive '%s' for object change node '%s'. Use 'Static', 'Dynamic', 'Kinematic' or 'NoRigidBody'!", t, key)
80 object.rigidBodyTypeInactive = nil
81 end
82 end
83
84 if parent ~= nil and parent.loadObjectChangeValuesFromXML ~= nil then
85 parent:loadObjectChangeValuesFromXML(xmlFile, key, node, object)
86 end
87end

setObjectChanges

Description
Set object changes
Definition
setObjectChanges(table object, boolean isActive, table target, function updateFunc)
Arguments
tableobjectobjects to change
booleanisActiveis active
tabletargettarget for updateFunc
functionupdateFuncfunction to update
Code
95function ObjectChangeUtil.setObjectChanges(objects, isActive, target, updateFunc)
96 for _, object in pairs(objects) do
97 ObjectChangeUtil.setObjectChange(object, isActive, target, updateFunc)
98 end
99end

setObjectChange

Description
Set object change
Definition
setObjectChange(table object, boolean isActive, table target, function updateFunc)
Arguments
tableobjectobjects to change
booleanisActiveis active
tabletargettarget for updateFunc
functionupdateFuncfunction to update
Code
107function ObjectChangeUtil.setObjectChange(object, isActive, target, updateFunc)
108 if isActive then
109 if object.visibilityActive ~= nil then
110 setVisibility(object.node, object.visibilityActive)
111 end
112 if object.translationActive ~= nil then
113 setTranslation(object.node, object.translationActive[1], object.translationActive[2], object.translationActive[3])
114 end
115 if object.rotationActive ~= nil then
116 setRotation(object.node, object.rotationActive[1], object.rotationActive[2], object.rotationActive[3])
117 end
118 if object.scaleActive ~= nil then
119 setScale(object.node, object.scaleActive[1], object.scaleActive[2], object.scaleActive[3])
120 end
121 if object.massActive ~= nil then
122 setMass(object.node, object.massActive)
123
124 if target ~= nil and target.components ~= nil then
125 for _, component in ipairs(target.components) do
126 if component.node == object.node then
127 component.defaultMass = object.massActive
128 target:setMassDirty()
129 end
130 end
131 end
132 end
133 if object.centerOfMassActive ~= nil then
134 setCenterOfMass(object.node, unpack(object.centerOfMassActive))
135 end
136 if object.compoundChildActive ~= nil then
137 setIsCompoundChild(object.node, object.compoundChildActive)
138 end
139 if object.rigidBodyTypeActive ~= nil then
140 setRigidBodyType(object.node, object.rigidBodyTypeActive)
141 end
142 else
143 if object.visibilityInactive ~= nil then
144 setVisibility(object.node, object.visibilityInactive)
145 end
146 if object.translationInactive ~= nil then
147 setTranslation(object.node, object.translationInactive[1], object.translationInactive[2], object.translationInactive[3])
148 end
149 if object.rotationInactive ~= nil then
150 setRotation(object.node, object.rotationInactive[1], object.rotationInactive[2], object.rotationInactive[3])
151 end
152 if object.scaleInactive ~= nil then
153 setScale(object.node, object.scaleInactive[1], object.scaleInactive[2], object.scaleInactive[3])
154 end
155 if object.massInactive ~= nil then
156 setMass(object.node, object.massInactive)
157
158 if target ~= nil and target.components ~= nil then
159 for _, component in ipairs(target.components) do
160 if component.node == object.node then
161 component.defaultMass = object.massInactive
162 target:setMassDirty()
163 end
164 end
165 end
166 end
167 if object.centerOfMassInactive ~= nil then
168 setCenterOfMass(object.node, unpack(object.centerOfMassInactive))
169 end
170 if object.compoundChildInactive ~= nil then
171 setIsCompoundChild(object.node, object.compoundChildInactive)
172 end
173 if object.rigidBodyTypeInactive ~= nil then
174 setRigidBodyType(object.node, object.rigidBodyTypeInactive)
175 end
176 end
177 if target ~= nil then
178 if target.setObjectChangeValues ~= nil then
179 target:setObjectChangeValues(object, isActive)
180 end
181 if updateFunc ~= nil then
182 updateFunc(target, object.node)
183 end
184 end
185end

updateObjectChanges

Description
Update object changes
Definition
updateObjectChanges(integer xmlFile, string key, integer configKey, integer rootNode, table parent)
Arguments
integerxmlFilefile id of xml file
stringkeykey
integerconfigKeyid of used config
integerrootNodeid of root node
tableparentparent
Code
194function ObjectChangeUtil.updateObjectChanges(xmlFile, key, configKey, rootNode, parent)
195 local i = 0
196 local activeI = (configKey - 1)
197 while true do
198 local objectChangeKey = string.format(key.."(%d)", i)
199 if not hasXMLProperty(xmlFile, objectChangeKey) then
200 break
201 end
202 if i ~= activeI then
203 local objects = {}
204 ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, objectChangeKey, objects, rootNode, parent)
205 ObjectChangeUtil.setObjectChanges(objects, false, parent)
206 end
207 i = i + 1
208 end
209
210 -- Set the active config last so that it can overwrite settings of inactive configurations
211 if i > activeI then
212 local objectChangeKey = string.format(key.."(%d)", activeI)
213 local objects = {}
214 ObjectChangeUtil.loadObjectChangeFromXML(xmlFile, objectChangeKey, objects, rootNode, parent)
215 ObjectChangeUtil.setObjectChanges(objects, true, parent)
216 end
217end

ParticleUtil

Description
ParticleUtil

loadParticleSystem

Description
Load particle system
Definition
loadParticleSystem(integer xmlId, table particleSystem, string baseString, table linkNodes, boolean defaultEmittingState, string defaultPsFile, string baseDir, integer defaultLinkNode)
Arguments
integerxmlIdid of xml file
tableparticleSystemtable to add particle system data
stringbaseStringbase string to load data from xml
tablelinkNodeslink nodes
booleandefaultEmittingStatedefault emitting state
stringdefaultPsFilepath to default ps file
stringbaseDirbase directory
integerdefaultLinkNodeid of default link node

deleteParticleSystem

Description
Delete particle system
Definition
deleteParticleSystem(table particleSystem)
Arguments
tableparticleSystemparticle system

deleteParticleSystems

Description
Delete particle systems
Definition
deleteParticleSystems(table particleSystems)
Arguments
tableparticleSystemsparticle systems

setEmittingState

Description
Set emitting state of particle system
Definition
setEmittingState(table particleSystem, boolean state, boolean resetStartTimer, boolean resetStopTimer)
Arguments
tableparticleSystemparticle system
booleanstateemitting state
booleanresetStartTimerreset start timer
booleanresetStopTimerreset stop timer

getParticleSystemAverageSpeed

Description
Returns average speed of particle system
Definition
getParticleSystemAverageSpeed(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floataverageSpeedaverage speed

setParticleSystemTimeScale

Description
Setting time scale of particle system
Definition
setParticleSystemTimeScale(table particleSystem, float scale)
Arguments
tableparticleSystemparticle system
floatscaletime scale

setEmitCountScale

Description
Setting emit count scale of particle system
Definition
setEmitCountScale(table particleSystem, float scale)
Arguments
tableparticleSystemparticle system
floatscaleemit count scale

setParticleLifespan

Description
Setting particle system lifespan
Definition
setParticleLifespan(table particleSystem, float lifespan)
Arguments
tableparticleSystemparticle system
floatlifespanlifespan

setParticleStartStopTime

Description
Sets start and stop time of particle system
Definition
setParticleStartStopTime(table particleSystem, float startTime, float stopTime)
Arguments
tableparticleSystemparticle system
floatstartTimestart time
floatstopTimestop time

getParticleSystemSpeed

Description
Returns speed of particle system
Definition
getParticleSystemSpeed(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatspeedspeed

setParticleSystemSpeed

Description
Sets speed of particle system
Definition
setParticleSystemSpeed(table particleSystem, float speed)
Arguments
tableparticleSystemparticle system
floatspeedspeed

getParticleSystemSpeedRandom

Description
Returns speed random of particle system
Definition
getParticleSystemSpeedRandom(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatspeedRandomspeed random

setParticleSystemSpeedRandom

Description
Sets speed random of particle system
Definition
setParticleSystemSpeedRandom(table particleSystem, float speedRandom)
Arguments
tableparticleSystemparticle system
floatspeedRandomspeed random

getParticleSystemNormalSpeed

Description
Returns normal speed of particle system
Definition
getParticleSystemNormalSpeed(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatnormalSpeednormal speed

setParticleSystemNormalSpeed

Description
Sets normal speed of particle system
Definition
setParticleSystemNormalSpeed(table particleSystem, float normalSpeed)
Arguments
tableparticleSystemparticle system
floatnormalSpeednormal speed

getParticleSystemTangentSpeed

Description
Returns tangent speed of particle system
Definition
getParticleSystemTangentSpeed(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floattangentSpeedtangent speed

setParticleSystemTangentSpeed

Description
Sets tangent speed of particle system
Definition
setParticleSystemTangentSpeed(table particleSystem, float tangentSpeed)
Arguments
tableparticleSystemparticle system
floattangentSpeedtangent speed

getParticleSystemSpriteScaleX

Description
Returns X sprite scale of particle system
Definition
getParticleSystemSpriteScaleX(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatspriteScaleXX sprite scale

setParticleSystemSpriteScaleX

Description
Sets X sprite scale of particle system
Definition
setParticleSystemSpriteScaleX(table particleSystem, float spriteScaleX)
Arguments
tableparticleSystemparticle system
floatspriteScaleXX sprite scale

getParticleSystemSpriteScaleY

Description
Returns Y sprite scale of particle system
Definition
getParticleSystemSpriteScaleY(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatspriteScaleYY sprite scale

setParticleSystemSpriteScaleY

Description
Sets Y sprite scale of particle system
Definition
setParticleSystemSpriteScaleY(table particleSystem, float spriteScaleY)
Arguments
tableparticleSystemparticle system
floatspriteScaleYY sprite scale

getParticleSystemSpriteScaleXGain

Description
Returns X sprite scale gain of particle system
Definition
getParticleSystemSpriteScaleXGain(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatspriteScaleXGainX sprite scale gain

setParticleSystemSpriteScaleXGain

Description
Sets X sprite scale gain of particle system
Definition
setParticleSystemSpriteScaleXGain(table particleSystem, float spriteScaleXGain)
Arguments
tableparticleSystemparticle system
floatspriteScaleXGainX sprite scale gain

getParticleSystemSpriteScaleYGain

Description
Returns Y sprite scale gain of particle system
Definition
getParticleSystemSpriteScaleYGain(table particleSystem)
Arguments
tableparticleSystemparticle system
Return Values
floatspriteScaleYGainY sprite scale gain

setParticleSystemSpriteScaleYGain

Description
Sets Y sprite scale gain of particle system
Definition
setParticleSystemSpriteScaleYGain(table particleSystem, float spriteScaleYGain)
Arguments
tableparticleSystemparticle system
floatspriteScaleYGainY sprite scale gain

resetNumOfEmittedParticles

Description
Resets number of emitted particles
Definition
resetNumOfEmittedParticles(table particleSystem)
Arguments
tableparticleSystemparticle system

PlacementUtil

Description

isInsideRestrictedZone

Description
Check if a placeable object at a given position lies within a restricted zone or below the water line.
Definition
isInsideRestrictedZone(places Array, placable Placeable, x Testing, y Testing, Z Testing)
Arguments
placesArrayof restricted zones (see PlacementUtil.createRestrictedZone() for data definition)
placablePlaceableinstance
xTestingX position in world space
yTestingY position in world space
ZTestingZ position in world space

isInsidePlacementPlaces

Description
Check if a placeable object at a given position lies within store or loading spaces.
Definition
isInsidePlacementPlaces(places Array, placable Placeable, x Testing, y Testing, Z Testing)
Arguments
placesArrayof places (see PlacementUtil.createPlace() for data definition)
placablePlaceableinstance
xTestingX position in world space
yTestingY position in world space
ZTestingZ position in world space

hasObjectOverlap

Description
Test if a placeable's placement test volume at a given position and orientation would collide with another object.
The test is performed with a placeable's "placementTestSizeX" and "placementTestSizeZ" attribute values. The given
coordinates must represent a point either on an object or on the terrain to generate a correct result.
Definition
hasObjectOverlap(Placeable Placeable, x Testing, y Testing, Z Testing, rotY Testing)
Arguments
PlaceablePlaceableinstance
xTestingX position in world space
yTestingY position in world space
ZTestingZ position in world space
rotYTestingrotation in radians
Return Values
Trueifthere is a collision, false otherwise

hasOverlapWithPoint

Description
Test if a placeable at given position and rotation would overlap with any player position
Definition
hasOverlapWithPoint()

loadPlaceableFromXML

Description
Load a placeable object from an XML definition file.
Definition
loadPlaceableFromXML(xmlFilename Path, x New, y New, Z New, rx New, ry New, rz New, moveMode True)
Arguments
xmlFilenamePathto placeable XML definition file
xNewobject X position in world space
yNewobject Y position in world space
ZNewobject Z position in world space
rxNewobject X rotation in radians
ryNewobject Y rotation in radians
rzNewobject Z rotation in radians
moveModeTrueif the placeable can be moved around for placement, false otherwise
Return Values
Placeableobjectinstance or nil if no object could be created
Trueifno placeable object could be created at the requested position because there was no valid space, false otherwise

loadPlaceable

Description
Load a placeable object from a validated XML definition.
Definition
loadPlaceable(placeableType Type, xmlFilename Path, x New, y New, Z New, rx New, ry New, rz New, moveMode True)
Arguments
placeableTypeTypename of the requested placeable object
xmlFilenamePathto placeable XML definition file
xNewobject X position in world space
yNewobject Y position in world space
ZNewobject Z position in world space
rxNewobject X rotation in radians
ryNewobject Y rotation in radians
rzNewobject Z rotation in radians
moveModeTrueif the placeable can be moved around for placement, false if the placeable is to be created on the spot
Return Values
Placeableobjectinstance or nil if no object could be created
Trueifno placeable object could be created at the requested position because there was no valid space, false otherwise

getPlaceableAreaByNodes

Description
Get a placeable area based on start, width and height nodes.
The area is returned as an array of 9 numbers, i.e. 1 world space point and 2 world space vectors. The point denotes
the area origin and the vectors define the orientation and length of the area sides.
return {worldStartX, worldStartY, worldStartZ, side1X, side1Y, side1Z, side2X, side2Y, side2Z}
Definition
getPlaceableAreaByNodes()

StringUtil

Description

getVectorFromString

Description
Returns vector from string separated by a whitespace
Definition
getVectorFromString(string input)
Arguments
stringinputinput
Return Values
any_typeunpackedValuesreturns unpacked values found in string

getVectorNFromString

Description
Returns vector N from string separated by a whitespace
Definition
getVectorNFromString(string input, integer num)
Arguments
stringinputinput
integernumnumber of values
Return Values
tablevaluesvalues

getRadiansFromString

Description
Returns radian vector N from string separated by a whitespace
Definition
getRadiansFromString(string input, integer num)
Arguments
stringinputinput
integernumnumber of values
Return Values
tablevaluesradian values

parseList

Description
Returns an array of elements from the string, split at separator, and passed through lambda
Definition
parseList(string str, string seprator, function lambda)
Arguments
stringstrinput string
stringsepratorlist separator
functionlambdafunction to apply to each list element, e.g. tonumber

splitString

Description
Returns text elements splitted by splitPattern
Definition
splitString(string splitPattern, string text)
Arguments
stringsplitPatternsplitting pattern
stringtexta text
Return Values
tableresulttext elements

startsWith

Description
Returns if a string starts with given sequence
Definition
startsWith(string str, string find)
Arguments
stringstra string
stringfindthe start pattern
Return Values
booleanstartsWidthtrue if given string starts with pattern else false

endsWith

Description
Returns if a string ends with given sequence
Definition
endsWith(string str, string find)
Arguments
stringstra string
stringfindthe start pattern
Return Values
booleanstartsWidthtrue if given string ends with pattern else false

trim

Description
Returns a trimed string (no whitespaces at start and end)
Definition
trim(string str)
Arguments
stringstra string
Return Values
stringtrimedStringtrimed text

Utils

Description
Utils

getNoNil

Description
Returns second parameter if the first is nil
Definition
getNoNil(any_type value, any_type setTo)
Arguments
any_typevaluevalue
any_typesetToset to value
Return Values
any_typevaluenot nil value

XMLUtil

Description
XMLUtil
Class for various xml operations

getXMLStringWithDefault

Description
Searches for an XML attribute in two places
Definition
getXMLStringWithDefault(DomXMLFile xmlFile, string key, string defkey, string overridekey, string attr)
Arguments
DomXMLFilexmlFilethe XML file to search
stringkeythe main key to look under
stringdefkeythe secondary key to look under, if the main key fails (can be nil)
stringoverridekeythe override key, which can override the main key (can be nil)
stringattrthe attribute to find

getXMLIntWithDefault

Description
Searches for an XML int attribute in two places
Definition
getXMLIntWithDefault(DomXMLFile xmlFile, string key, string defkey, string overridekey, string attr)
Arguments
DomXMLFilexmlFilethe XML file to search
stringkeythe main key to look under
stringdefkeythe secondary key to look under, if the main key fails (can be nil)
stringoverridekeythe override key, which can override the main key (can be nil)
stringattrthe attribute to find

getXMLFloatWithDefault

Description
Searches for an XML float attribute in two places
Definition
getXMLFloatWithDefault(DomXMLFile xmlFile, string key, string defkey, string overridekey, string attr)
Arguments
DomXMLFilexmlFilethe XML file to search
stringkeythe main key to look under
stringdefkeythe secondary key to look under, if the main key fails (can be nil)
stringoverridekeythe override key, which can override the main key (can be nil)
stringattrthe attribute to find

getXMLOverwrittenValue

Description
Tries to retrieve xml value with given xmlFunc, returns nil if xml-value equals "-" otherwise xml-value if exists otherwise fallbackValue
Definition
getXMLOverwrittenValue(DomXMLFile xmlFile, string key, string subKey, args param, function xmlFunc, fallbackValue fallbackValue, valueFunc additional, ... variable)
Arguments
DomXMLFilexmlFilethe XML file to search
stringkeythe main key
stringsubKeythe secondary key to append to the main key
argsparamparameters passed to the xmlFunc
functionxmlFuncthe xml function to be used for accessing the key
fallbackValuefallbackValueto be returned if key does not exist
valueFuncadditionalfunction to be applied to value retrieved from xml file
...variablenumber of arguments additionally passed to valueFunc

loadDataFromMapXML

Description
Loads the map specific data from the map xml. Can either be inlined in the map xml directly (<xmlKey>...</xmlKey>) or can be referenced with an external file (<xmlKey filename="..." />)
Definition
loadDataFromMapXML(DomXMLFile mapXMLFile, string xmlKey, object loadTarget, function loadFunc, vararg vararg)
Arguments
DomXMLFilemapXMLFilethe map XML file
stringxmlKeythe xml key specifying the data to be loaded
objectloadTargetthe object to call the load function on
functionloadFuncthe load function to be called with the data
varargvarargany data that should be passed to the load function

AIVehicleUtil

Description
Util class for various ai vehicle functions

driveToPoint

Description
Drive vehicle to given point
Definition
driveToPoint(table self, float dt, float acceleration, boolean allowedToDrive, boolean moveForwards, float tX, float tY, float maxSpeed, boolean doNotSteer)
Arguments
tableselfobject of vehicle to move
floatdttime since last call in ms
floataccelerationacceleration
booleanallowedToDriveallowed to drive
booleanmoveForwardsmove forwards
floattXlocal space x position
floattYlocal space y position
floatmaxSpeedspeed limit
booleandoNotSteerdo not steer
Code
28function AIVehicleUtil.driveToPoint(self, dt, acceleration, allowedToDrive, moveForwards, tX, tZ, maxSpeed, doNotSteer)
29
30 if self.firstTimeRun then
31
32 if allowedToDrive then
33
34 local tX_2 = tX * 0.5
35 local tZ_2 = tZ * 0.5
36
37 local d1X, d1Z = tZ_2, -tX_2
38 if tX > 0 then
39 d1X, d1Z = -tZ_2, tX_2
40 end
41
42 local hit,_,f2 = MathUtil.getLineLineIntersection2D(tX_2,tZ_2, d1X,d1Z, 0,0, tX, 0)
43
44 if doNotSteer == nil or not doNotSteer then
45 local rotTime = 0
46 if hit and math.abs(f2) < 100000 then
47 local radius = tX * f2
48 rotTime = self.wheelSteeringDuration * ( math.atan(1/radius) / math.atan(1/self.maxTurningRadius) )
49 end
50
51 local targetRotTime
52 if rotTime >= 0 then
53 targetRotTime = math.min(rotTime, self.maxRotTime)
54 else
55 targetRotTime = math.max(rotTime, self.minRotTime)
56 end
57
58 if targetRotTime > self.rotatedTime then
59 self.rotatedTime = math.min(self.rotatedTime + dt*self:getAISteeringSpeed(), targetRotTime)
60 else
61 self.rotatedTime = math.max(self.rotatedTime - dt*self:getAISteeringSpeed(), targetRotTime)
62 end
63
64 -- adjust maxSpeed
65 local steerDiff = targetRotTime - self.rotatedTime
66 local fac = math.abs(steerDiff) / math.max(self.maxRotTime, -self.minRotTime)
67 local speedReduction = 1.0 - math.pow(fac, 0.25)
68
69 -- if the speed is decreased to less than 1.5km/h we do not accelrate anymore
70 if maxSpeed * speedReduction < 1.5 then
71 acceleration = 0
72 speedReduction = 1.5 / maxSpeed
73 end
74
75 maxSpeed = maxSpeed * speedReduction
76 end
77 end
78
79 self:getMotor():setSpeedLimit(math.min(maxSpeed, self:getCruiseControlSpeed()))
80 if self:getCruiseControlState() ~= Drivable.CRUISECONTROL_STATE_ACTIVE then
81 self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_ACTIVE)
82 end
83
84 if not allowedToDrive then
85 acceleration = 0
86 end
87 if not moveForwards then
88 acceleration = -acceleration
89 end
90
91 WheelsUtil.updateWheelsPhysics(self, dt, self.lastSpeedReal*self.movingDirection, acceleration, not allowedToDrive, true)
92
93 end
94
95end

driveInDirection

Description
Drive in given direction
Definition
driveInDirection(table self, float dt, float steeringAngleLimit, float acceleration, float slowAcceleration, float slowAngleLimit, boolean allowedToDrive, boolean moveForwards, float lx, float lz, float maxSpeed, float slowDownFactor)
Arguments
tableselfobject of vehicle
floatdttime since last call in ms
floatsteeringAngleLimitlimit for steering angle
floataccelerationacceleration
floatslowAccelerationslow acceleration
floatslowAngleLimitlimit of slow angle
booleanallowedToDriveallow to drive
booleanmoveForwardsmove forwards
floatlxx direction
floatlzz direction
floatmaxSpeedmax speed
floatslowDownFactorslow down factor
Code
111function AIVehicleUtil.driveInDirection(self, dt, steeringAngleLimit, acceleration, slowAcceleration, slowAngleLimit, allowedToDrive, moveForwards, lx, lz, maxSpeed, slowDownFactor)
112
113 local angle = 0
114 if lx ~= nil and lz ~= nil then
115 local dot = lz
116 angle = math.deg(math.acos(dot))
117 if angle < 0 then
118 angle = angle+180
119 end
120
121 local turnLeft = lx > 0.00001
122 if not moveForwards then
123 turnLeft = not turnLeft
124 end
125
126 local targetRotTime
127 if turnLeft then
128 --rotate to the left
129 targetRotTime = self.maxRotTime*math.min(angle/steeringAngleLimit, 1)
130 else
131 --rotate to the right
132 targetRotTime = self.minRotTime*math.min(angle/steeringAngleLimit, 1)
133 end
134
135 if targetRotTime > self.rotatedTime then
136 self.rotatedTime = math.min(self.rotatedTime + dt*self:getAISteeringSpeed(), targetRotTime)
137 else
138 self.rotatedTime = math.max(self.rotatedTime - dt*self:getAISteeringSpeed(), targetRotTime)
139 end
140 end
141
142
143 if self.firstTimeRun then
144 local acc = acceleration
145 if maxSpeed ~= nil and maxSpeed ~= 0 then
146 if math.abs(angle) >= slowAngleLimit then
147 maxSpeed = maxSpeed * slowDownFactor
148 end
149 self.motor:setSpeedLimit(maxSpeed)
150
151 if self.cruiseControl.state ~= Drivable.CRUISECONTROL_STATE_ACTIVE then
152 self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_ACTIVE)
153 end
154 else
155 if math.abs(angle) >= slowAngleLimit then
156 acc = slowAcceleration
157 end
158 end
159 if not allowedToDrive then
160 acc = 0
161 end
162 if not moveForwards then
163 acc = -acc
164 end
165 WheelsUtil.updateWheelsPhysics(self, dt, self.lastSpeedReal*self.movingDirection, acc, not allowedToDrive, true)
166 end
167end

getDriveDirection

Description
Returns drive direction
Definition
getDriveDirection(integer refNode, float x, float y, float z)
Arguments
integerrefNodeid of ref node
floatxworld x
floatyworld y
floatzworld z
Return Values
floatlxx direction
floatlzz direction
Code
177function AIVehicleUtil.getDriveDirection(refNode, x, y, z)
178 local lx, _, lz = worldToLocal(refNode, x, y, z)
179
180 local length = MathUtil.vector2Length(lx, lz)
181 if length > 0.00001 then
182 length = 1/length
183 lx = lx*length
184 lz = lz*length
185 end
186 return lx, lz
187end

getAverageDriveDirection

Description
Returns average drive direction between 2 given vectors
Definition
getAverageDriveDirection(integer refNode, float x, float y, float z, float x2, float y2, float z2)
Arguments
integerrefNodeid of ref node
floatxworld x 1
floatyworld y 1
floatzworld z 1
floatx2world x 2
floaty2world y 2
floatz2world z 2
Return Values
floatlxaverage x direction
floatlzaverage z direction
Code
200function AIVehicleUtil.getAverageDriveDirection(refNode, x, y, z, x2, y2, z2)
201 local lx, _, lz = worldToLocal(refNode, (x+x2)*0.5, (y+y2)*0.5, (z+z2)*0.5)
202
203 local length = MathUtil.vector2Length(lx, lz)
204 if length > 0.00001 then
205 lx = lx/length
206 lz = lz/length
207 end
208 return lx, lz, length
209end

getAttachedImplementsAllowTurnBackward

Description
Returns if trailer or trailer low is attached
Definition
getAttachedImplementsAllowTurnBackward(table vehicle)
Arguments
tablevehiclevehicle to check
Return Values
booleanisAttachedis attached
Code
215function AIVehicleUtil.getAttachedImplementsAllowTurnBackward(vehicle)
216 if vehicle.getAIAllowTurnBackward ~= nil then
217 if not vehicle:getAIAllowTurnBackward() then
218 return false
219 end
220 end
221
222 if vehicle.getAttachedImplements ~= nil then
223 for _, implement in pairs(vehicle:getAttachedImplements()) do
224 local object = implement.object
225 if object ~= nil then
226 if object.getAIAllowTurnBackward ~= nil then
227 if not object:getAIAllowTurnBackward() then
228 return false
229 end
230 end
231
232 if not AIVehicleUtil.getAttachedImplementsAllowTurnBackward(object) then
233 return false
234 end
235 end
236 end
237 end
238
239 return true
240end

getAIToolReverserDirectionNode

Description
Returns reverser direction node of attached ai tool
Definition
getAIToolReverserDirectionNode(table vehicle)
Arguments
tablevehiclevehicle to check
Return Values
integeraiToolReverserDirectionNodereverser direction node of ai tool
Code
270function AIVehicleUtil.getAIToolReverserDirectionNode(vehicle)
271 for _, implement in pairs(vehicle:getAttachedImplements()) do
272 if implement.object ~= nil then
273 local reverserNode = implement.object:getAIToolReverserDirectionNode()
274
275 local attachedReverserNode = AIVehicleUtil.getAIToolReverserDirectionNode(implement.object)
276 reverserNode = reverserNode or attachedReverserNode
277
278 return reverserNode
279 end
280 end
281end

getMaxToolRadius

Description
Returns max tool turn radius
Definition
getMaxToolRadius(table implement)
Arguments
tableimplementimplement to check
Return Values
floatmaxTurnRadiusmax turn radius
Code
287function AIVehicleUtil.getMaxToolRadius(implement)
288 local radius = 0
289
290 local _, rotationNode, wheels = implement.object:getAITurnRadiusLimitation()
291
292 -- collect the max manual defined turn radius of all vehicles, not only valid ai implements
293 local rootVehicle = implement.object:getRootVehicle()
294 local retRadius = AIVehicleUtil.getAttachedImplementsMaxTurnRadius(rootVehicle)
295
296 if retRadius ~= -1 then
297 radius = retRadius
298 end
299
300 if rotationNode then
301 local activeInputAttacherJoint = implement.object:getActiveInputAttacherJoint()
302 local refNode = rotationNode
303
304 -- If the refNode is any attacher joint, we always use the currently used attacher joint
305 for _, inputAttacherJoint in pairs(implement.object:getInputAttacherJoints()) do
306 if refNode == inputAttacherJoint.node then
307 refNode = activeInputAttacherJoint.node
308 break
309 end
310 end
311
312 local rx,_,rz = localToLocal(refNode, implement.object.components[1].node, 0,0,0)
313
314 for _, wheel in pairs(wheels) do
315 local nx,_,nz = localToLocal(wheel.repr, implement.object.components[1].node, 0,0,0)
316
317 local x,z = nx-rx, nz-rz
318 local cx,cz = 0,0
319
320 -- get max rotation
321 local rotMax
322 if refNode == activeInputAttacherJoint.node then
323 local attacherVehicle = implement.object:getAttacherVehicle()
324 local jointDesc = attacherVehicle:getAttacherJointDescFromObject(implement.object)
325 rotMax = math.max(jointDesc.upperRotLimit[2], jointDesc.lowerRotLimit[2]) * activeInputAttacherJoint.lowerRotLimitScale[2]
326 else
327 for _,compJoint in pairs(implement.object.componentJoints) do
328 if refNode == compJoint.jointNode then
329 rotMax = compJoint.rotLimit[2]
330 break
331 end
332 end
333 end
334
335 -- calc turning radius
336 local x1 = x*math.cos(rotMax) - z*math.sin(rotMax)
337 local z1 = x*math.sin(rotMax) + z*math.cos(rotMax)
338
339 local dx = -z1
340 local dz = x1
341 if wheel.steeringAxleScale ~= 0 and wheel.steeringAxleRotMax ~= 0 then
342 local tmpx, tmpz = dx, dz
343 dx = tmpx*math.cos(wheel.steeringAxleRotMax) - tmpz*math.sin(wheel.steeringAxleRotMax)
344 dz = tmpx*math.sin(wheel.steeringAxleRotMax) + tmpz*math.cos(wheel.steeringAxleRotMax)
345 end
346
347 local hit,f1,_ = MathUtil.getLineLineIntersection2D(cx,cz, 1,0, x1,z1, dx,dz)
348 if hit then
349 radius = math.max(radius, math.abs(f1))
350 end
351 end
352 end
353
354 return radius
355end

updateInvertLeftRightMarkers

Description
Update invertation of ai left and right markers on vehicle
Definition
updateInvertLeftRightMarkers(table rootAttacherVehicle, table vehicle)
Arguments
tablerootAttacherVehicleroot attacher vehicle
tablevehiclevehicle
Code
361function AIVehicleUtil.updateInvertLeftRightMarkers(rootAttacherVehicle, vehicle)
362 if vehicle.getAIMarkers ~= nil then
363 local leftMarker, rightMarker, _ = vehicle:getAIMarkers()
364 if leftMarker ~= nil and rightMarker ~= nil then
365 local lX, _, _ = localToLocal(leftMarker, rootAttacherVehicle:getAIVehicleDirectionNode(), 0,0,0)
366 local rX, _, _ = localToLocal(rightMarker, rootAttacherVehicle:getAIVehicleDirectionNode(), 0,0,0)
367
368 if rX > lX then
369 vehicle:setAIMarkersInverted()
370 end
371 end
372 end
373end

getValidityOfTurnDirections

Description
Checks fruits on left and right side of vehicle to decide the turn direction
Definition
getValidityOfTurnDirections(table vehicle, float checkFrontDistance, table turnData)
Arguments
tablevehiclevehicle to check
floatcheckFrontDistancedistance to check in front of vehicle
tableturnDataproperties for turning
Return Values
floatleftAreaPercentageleft area percentage
floatrightAreaPercentageright area percentage
Code
382function AIVehicleUtil.getValidityOfTurnDirections(vehicle, turnData)
383 -- let's check the area at/around the marker which is farest behind of vehicle
384 local directionNode = vehicle:getAIVehicleDirectionNode()
385 local attachedAIImplements = vehicle:getAttachedAIImplements()
386 local checkFrontDistance = 5
387
388 local leftAreaPercentage = 0
389 local rightAreaPercentage = 0
390
391 local minZ = math.huge
392 local maxZ = -math.huge
393 for _,implement in pairs(attachedAIImplements) do
394 local leftMarker, rightMarker, backMarker = implement.object:getAIMarkers()
395
396 local _,_,zl = localToLocal(leftMarker, directionNode, 0,0,0)
397 local _,_,zr = localToLocal(rightMarker, directionNode, 0,0,0)
398 local _,_,zb = localToLocal(backMarker, directionNode, 0,0,0)
399
400 minZ = math.min(minZ, zl, zr, zb)
401 maxZ = math.max(maxZ, zl, zr, zb)
402 end
403
404 local sideDistance
405 if turnData == nil then
406 local minAreaWidth = math.huge
407 for _,implement in pairs(attachedAIImplements) do
408 local leftMarker, rightMarker, _ = implement.object:getAIMarkers()
409
410 local lx, _, _ = localToLocal(leftMarker, directionNode, 0,0,0)
411 local rx, _, _ = localToLocal(rightMarker, directionNode, 0,0,0)
412 minAreaWidth = math.min(minAreaWidth, math.abs(lx-rx))
413 end
414 sideDistance = minAreaWidth
415 else
416 sideDistance = math.abs(turnData.sideOffsetRight - turnData.sideOffsetLeft)
417 end
418
419 local dx, dz = vehicle.aiDriveDirection[1], vehicle.aiDriveDirection[2]
420 local sx, sz = -dz, dx
421
422 for _,implement in pairs(attachedAIImplements) do
423 local leftMarker, rightMarker, _ = implement.object:getAIMarkers()
424
425 local lx, ly, lz = localToLocal(leftMarker, directionNode, 0,0,0)
426 local rx, ry, rz = localToLocal(rightMarker, directionNode, 0,0,0)
427
428 local width = math.abs(lx-rx)
429 local length = checkFrontDistance + (maxZ - minZ) + math.max(sideDistance*1.3 + 2, checkFrontDistance) -- 1.3~tan(53) allows detecting back along a field side with angle 53 (and 2m extra compensates for some variances, or higher angles with small tools)
430
431 lx, _, lz = localToWorld(directionNode, lx,ly,maxZ + checkFrontDistance)
432 rx, _, rz = localToWorld(directionNode, rx,ry,maxZ + checkFrontDistance)
433
434 local lSX = lx
435 local lSZ = lz
436 local lWX = lSX - sx * width
437 local lWZ = lSZ - sz * width
438 local lHX = lSX - dx * length
439 local lHZ = lSZ - dz * length
440
441 local rSX = rx
442 local rSZ = rz
443 local rWX = rSX + sx * width
444 local rWZ = rSZ + sz * width
445 local rHX = rSX - dx * length
446 local rHZ = rSZ - dz * length
447
448 local lArea, lTotal = AIVehicleUtil.getAIAreaOfVehicle(implement.object, lSX,lSZ, lWX,lWZ, lHX,lHZ, false)
449 local rArea, rTotal = AIVehicleUtil.getAIAreaOfVehicle(implement.object, rSX,rSZ, rWX,rWZ, rHX,rHZ, false)
450
451 if lTotal > 0 then
452 leftAreaPercentage = leftAreaPercentage + (lArea / lTotal)
453 end
454 if rTotal > 0 then
455 rightAreaPercentage = rightAreaPercentage + (rArea / rTotal)
456 end
457
458 -- just visual debuging
459 if VehicleDebug.state == VehicleDebug.DEBUG_AI then
460 local lSY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lSX,0,lSZ)+2
461 local lWY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lWX,0,lWZ)+2
462 local lHY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lHX,0,lHZ)+2
463 local rSY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, rSX,0,rSZ)+2
464 local rWY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, rWX,0,rWZ)+2
465 local rHY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, rHX,0,rHZ)+2
466
467 vehicle:addAIDebugLine({lSX,lSY,lSZ}, {lWX,lWY,lWZ}, {0.5, 0.5, 0.5})
468 vehicle:addAIDebugLine({lSX,lSY,lSZ}, {lHX,lHY,lHZ}, {0.5, 0.5, 0.5})
469 vehicle:addAIDebugLine({rSX,rSY,rSZ}, {rWX,rWY,rWZ}, {0.5, 0.5, 0.5})
470 vehicle:addAIDebugLine({rSX,rSY,rSZ}, {rHX,rHY,rHZ}, {0.5, 0.5, 0.5})
471 end
472 end
473
474 leftAreaPercentage = leftAreaPercentage / table.getn(attachedAIImplements)
475 rightAreaPercentage = rightAreaPercentage / table.getn(attachedAIImplements)
476
477 return leftAreaPercentage, rightAreaPercentage
478end

checkImplementListForValidGround

Description
Returns if valid ground to work on is found for ai vehicle
Definition
checkImplementListForValidGround(table vehicle, float lookAheadDist, float lookAheadSize)
Arguments
tablevehiclevehicle to check
floatlookAheadDistlook a head distance
floatlookAheadSizelook a head size

getAIAreaOfVehicle

Description
Returns amount of fruit to work for ai vehicle is in given area
Definition
getAIAreaOfVehicle(table vehicle, float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ)
Arguments
tablevehiclevehicle
floatstartWorldXstart world x
floatstartWorldZstart world z
floatwidthWorldXwidth world x
floatwidthWorldZwidth world z
floatheightWorldXheight world x
floatheightWorldZheight world z
Return Values
floatareaarea found
floattotalAreatotal area checked
Code
528function AIVehicleUtil.getAIAreaOfVehicle(vehicle, startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, ignoreProhibitedValues)
529 local terrainDetailRequiredValueRanges = vehicle:getAITerrainDetailRequiredRange()
530 local terrainDetailProhibitValueRanges = vehicle:getAITerrainDetailProhibitedRange()
531
532 local fruitRequirements = vehicle:getAIFruitRequirements()
533 local useDensityHeightMap, useWindrowFruitType = vehicle:getAIFruitExtraRequirements()
534
535 local fruitProhibitions = vehicle:getAIFruitProhibitions()
536
537 if ignoreProhibitedValues then
538 terrainDetailProhibitValueRanges = {}
539 fruitProhibitions = {}
540 end
541
542 if not useDensityHeightMap then
543 return AIVehicleUtil.getAIFruitArea(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, terrainDetailRequiredValueRanges, terrainDetailProhibitValueRanges, fruitRequirements, fruitProhibitions, useWindrowFruitType)
544 else
545 return AIVehicleUtil.getAIDensityHeightArea(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, terrainDetailRequiredValueRanges, terrainDetailProhibitValueRanges, fruitRequirements, fruitProhibitions, useWindrowFruitType)
546 end
547end

getAIFruitArea

Description
Returns amount of fruit to work is in given area
Definition
getAIFruitArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, table terrainDetailRequiredValueRanges, table terrainDetailProhibitValueRanges, table fruitRequirements, table fruitProhibitions, boolean useWindrowed)
Arguments
floatstartWorldXstart world x
floatstartWorldZstart world z
floatwidthWorldXwidth world x
floatwidthWorldZwidth world z
floatheightWorldXheight world x
floatheightWorldZheight world z
tableterrainDetailRequiredValueRangesterrain detail required value ranges
tableterrainDetailProhibitValueRangesterrain detail prohibit value ranges
tablefruitRequirementsrequired fruit type
tablefruitProhibitionsprohibited fruit type
booleanuseWindroweduse windrow
Return Values
floatareaarea found
floattotalAreatotal area checked
Code
564function AIVehicleUtil.getAIFruitArea(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, terrainDetailRequiredValueRanges, terrainDetailProhibitValueRanges, fruitRequirements, fruitProhibitions, useWindrowed)
565 local query = g_currentMission.fieldCropsQuery
566
567 for _, fruitRequirement in pairs(fruitRequirements) do
568 if fruitRequirement.fruitType ~= FruitType.UNKNOWN then
569 local ids = g_currentMission.fruits[fruitRequirement.fruitType]
570 if ids ~= nil and ids.id ~= 0 then
571 if useWindrowed then
572 return 0, 1
573 end
574
575 local desc = g_fruitTypeManager:getFruitTypeByIndex(fruitRequirement.fruitType)
576 query:addRequiredCropType(ids.id, fruitRequirement.minGrowthState+1, fruitRequirement.maxGrowthState+1, desc.startStateChannel, desc.numStateChannels, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
577 end
578 end
579 end
580
581 for _, fruitProhibition in pairs(fruitProhibitions) do
582 if fruitProhibition.fruitType ~= FruitType.UNKNOWN then
583 local ids = g_currentMission.fruits[fruitProhibition.fruitType]
584 if ids ~= nil and ids.id ~= 0 then
585 local desc = g_fruitTypeManager:getFruitTypeByIndex(fruitProhibition.fruitType)
586 query:addProhibitedCropType(ids.id, fruitProhibition.minGrowthState+1, fruitProhibition.maxGrowthState+1, desc.startStateChannel, desc.numStateChannels, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels)
587 end
588 end
589 end
590
591 for _,valueRange in pairs(terrainDetailRequiredValueRanges) do
592 query:addRequiredGroundValue(valueRange[1], valueRange[2], valueRange[3], valueRange[4])
593 end
594
595 for _,valueRange in pairs(terrainDetailProhibitValueRanges) do
596 query:addProhibitedGroundValue(valueRange[1], valueRange[2], valueRange[3], valueRange[4])
597 end
598
599 local x,z, widthX,widthZ, heightX,heightZ = MathUtil.getXZWidthAndHeight(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ)
600 return query:getParallelogram(x,z, widthX,widthZ, heightX,heightZ, true)
601end

getAIDensityHeightArea

Description
Returns amount of density height to work is in given area
Definition
getAIDensityHeightArea(float startWorldX, float startWorldZ, float widthWorldX, float widthWorldZ, float heightWorldX, float heightWorldZ, table terrainDetailRequiredValueRanges, table terrainDetailProhibitValueRanges, integer requiredfruittype, integer requiredMinGrowthState, integer requiredMaxGrowthState, integer prohibitedFruitType, integer prohibitedMinGrowthState, integer prohibitedMaxGrowthState, boolean useWindrowed)
Arguments
floatstartWorldXstart world x
floatstartWorldZstart world z
floatwidthWorldXwidth world x
floatwidthWorldZwidth world z
floatheightWorldXheight world x
floatheightWorldZheight world z
tableterrainDetailRequiredValueRangesterrain detail required value ranges
tableterrainDetailProhibitValueRangesterrain detail prohibit value ranges
integerrequiredfruittyperequired fruit type
integerrequiredMinGrowthStaterequired min growth state
integerrequiredMaxGrowthStaterequired max growth state
integerprohibitedFruitTypeprohibited fruit type
integerprohibitedMinGrowthStateprohibited min growth state
integerprohibitedMaxGrowthStateprohibited max growth state
booleanuseWindroweduse windrow
Return Values
floatareaarea found
floattotalAreatotal area checked
Code
622function AIVehicleUtil.getAIDensityHeightArea(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, terrainDetailRequiredValueRanges, terrainDetailProhibitValueRanges, fruitRequirements, fruitProhibitions, useWindrowed)
623 -- first check if we are on a field
624
625 local data = g_currentMission.densityMapModifiers.getAIDensityHeightArea
626 local modifier = data.modifier
627 local filter = data.filter
628
629 modifier:setParallelogramWorldCoords(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, "ppp")
630 filter:setValueCompareParams("greater", 0)
631
632 local _, detailArea, _ = modifier:executeGet(filter)
633 if detailArea == 0 then
634 return 0, 0
635 end
636
637 local retArea, retTotalArea = 0, 0
638 for _, fruitRequirement in pairs(fruitRequirements) do
639 if fruitRequirement.fruitType ~= FruitType.UNKNOWN then
640 local fillType
641 if useWindrowed then
642 fillType = g_fruitTypeManager:getWindrowFillTypeIndexByFruitTypeIndex(fruitRequirement.fruitType)
643 else
644 fillType = g_fruitTypeManager:getFruitTypeIndexByFillTypeIndex(fruitRequirement.fruitType)
645 end
646 local _, area, totalArea = DensityMapHeightUtil.getFillLevelAtArea(fillType, startWorldX,startWorldZ, widthWorldX,widthWorldZ, heightWorldX,heightWorldZ)
647 retArea, retTotalArea = retArea+area, totalArea
648 end
649 end
650
651 return retArea, retTotalArea
652end

ConfigurationManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
17function ConfigurationManager:new(customMt)
18 local self = AbstractManager:new(customMt or ConfigurationManager_mt)
19
20 self:initDataStructures()
21
22 return self
23end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
27function ConfigurationManager:initDataStructures()
28 self.configurations = {}
29 self.intToConfigurationName = {}
30 self.configurationNameToInt = {}
31end

addConfigurationType

Description
Register new configuration type
Definition
addConfigurationType(string name, string title, function preLoadFunc, function singleItemLoadFunc, function postLoadFunc, integer selectorType)
Arguments
stringnamename of config
stringtitletitle displayed in shop
functionpreLoadFunccalled before loading of configuration
functionsingleItemLoadFunccalled on single item load
functionpostLoadFunccalled after loading of configuration
integerselectorTypeselector type [ConfigurationManager.SELECTOR_MULTIOPTION ConfigurationManager.SELECTOR_COLOR]

getNumOfConfigurationTypes

Description
Returns number of configuration types
Definition
getNumOfConfigurationTypes()
Return Values
integernumOfConfigurationTypesnumber of configuration types
Code
73function ConfigurationManager:getNumOfConfigurationTypes()
74 return table.getn(self.intToConfigurationName)
75end

getConfigurationTypes

Description
Returns a table of the available configuration types
Definition
getConfigurationTypes()
Return Values
integernumOfConfigurationTypesnumber of configuration types
Code
80function ConfigurationManager:getConfigurationTypes()
81 return self.intToConfigurationName
82end

getConfigurationNameByIndex

Description
Returns configuration name by given index
Definition
getConfigurationNameByIndex(integer index)
Arguments
integerindexindex of config
Return Values
stringnamename of config
Code
88function ConfigurationManager:getConfigurationNameByIndex(index)
89 return self.intToConfigurationName[index]
90end

getConfigurationIndexByName

Description
Returns configuration index by given name
Definition
getConfigurationIndexByName(string name)
Arguments
stringnamename of config
Return Values
integerindexindex of config
Code
96function ConfigurationManager:getConfigurationIndexByName(name)
97 return self.configurationNameToInt[name]
98end

getConfigurationDescByName

Description
Returns configuration desc by name
Definition
getConfigurationDescByName(string name)
Arguments
stringnamename of config
Return Values
tableconfigurationconfiguration
Code
104function ConfigurationManager:getConfigurationDescByName(name)
105 return self.configurations[name]
106end

getConfigurationAttribute

Description
Returns configuration attribute by given name and attribute
Definition
getConfigurationAttribute(string configurationName, string attribute)
Arguments
stringconfigurationNamename of config
stringattributename of attribute
Return Values
any_typevaluevalue of attribute
Code
113function ConfigurationManager:getConfigurationAttribute(configurationName, attribute)
114 local config = self:getConfigurationDescByName(configurationName)
115 return config[attribute]
116end

SpecializationManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
17function SpecializationManager:new(customMt)
18 local self = AbstractManager:new(customMt or SpecializationManager_mt)
19
20 return self
21end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
25function SpecializationManager:initDataStructures()
26 self.specializations = {}
27end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
32function SpecializationManager:loadMapData()
33 SpecializationManager:superClass().loadMapData(self)
34
35 local xmlFile = loadXMLFile("SpecializationsXML", "dataS/specializations.xml")
36 local i=0
37 while true do
38 local baseName = string.format("specializations.specialization(%d)", i)
39
40 local typeName = getXMLString(xmlFile, baseName.. "#name")
41 if typeName == nil then
42 break
43 end
44 local className = getXMLString(xmlFile, baseName.. "#className")
45 local filename = getXMLString(xmlFile, baseName.. "#filename")
46
47 g_deferredLoadingManager:addSubtask(function()
48 self:addSpecialization(typeName, className, filename, "")
49 end)
50 i = i+1
51 end
52 delete(xmlFile)
53
54 g_deferredLoadingManager:addSubtask(function()
55 print(" Loaded specializations")
56 end)
57
58 return true
59end

addSpecialization

Description
Adds a new vehicleType
Definition
addSpecialization(string name, string className, string filename, string customEnvironment)
Arguments
stringnamespecialization name
stringclassNameclassname
stringfilenamefilename
stringcustomEnvironmenta custom environment
Return Values
booleansuccesstrue if added else false

Vehicle

Description

registerInteractionFlag

Description
Register interaction flag
Definition
registerInteractionFlag(string name)
Arguments
stringnamename of flag
Code
47function Vehicle.registerInteractionFlag(name)
48 local key = "INTERACTION_FLAG_"..string.upper(name)
49 if Vehicle[key] == nil then
50 Vehicle.NUM_INTERACTION_FLAGS = Vehicle.NUM_INTERACTION_FLAGS + 1
51 Vehicle[key] = Vehicle.NUM_INTERACTION_FLAGS
52 end
53end

saveStatsToXMLFile

Description
Get xml states attributes
Definition
saveStatsToXMLFile()
Return Values
stringattributesattributes
Code
862function Vehicle:saveStatsToXMLFile(xmlFile, key)
863 local isTabbable = self.getIsTabbable == nil or self:getIsTabbable()
864 if self.isDeleted or not self.isVehicleSaved or not isTabbable then
865 return false
866 end
867 local name = "Unknown"
868 local categoryName = "unknown"
869 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
870 if storeItem ~= nil then
871 if storeItem.name ~= nil then
872 name = tostring(storeItem.name)
873 end
874 if storeItem.categoryName ~= nil and storeItem.categoryName ~= "" then
875 categoryName = tostring(storeItem.categoryName)
876 end
877 end
878
879 setXMLString(xmlFile, key.."#name", HTMLUtil.encodeToHTML(name))
880 setXMLString(xmlFile, key.."#category", HTMLUtil.encodeToHTML(categoryName))
881 setXMLString(xmlFile, key.."#type", HTMLUtil.encodeToHTML(tostring(self.typeName)))
882
883 if self.components[1] ~= nil and self.components[1].node ~= 0 then
884 local x,y,z = getWorldTranslation(self.components[1].node)
885 setXMLFloat(xmlFile, key.."#x", x)
886 setXMLFloat(xmlFile, key.."#y", y)
887 setXMLFloat(xmlFile, key.."#z", z)
888 end
889
890 for id, spec in pairs(self.specializations) do
891 local name = self.specializationNames[id]
892
893 if spec.saveStatsToXMLFile ~= nil then
894 spec.saveStatsToXMLFile(self, xmlFile, key)
895 end
896 end
897
898 return true
899end

readStream

Description
Called on client side on join
Definition
readStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
905function Vehicle:readStream(streamId, connection)
906 Vehicle:superClass().readStream(self, streamId)
907 local configFile = NetworkUtil.convertFromNetworkFilename(streamReadString(streamId))
908 local typeName = streamReadString(streamId)
909
910 local configurations = {}
911 local numConfigs = streamReadUIntN(streamId, ConfigurationUtil.SEND_NUM_BITS)
912 for i=1, numConfigs do
913 local configNameId = streamReadUIntN(streamId, ConfigurationUtil.SEND_NUM_BITS)
914 local configId = streamReadUInt16(streamId)
915
916 local configName = g_configurationManager:getConfigurationNameByIndex(configNameId+1)
917 if configName ~= nil then
918 configurations[configName] = configId+1
919 end
920 end
921
922 local boughtConfigurations = {}
923 local numConfigs = streamReadUIntN(streamId, ConfigurationUtil.SEND_NUM_BITS)
924 for i=1, numConfigs do
925 local configNameId = streamReadUIntN(streamId, ConfigurationUtil.SEND_NUM_BITS)
926 local configName = g_configurationManager:getConfigurationNameByIndex(configNameId+1)
927 boughtConfigurations[configName] = {}
928 local numBoughtConfigIds = streamReadUInt16(streamId)
929 for j=1, numBoughtConfigIds do
930 local boughtConfigId = streamReadUInt16(streamId)
931 boughtConfigurations[configName][boughtConfigId + 1] = true
932 end
933 end
934
935 if self.configFileName == nil then
936 local vehicleData = {}
937 vehicleData.filename = configFile
938 vehicleData.isAbsolute = false
939 vehicleData.typeName = typeName
940 vehicleData.posX = 0
941 vehicleData.posY = nil
942 vehicleData.posZ = 0
943 vehicleData.yOffset = 0
944 vehicleData.rotX = 0
945 vehicleData.rotY = 0
946 vehicleData.rotZ = 0
947 vehicleData.isVehicleSaved = true
948 vehicleData.price = 0
949 vehicleData.propertyState = Vehicle.PROPERTY_STATE_NONE
950 -- assign parent class Object's ownerFarmId field here to ensure ownership synchronization in MP:
951 vehicleData.ownerFarmId = self.ownerFarmId
952 vehicleData.isLeased = 0
953 vehicleData.configurations = configurations
954 vehicleData.boughtConfigurations = boughtConfigurations
955 self:load(vehicleData)
956 end
957
958 -- remove from physics to set static components correctly
959 self:removeFromPhysics()
960
961 local paramsXZ = self.highPrecisionPositionSynchronization and g_currentMission.vehicleXZPosHighPrecisionCompressionParams or g_currentMission.vehicleXZPosCompressionParams
962 local paramsY = self.highPrecisionPositionSynchronization and g_currentMission.vehicleYPosHighPrecisionCompressionParams or g_currentMission.vehicleYPosCompressionParams
963 for i=1, table.getn(self.components) do
964 local component = self.components[i]
965 local x = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
966 local y = NetworkUtil.readCompressedWorldPosition(streamId, paramsY)
967 local z = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
968 local x_rot = NetworkUtil.readCompressedAngle(streamId)
969 local y_rot = NetworkUtil.readCompressedAngle(streamId)
970 local z_rot = NetworkUtil.readCompressedAngle(streamId)
971
972 local qx,qy,qz,qw = mathEulerToQuaternion(x_rot,y_rot,z_rot)
973 self:setWorldPositionQuaternion(x,y,z, qx,qy,qz,qw, i, true)
974
975 component.networkInterpolators.position:setPosition(x,y,z)
976 component.networkInterpolators.quaternion:setQuaternion(qx,qy,qz,qw)
977 end
978 self.networkTimeInterpolator:reset()
979
980 -- add to physics again
981 self:addToPhysics()
982
983 self.serverMass = streamReadFloat32(streamId)
984 self.age = streamReadUInt16(streamId)
985 self:setOperatingTime(streamReadFloat32(streamId), true)
986 self.price = streamReadInt32(streamId)
987 self.propertyState = streamReadUIntN(streamId, 2)
988
989 SpecializationUtil.raiseEvent(self, "onReadStream", streamId, connection)
990end

writeStream

Description
Called on server side on join
Definition
writeStream(integer streamId, table connection)
Arguments
integerstreamIdstream ID
tableconnectionconnection
Code
996function Vehicle:writeStream(streamId, connection)
997 Vehicle:superClass().writeStream(self, streamId)
998 streamWriteString(streamId, NetworkUtil.convertToNetworkFilename(self.configFileName))
999 streamWriteString(streamId, self.typeName)
1000
1001 local numConfigs = 0
1002 for _,_ in pairs(self.configurations) do
1003 numConfigs = numConfigs + 1
1004 end
1005
1006 streamWriteUIntN(streamId, numConfigs, ConfigurationUtil.SEND_NUM_BITS)
1007 for configName, configId in pairs(self.configurations) do
1008 local configNameId = g_configurationManager:getConfigurationIndexByName(configName)
1009 streamWriteUIntN(streamId, configNameId-1, ConfigurationUtil.SEND_NUM_BITS)
1010 streamWriteUInt16(streamId, configId-1)
1011 end
1012
1013 local numBoughtConfigs = 0
1014 for _,_ in pairs(self.boughtConfigurations) do
1015 numBoughtConfigs = numBoughtConfigs + 1
1016 end
1017
1018 streamWriteUIntN(streamId, numBoughtConfigs, ConfigurationUtil.SEND_NUM_BITS)
1019 for configName, configIds in pairs(self.boughtConfigurations) do
1020 local numBoughtConfigIds = 0
1021 for _,_ in pairs(configIds) do
1022 numBoughtConfigIds = numBoughtConfigIds + 1
1023 end
1024 local configNameId = g_configurationManager:getConfigurationIndexByName(configName)
1025 streamWriteUIntN(streamId, configNameId-1, ConfigurationUtil.SEND_NUM_BITS)
1026 streamWriteUInt16(streamId, numBoughtConfigIds)
1027 for id, _ in pairs(configIds) do
1028 streamWriteUInt16(streamId, id-1)
1029 end
1030 end
1031
1032 local paramsXZ = self.highPrecisionPositionSynchronization and g_currentMission.vehicleXZPosHighPrecisionCompressionParams or g_currentMission.vehicleXZPosCompressionParams
1033 local paramsY = self.highPrecisionPositionSynchronization and g_currentMission.vehicleYPosHighPrecisionCompressionParams or g_currentMission.vehicleYPosCompressionParams
1034 for i=1, table.getn(self.components) do
1035 local component = self.components[i]
1036 local x,y,z = getWorldTranslation(component.node)
1037 local x_rot,y_rot,z_rot = getWorldRotation(component.node)
1038 NetworkUtil.writeCompressedWorldPosition(streamId, x, paramsXZ)
1039 NetworkUtil.writeCompressedWorldPosition(streamId, y, paramsY)
1040 NetworkUtil.writeCompressedWorldPosition(streamId, z, paramsXZ)
1041 NetworkUtil.writeCompressedAngle(streamId, x_rot)
1042 NetworkUtil.writeCompressedAngle(streamId, y_rot)
1043 NetworkUtil.writeCompressedAngle(streamId, z_rot)
1044 end
1045
1046 streamWriteFloat32(streamId, self.serverMass)
1047 streamWriteUInt16(streamId, self.age)
1048 streamWriteFloat32(streamId, self.operatingTime)
1049 streamWriteInt32(streamId, self.price)
1050 streamWriteUIntN(streamId, self.propertyState, 2)
1051
1052 SpecializationUtil.raiseEvent(self, "onWriteStream", streamId, connection)
1053end

readUpdateStream

Description
Called on client side on update
Definition
readUpdateStream(integer streamId, integer timestamp, table connection)
Arguments
integerstreamIdstream ID
integertimestamptimestamp
tableconnectionconnection
Code
1060function Vehicle:readUpdateStream(streamId, timestamp, connection)
1061 if connection.isServer then
1062 local hasUpdate = streamReadBool(streamId)
1063 if hasUpdate then
1064 self.networkTimeInterpolator:startNewPhaseNetwork()
1065
1066 local paramsXZ = self.highPrecisionPositionSynchronization and g_currentMission.vehicleXZPosHighPrecisionCompressionParams or g_currentMission.vehicleXZPosCompressionParams
1067 local paramsY = self.highPrecisionPositionSynchronization and g_currentMission.vehicleYPosHighPrecisionCompressionParams or g_currentMission.vehicleYPosCompressionParams
1068 for i=1, table.getn(self.components) do
1069 local component = self.components[i]
1070 if not component.isStatic then
1071 local x = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
1072 local y = NetworkUtil.readCompressedWorldPosition(streamId, paramsY)
1073 local z = NetworkUtil.readCompressedWorldPosition(streamId, paramsXZ)
1074 local x_rot = NetworkUtil.readCompressedAngle(streamId)
1075 local y_rot = NetworkUtil.readCompressedAngle(streamId)
1076 local z_rot = NetworkUtil.readCompressedAngle(streamId)
1077 local qx,qy,qz,qw = mathEulerToQuaternion(x_rot,y_rot,z_rot)
1078
1079 component.networkInterpolators.position:setTargetPosition(x,y,z)
1080 component.networkInterpolators.quaternion:setTargetQuaternion(qx,qy,qz,qw)
1081 end
1082 end
1083 SpecializationUtil.raiseEvent(self, "onReadPositionUpdateStream", streamId, connection)
1084 end
1085 end
1086
1087 if Vehicle.debugNetworkUpdate then
1088 print("-------------------------------------------------------------")
1089 print(self.configFileName)
1090 for _, spec in ipairs(self.eventListeners["readUpdateStream"]) do
1091 local className = ClassUtil.getClassName(spec)
1092 local startBits = streamGetReadOffset(streamId)
1093 spec["readUpdateStream"](self, streamId, timestamp, connection)
1094 print(" "..tostring(className).." read " .. streamGetReadOffset(streamId)-startBits .. " bits")
1095 end
1096 else
1097 SpecializationUtil.raiseEvent(self, "onReadUpdateStream", streamId, timestamp, connection)
1098 end
1099end

writeUpdateStream

Description
Called on server side on update
Definition
writeUpdateStream(integer streamId, table connection, integer dirtyMask)
Arguments
integerstreamIdstream ID
tableconnectionconnection
integerdirtyMaskdirty mask
Code
1106function Vehicle:writeUpdateStream(streamId, connection, dirtyMask)
1107 if not connection.isServer then
1108 if streamWriteBool(streamId, bitAND(dirtyMask, self.vehicleDirtyFlag) ~= 0) then
1109
1110 local paramsXZ = self.highPrecisionPositionSynchronization and g_currentMission.vehicleXZPosHighPrecisionCompressionParams or g_currentMission.vehicleXZPosCompressionParams
1111 local paramsY = self.highPrecisionPositionSynchronization and g_currentMission.vehicleYPosHighPrecisionCompressionParams or g_currentMission.vehicleYPosCompressionParams
1112 for i=1, table.getn(self.components) do
1113 local component = self.components[i]
1114 if not component.isStatic then
1115 local x,y,z = getWorldTranslation(component.node)
1116 local x_rot,y_rot,z_rot = getWorldRotation(component.node)
1117 NetworkUtil.writeCompressedWorldPosition(streamId, x, paramsXZ)
1118 NetworkUtil.writeCompressedWorldPosition(streamId, y, paramsY)
1119 NetworkUtil.writeCompressedWorldPosition(streamId, z, paramsXZ)
1120 NetworkUtil.writeCompressedAngle(streamId, x_rot)
1121 NetworkUtil.writeCompressedAngle(streamId, y_rot)
1122 NetworkUtil.writeCompressedAngle(streamId, z_rot)
1123 end
1124 end
1125 SpecializationUtil.raiseEvent(self, "onWritePositionUpdateStream", streamId, connection, dirtyMask)
1126 end
1127 end
1128
1129 if Vehicle.debugNetworkUpdate then
1130 print("-------------------------------------------------------------")
1131 print(self.configFileName)
1132 for _, spec in ipairs(self.eventListeners["writeUpdateStream"]) do
1133 local className = ClassUtil.getClassName(spec)
1134 local startBits = streamGetWriteOffset(streamId)
1135 spec["writeUpdateStream"](self, streamId, connection, dirtyMask)
1136 print(" "..tostring(className).." Wrote " .. streamGetWriteOffset(streamId)-startBits .. " bits")
1137 end
1138 else
1139 SpecializationUtil.raiseEvent(self, "onWriteUpdateStream", streamId, connection, dirtyMask)
1140 end
1141end

updateTick

Description
updateTick
Definition
updateTick(float dt)
Arguments
floatdttime since last call in ms
Code
1281function Vehicle:updateTick(dt)
1282
1283 local isActive = self:getIsActive()
1284 local isActiveForInput = self:getIsActiveForInput()
1285 local isSelected = self:getIsSelected()
1286
1287 self.wasTooFast = false
1288 if self.isServer then
1289 if self.synchronizePosition then
1290 local hasOwner = self:getOwner() ~= nil
1291 for i=1, table.getn(self.components) do
1292 local component = self.components[i]
1293 if not component.isStatic then
1294 local x,y,z = getWorldTranslation(component.node)
1295 local x_rot,y_rot,z_rot=getWorldRotation(component.node)
1296 local sentTranslation = component.sentTranslation
1297 local sentRotation = component.sentRotation
1298 if hasOwner or
1299 math.abs(x-sentTranslation[1]) > 0.005 or
1300 math.abs(y-sentTranslation[2]) > 0.005 or
1301 math.abs(z-sentTranslation[3]) > 0.005 or
1302 math.abs(x_rot-sentRotation[1]) > 0.1 or
1303 math.abs(y_rot-sentRotation[2]) > 0.1 or
1304 math.abs(z_rot-sentRotation[3]) > 0.1
1305 then
1306 self:raiseDirtyFlags(self.vehicleDirtyFlag)
1307 sentTranslation[1] = x
1308 sentTranslation[2] = y
1309 sentTranslation[3] = z
1310 sentRotation[1] = x_rot
1311 sentRotation[2] = y_rot
1312 sentRotation[3] = z_rot
1313
1314 self.lastMoveTime = g_currentMission.time
1315 end
1316 end
1317 end
1318 end
1319
1320 -- is the vehicle sunken in the water?
1321 self.showTailwaterDepthWarning = false
1322 if not self.isBroken and not g_gui:getIsGuiVisible() then
1323 local tailwaterDepth = self:getTailwaterDepth()
1324 if tailwaterDepth > self.thresholdTailwaterDepthWarning then
1325 self.showTailwaterDepthWarning = true
1326 if tailwaterDepth > self.thresholdTailwaterDepth then
1327 self:setBroken()
1328 end
1329 end
1330 end
1331
1332 local rootAttacherVehicle = self:getRootVehicle()
1333 if rootAttacherVehicle ~= nil and rootAttacherVehicle ~= self then
1334 rootAttacherVehicle.showTailwaterDepthWarning = rootAttacherVehicle.showTailwaterDepthWarning or self.showTailwaterDepthWarning
1335 end
1336 end
1337
1338 if self:getIsOperating() then
1339 self:setOperatingTime(self.operatingTime + dt)
1340 end
1341
1342 SpecializationUtil.raiseEvent(self, "onUpdateTick", dt, isActiveForInput, isSelected)
1343 SpecializationUtil.raiseEvent(self, "onPostUpdateTick", dt, isActiveForInput, isSelected)
1344end

drawUIInfo

Description
Draw UI info
Definition
drawUIInfo()
Code
1371function Vehicle:drawUIInfo()
1372 if g_showVehicleDistance then
1373 local dist = calcDistanceFrom(self.rootNode, getCamera())
1374 if dist <= 350 then
1375 Utils.renderTextAtWorldPosition(x,y+1,z, string.format("%.0f", dist), getCorrectTextSize(0.02), 0)
1376 end
1377 end
1378end

addNodeObjectMapping

Description
Add component nodes to list
Definition
addNodeObjectMapping(table list)
Arguments
tablelistlist
Code
1396function Vehicle:addNodeObjectMapping(list)
1397 for _,v in pairs(self.components) do
1398 list[v.node] = self
1399 end
1400end

removeNodeObjectMapping

Description
Remove component nodes from list
Definition
removeNodeObjectMapping(table list)
Arguments
tablelistlist
Code
1405function Vehicle:removeNodeObjectMapping(list)
1406 for _,v in pairs(self.components) do
1407 list[v.node] = nil
1408 end
1409end

addToPhysics

Description
Add vehicle to physics
Definition
addToPhysics()
Return Values
booleansuccesssuccess
Code
1414function Vehicle:addToPhysics()
1415
1416 if not self.isAddedToPhysics then
1417 local lastMotorizedNode = nil
1418 for _, component in pairs(self.components) do
1419 addToPhysics(component.node)
1420 if component.motorized then
1421 if lastMotorizedNode ~= nil then
1422 if self.isServer then
1423 addVehicleLink(lastMotorizedNode, component.node)
1424 end
1425 end
1426 lastMotorizedNode = component.node
1427 end
1428 end
1429
1430 self.isAddedToPhysics = true
1431
1432 if self.isServer then
1433 for _, jointDesc in pairs(self.componentJoints) do
1434 self:createComponentJoint(self.components[jointDesc.componentIndices[1]], self.components[jointDesc.componentIndices[2]], jointDesc)
1435 end
1436
1437 -- if rootnode is sleeping all other components are sleeping as well
1438 addWakeUpReport(self.rootNode, "onVehicleWakeUpCallback", self)
1439 end
1440
1441 for _, collisionPair in pairs(self.collisionPairs) do
1442 setPairCollision(collisionPair.component1.node, collisionPair.component2.node, collisionPair.enabled)
1443 end
1444
1445 self:setMassDirty()
1446 end
1447
1448 return true
1449end

removeFromPhysics

Description
Remove vehicle from physics
Definition
removeFromPhysics()
Code
1453function Vehicle:removeFromPhysics()
1454 for _, component in pairs(self.components) do
1455 removeFromPhysics(component.node)
1456 end
1457 -- invalidate wheel shapes and component joints (removing the components removes the wheels and joints too)
1458 if self.isServer then
1459 for _, jointDesc in pairs(self.componentJoints) do
1460 jointDesc.jointIndex = 0
1461 end
1462 removeWakeUpReport(self.rootNode)
1463 end
1464 self.isAddedToPhysics = false
1465
1466 return true
1467end

setRelativePosition

Description
Set relative position of vehicle
Definition
setRelativePosition(float positionX, float offsetY, float positionZ, float yRot)
Arguments
floatpositionXx position
floatoffsetYy offset
floatpositionZz position
floatyRoty rotation
Code
1475function Vehicle:setRelativePosition(positionX, offsetY, positionZ, yRot)
1476 -- position the vehicle
1477 local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, positionX, 300, positionZ)
1478
1479 self:setAbsolutePosition(positionX, terrainHeight+offsetY, positionZ, 0, yRot, 0)
1480end

setWorldPosition

Description
Set world position and rotation of component
Definition
setWorldPosition(float x, float y, float z, float xRot, float yRot, float zRot, integer i, boolean changeInterp)
Arguments
floatxx position
floatyy position
floatzz position
floatxRotx rotation
floatyRoty rotation
floatzRotz rotation
integeriindex if component
booleanchangeInterpchange interpolation
Code
1524function Vehicle:setWorldPosition(x,y,z, xRot,yRot,zRot, i, changeInterp)
1525 local component = self.components[i]
1526 setWorldTranslation(component.node, x,y,z)
1527 setWorldRotation(component.node, xRot,yRot,zRot)
1528 if changeInterp then
1529 local qx, qy, qz, qw = mathEulerToQuaternion(xRot,yRot,zRot)
1530 component.networkInterpolators.quaternion:setQuaternion(qx, qy, qz, qw)
1531 component.networkInterpolators.position:setPosition(x,y,z)
1532 end
1533end

setWorldPositionQuaternion

Description
Set world position and quaternion rotation of component
Definition
setWorldPositionQuaternion(float x, float y, float z, float qx, float qy, float qz, float qw, integer i, boolean changeInterp)
Arguments
floatxx position
floatyy position
floatzz position
floatqxx rotation
floatqyy rotation
floatqzz rotation
floatqww rotation
integeriindex if component
booleanchangeInterpchange interpolation
Code
1546function Vehicle:setWorldPositionQuaternion(x,y,z, qx,qy,qz,qw, i, changeInterp)
1547 local component = self.components[i]
1548 setWorldTranslation(component.node, x,y,z)
1549 setWorldQuaternion(component.node, qx,qy,qz,qw)
1550 if changeInterp then
1551 component.networkInterpolators.quaternion:setQuaternion(qx, qy, qz, qw)
1552 component.networkInterpolators.position:setPosition(x,y,z)
1553 end
1554end

getPrice

Description
Returns price
Definition
getPrice(float price)
Arguments
floatpriceprice
Code
1578function Vehicle:getPrice()
1579 return self.price
1580end

getSellPrice

Description
Get sell price
Definition
getSellPrice()
Return Values
floatsellPricesell price
Code
1585function Vehicle:getSellPrice()
1586 local priceMultiplier = 0.75
1587 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
1588 local maxVehicleAge = storeItem.lifetime
1589
1590 if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then
1591 local ageMultiplier = 0.5 * math.min(self.age/maxVehicleAge, 1)
1592 local operatingTime = self.operatingTime / (1000*60*60)
1593 local operatingTimeMultiplier = 0.5 * math.min(operatingTime / (maxVehicleAge*EconomyManager.LIFETIME_OPERATINGTIME_RATIO), 1)
1594 priceMultiplier = priceMultiplier * math.exp(-3.5 * (ageMultiplier+operatingTimeMultiplier))
1595 end
1596
1597 return math.max(math.floor(self:getPrice() * math.max(priceMultiplier, 0.05)) - self:getRepairPrice(true), 0)
1598end

getIsOnField

Description
Returns true if vehicle is on a field
Definition
getIsOnField()
Return Values
booleanisOnFieldis on field
Code
1603function Vehicle:getIsOnField()
1604 local densityBits = 0
1605 for _,component in pairs(self.components) do
1606 local wx, wy, wz = getWorldTranslation(component.node)
1607
1608 local h = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, wx, wy, wz)
1609 if h-1 > wy then -- 1m threshold since ground tools are working slightly under the ground
1610 break
1611 end
1612
1613 local bits = getDensityAtWorldPos(g_currentMission.terrainDetailId, wx, wy, wz)
1614 densityBits = bitOR(densityBits, bits)
1615 if densityBits ~= 0 then
1616 return true
1617 end
1618 end
1619
1620 return false
1621end

getParentComponent

Description
Get parent component of node
Definition
getParentComponent(integer node)
Arguments
integernodeid of node
Return Values
integerparentComponentid of parent component node
Code
1627function Vehicle:getParentComponent(node)
1628 while node ~= 0 do
1629 if self:getIsVehicleNode(node) then
1630 return node
1631 end
1632 node = getParent(node)
1633 end
1634 return 0
1635end

getLastSpeed

Description
Returns last speed in kph
Definition
getLastSpeed(boolean useAttacherVehicleSpeed)
Arguments
booleanuseAttacherVehicleSpeeduse speed of attacher vehicle
Return Values
floatlastSpeedlast speed
Code
1641function Vehicle:getLastSpeed(useAttacherVehicleSpeed)
1642 if useAttacherVehicleSpeed then
1643 if self.attacherVehicle ~= nil then
1644 return self.attacherVehicle:getLastSpeed(true)
1645 end
1646 end
1647
1648 return self.lastSpeed * 3600
1649end

getOwner

Description
Get owner of vehicle
Definition
getOwner()
Return Values
tableownerowner
Code
1659function Vehicle:getOwner()
1660 if self.owner ~= nil then
1661 return self.owner
1662 end
1663
1664 return nil
1665end

getActiveFarm

Description
Get the active farm. Preferable the one of the controlling player. Otherwise the owner.
Definition
getActiveFarm()
Return Values
integer

getIsVehicleNode

Description
Returns true if node is from vehicle
Definition
getIsVehicleNode(integer nodeId)
Arguments
integernodeIdnode id
Return Values
booleanisFromVehicleis from vehicle
Code
1677function Vehicle:getIsVehicleNode(nodeId)
1678 return self.vehicleNodes[nodeId] ~= nil
1679end

getIsOperating

Description
Returns true if is operating
Definition
getIsOperating()
Return Values
booleanisOperatingis operating
Code
1684function Vehicle:getIsOperating()
1685 return false
1686end

getTotalMass

Description
Returns total mass of vehicle (optional including attached vehicles)
Definition
getTotalMass(boolean onlyGivenVehicle)
Arguments
booleanonlyGivenVehicleuse only the given vehicle, if false or nil it includes all attachables
Return Values
floattotalMasstotal mass
Code
2070function Vehicle:getTotalMass(onlyGivenVehicle)
2071 if self.isServer then
2072 local mass = 0
2073
2074 for _, component in ipairs(self.components) do
2075 mass = mass + component.mass
2076 end
2077
2078 return mass
2079 end
2080
2081 return 0
2082end

getFillLevelInformation

Description
Get fill level information
Definition
getFillLevelInformation(table fillLevelInformations)
Arguments
tablefillLevelInformationsfill level informations
Code
2087function Vehicle:getFillLevelInformation(fillLevelInformations)
2088end

activate

Description
Called on activate
Definition
activate()
Code
2092function Vehicle:activate()
2093 SpecializationUtil.raiseEvent(self, "onActivate")
2094end

deactivate

Description
Called on deactivate
Definition
deactivate()
Code
2098function Vehicle:deactivate()
2099 if self:getDeactivateOnLeave() then
2100 SpecializationUtil.raiseEvent(self, "onDeactivate")
2101 end
2102end

setComponentJointFrame

Description
Set component joint frame
Definition
setComponentJointFrame(integer jointDesc, integer anchorActor)
Arguments
integerjointDescjoint desc index
integeranchorActoranchor actor
Code
2109function Vehicle:setComponentJointFrame(jointDesc, anchorActor)
2110 if anchorActor == 0 then
2111 local localPoses = jointDesc.jointLocalPoses[1]
2112 localPoses.trans[1], localPoses.trans[2], localPoses.trans[3] = localToLocal(jointDesc.jointNode, self.components[jointDesc.componentIndices[1]].node, 0, 0, 0)
2113 localPoses.rot[1], localPoses.rot[2], localPoses.rot[3] = localRotationToLocal(jointDesc.jointNode, self.components[jointDesc.componentIndices[1]].node, 0, 0, 0)
2114 else
2115 local localPoses = jointDesc.jointLocalPoses[2]
2116 localPoses.trans[1], localPoses.trans[2], localPoses.trans[3] = localToLocal(jointDesc.jointNodeActor1, self.components[jointDesc.componentIndices[2]].node, 0, 0, 0)
2117 localPoses.rot[1], localPoses.rot[2], localPoses.rot[3] = localRotationToLocal(jointDesc.jointNodeActor1, self.components[jointDesc.componentIndices[2]].node, 0, 0, 0)
2118 end
2119
2120 local jointNode = jointDesc.jointNode
2121 if anchorActor == 1 then
2122 jointNode = jointDesc.jointNodeActor1
2123 end
2124
2125 if jointDesc.jointIndex ~= 0 then
2126 setJointFrame(jointDesc.jointIndex, anchorActor, jointNode)
2127 end
2128end

setComponentJointRotLimit

Description
Set component joint rot limit
Definition
setComponentJointRotLimit(integer componentJoint, integer axis, float minLimit, float maxLimit)
Arguments
integercomponentJointindex of component joint
integeraxisaxis
floatminLimitmin limit
floatmaxLimitmax limit
Code
2137function Vehicle:setComponentJointRotLimit(componentJoint, axis, minLimit, maxLimit)
2138 if self.isServer then
2139 componentJoint.rotLimit[axis] = maxLimit
2140 componentJoint.rotMinLimit[axis] = minLimit
2141
2142 if componentJoint.jointIndex ~= 0 then
2143 if minLimit <= maxLimit then
2144 setJointRotationLimit(componentJoint.jointIndex, axis-1, true, minLimit, maxLimit)
2145 else
2146 setJointRotationLimit(componentJoint.jointIndex, axis-1, false, 0, 0)
2147 end
2148 end
2149 end
2150end

setComponentJointTransLimit

Description
Set component joint trans limit
Definition
setComponentJointTransLimit(integer componentJoint, integer axis, float minLimit, float maxLimit)
Arguments
integercomponentJointindex of component joint
integeraxisaxis
floatminLimitmin limit
floatmaxLimitmax limit
Code
2158function Vehicle:setComponentJointTransLimit(componentJoint, axis, minLimit, maxLimit)
2159 if self.isServer then
2160 componentJoint.transLimit[axis] = maxLimit
2161 componentJoint.transMinLimit[axis] = minLimit
2162
2163 if componentJoint.jointIndex ~= 0 then
2164 if minLimit <= maxLimit then
2165 setJointTranslationLimit(componentJoint.jointIndex, axis-1, true, minLimit, maxLimit)
2166 else
2167 setJointTranslationLimit(componentJoint.jointIndex, axis-1, false, 0, 0)
2168 end
2169 end
2170 end
2171end

loadComponentFromXML

Description
Load component from xml
Definition
loadComponentFromXML(table component, integer xmlFile, string key, table rootPosition, integer i)
Arguments
tablecomponentcomponent
integerxmlFileid of xml object
stringkeykey
tablerootPositionroot position (x, y, z)
integericomponent index
Return Values
booleansuccesssuccess
Code
2181function Vehicle:loadComponentFromXML(component, xmlFile, key, rootPosition, i)
2182 if not self.isServer then
2183 if getRigidBodyType(component.node) == "Dynamic" then
2184 setRigidBodyType(component.node, "Kinematic")
2185 end
2186 end
2187 link(getRootNode(), component.node)
2188 if i == 1 then
2189 rootPosition[1], rootPosition[2], rootPosition[3] = getTranslation(component.node)
2190 if rootPosition[2] ~= 0 then
2191 g_logManager:xmlWarning(self.configFileName, "Y-Translation of component 1 (node 0>) has to be 0. Current value is: %.5f", rootPosition[2])
2192 end
2193 end
2194
2195 if getRigidBodyType(component.node) == "Static" then
2196 component.isStatic = true
2197 elseif getRigidBodyType(component.node) == "Kinematic" then
2198 component.isKinematic = true
2199 elseif getRigidBodyType(component.node) == "Dynamic" then
2200 component.isDynamic = true
2201 end
2202
2203 -- the position of the first component is the zero
2204 translate(component.node, -rootPosition[1], -rootPosition[2], -rootPosition[3])
2205 local x,y,z = getTranslation(component.node)
2206 local rx,ry,rz = getRotation(component.node)
2207 component.originalTranslation = {x,y,z}
2208 component.originalRotation = {rx,ry,rz}
2209
2210 component.sentTranslation = {x,y,z}
2211 component.sentRotation = {rx,ry,rz}
2212
2213 component.defaultMass = nil
2214 component.mass = nil
2215
2216 local mass = getXMLFloat(xmlFile, key.."#mass")
2217 if mass ~= nil then
2218 if mass < 10 then
2219 g_logManager:xmlDevWarning(self.configFileName, "Mass is lower than 10kg for '%s'. Mass unit is kilogramms. Is this correct?", key)
2220 end
2221 if component.isDynamic then
2222 setMass(component.node, mass/1000)
2223 end
2224
2225 component.defaultMass = mass/1000
2226 component.mass = component.defaultMass
2227 component.lastMass = component.mass
2228 else
2229 g_logManager:xmlWarning(self.configFileName, "Missing 'mass' for '%s'. Using default mass 500kg instead!", key)
2230 component.defaultMass = 0.5
2231 component.mass = 0.5
2232 component.lastMass = component.mass
2233 end
2234
2235 local comStr = getXMLString(xmlFile, key .. "#centerOfMass");
2236 if comStr ~= nil then
2237 local com = StringUtil.getVectorNFromString(comStr, 3)
2238 if com ~= nil then
2239 setCenterOfMass(component.node, com[1], com[2], com[3])
2240 else
2241 g_logManager:xmlWarning(self.configFileName, "Invalid center of mass given for '%s'. Ignoring this definition", key)
2242 end
2243 end
2244 local count = getXMLInt(xmlFile, key .. "#solverIterationCount")
2245 if count ~= nil then
2246 setSolverIterationCount(component.node, count)
2247 component.solverIterationCount = count
2248 end
2249 component.motorized = getXMLBool(xmlFile, key .. "#motorized") -- Note: motorized is nil if not set in the xml, and can be set by the wheels
2250 self.vehicleNodes[component.node] = {component=component}
2251 local clipDistance = getClipDistance(component.node)
2252 if clipDistance >= 1000000 and getVisibility(component.node) then
2253 local defaultClipdistance = 300
2254 g_logManager:xmlWarning(self.configFileName, "No clipdistance is set to component node '%s' (%s>). Set default clipdistance '%d'", getName(component.node), i-1, defaultClipdistance)
2255 setClipDistance(component.node, defaultClipdistance)
2256 end
2257
2258 component.collideWithAttachables = Utils.getNoNil(getXMLBool(xmlFile, key.."#collideWithAttachables"), false)
2259
2260 if getRigidBodyType(component.node) ~= "NoRigidBody" then
2261 if getLinearDamping(component.node) > 0.01 then
2262 g_logManager:xmlDevWarning(self.configFileName, "Non-zero linear damping (%.4f) for component node '%s' (%s>). Is this correct?", getLinearDamping(component.node), getName(component.node), i-1)
2263 elseif getAngularDamping(component.node) > 0.05 then
2264 g_logManager:xmlDevWarning(self.configFileName, "Large angular damping (%.4f) for component node '%s' (%s>). Is this correct?", getAngularDamping(component.node), getName(component.node), i-1)
2265 elseif getAngularDamping(component.node) < 0.0001 then
2266 g_logManager:xmlDevWarning(self.configFileName, "Zero damping for component node '%s' (%s>). Is this correct?", getName(component.node), i-1)
2267 end
2268 end
2269
2270 local name = getName(component.node)
2271 if not StringUtil.endsWith(name, "component"..i) then
2272 g_logManager:xmlDevWarning(self.configFileName, "Name of component '%d' ('%s') does not correpond with the component naming convention! (vehicleName_componentName_component%d)", i, name, i)
2273 end
2274
2275 return true
2276end

loadComponentJointFromXML

Description
Load component joints from xml
Definition
loadComponentJointFromXML(table jointDesc, integer xmlFile, string key, integer componentJointI, integer jointNode, integer index1, integer index2)
Arguments
tablejointDescjoint desc
integerxmlFileid of xml object
stringkeykey
integercomponentJointIcomponent joint index
integerjointNodeid of joint node
integerindex1index of component 1
integerindex2index of component 2
Return Values
booleansuccesssuccess
Code
2288function Vehicle:loadComponentJointFromXML(jointDesc, xmlFile, key, componentJointI, jointNode, index1, index2)
2289 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, key .. "#indexActor1", key .. "#nodeActor1") --FS17 to FS19
2290
2291 jointDesc.componentIndices = {index1, index2}
2292 jointDesc.jointNode = jointNode
2293 jointDesc.jointNodeActor1 = Utils.getNoNil(I3DUtil.indexToObject(self.components, getXMLString(xmlFile, key.."#nodeActor1"), self.i3dMappings), jointNode)
2294 if self.isServer then
2295 if self.components[index1] == nil or self.components[index2] == nil then
2296 g_logManager:xmlWarning(self.configFileName, "Invalid component indices (component1: %d, component2: %d) for component joint %d. Indices start with 1!", index1, index2, componentJointI)
2297 return false
2298 end
2299
2300 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotLimit"))
2301 local rotLimits = { math.rad(Utils.getNoNil(x, 0)), math.rad(Utils.getNoNil(y, 0)), math.rad(Utils.getNoNil(z, 0)) }
2302 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transLimit"))
2303 local transLimits = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2304 jointDesc.rotLimit = rotLimits
2305 jointDesc.transLimit = transLimits
2306
2307 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotMinLimit"))
2308 local rotMinLimits = { Utils.getNoNilRad(x, nil), Utils.getNoNilRad(y, nil), Utils.getNoNilRad(z, nil) }
2309
2310 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transMinLimit"))
2311 local transMinLimits = { x,y,z }
2312
2313 for i=1,3 do
2314 if rotMinLimits[i] == nil then
2315 if rotLimits[i] >= 0 then
2316 rotMinLimits[i] = -rotLimits[i]
2317 else
2318 rotMinLimits[i] = rotLimits[i]+1
2319 end
2320 end
2321 if transMinLimits[i] == nil then
2322 if transLimits[i] >= 0 then
2323 transMinLimits[i] = -transLimits[i]
2324 else
2325 transMinLimits[i] = transLimits[i]+1
2326 end
2327 end
2328 end
2329
2330 jointDesc.jointLocalPoses = {}
2331 local trans = {localToLocal(jointDesc.jointNode, self.components[index1].node, 0, 0, 0)}
2332 local rot = {localRotationToLocal(jointDesc.jointNode, self.components[index1].node, 0, 0, 0)}
2333 jointDesc.jointLocalPoses[1] = {trans=trans, rot=rot}
2334
2335 local trans = {localToLocal(jointDesc.jointNodeActor1, self.components[index2].node, 0, 0, 0)}
2336 local rot = {localRotationToLocal(jointDesc.jointNodeActor1, self.components[index2].node, 0, 0, 0)}
2337 jointDesc.jointLocalPoses[2] = {trans=trans, rot=rot}
2338
2339 jointDesc.rotMinLimit = rotMinLimits
2340 jointDesc.transMinLimit = transMinLimits
2341
2342 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotLimitSpring"))
2343 local rotLimitSpring = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2344 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotLimitDamping"))
2345 local rotLimitDamping = { Utils.getNoNil(x, 1), Utils.getNoNil(y, 1), Utils.getNoNil(z, 1) }
2346 jointDesc.rotLimitSpring = rotLimitSpring
2347 jointDesc.rotLimitDamping = rotLimitDamping
2348
2349 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotLimitForceLimit"))
2350 local rotLimitForceLimit = { Utils.getNoNil(x, -1), Utils.getNoNil(y, -1), Utils.getNoNil(z, -1) }
2351 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transLimitForceLimit"))
2352 local transLimitForceLimit = { Utils.getNoNil(x, -1), Utils.getNoNil(y, -1), Utils.getNoNil(z, -1) }
2353 jointDesc.rotLimitForceLimit = rotLimitForceLimit
2354 jointDesc.transLimitForceLimit = transLimitForceLimit
2355
2356 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transLimitSpring"))
2357 local transLimitSpring = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2358 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transLimitDamping"))
2359 local transLimitDamping = { Utils.getNoNil(x, 1), Utils.getNoNil(y, 1), Utils.getNoNil(z, 1) }
2360 jointDesc.transLimitSpring = transLimitSpring
2361 jointDesc.transLimitDamping = transLimitDamping
2362
2363 jointDesc.zRotationXOffset = 0
2364 local zRotationNode = I3DUtil.indexToObject(self.components, getXMLString(xmlFile, key.."#zRotationNode"), self.i3dMappings)
2365 if zRotationNode ~= nil then
2366 jointDesc.zRotationXOffset,_,_ = localToLocal(zRotationNode, jointNode, 0,0,0)
2367 end
2368
2369 jointDesc.isBreakable = Utils.getNoNil(getXMLBool(xmlFile, key.."#breakable"), false)
2370 if jointDesc.isBreakable then
2371 jointDesc.breakForce = Utils.getNoNil(getXMLFloat(xmlFile, key.."#breakForce"), 10)
2372 jointDesc.breakTorque = Utils.getNoNil(getXMLFloat(xmlFile, key.."#breakTorque"), 10)
2373 end
2374 jointDesc.enableCollision = Utils.getNoNil(getXMLBool(xmlFile, key.."#enableCollision"), false)
2375
2376 -- Rotational drive
2377 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#maxRotDriveForce"))
2378 local maxRotDriveForce = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2379 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotDriveVelocity"))
2380 local rotDriveVelocity = { Utils.getNoNilRad(x, nil), Utils.getNoNilRad(y, nil), Utils.getNoNilRad(z, nil) } -- convert from deg/s to rad/s
2381 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotDriveRotation"))
2382 local rotDriveRotation = { Utils.getNoNilRad(x, nil), Utils.getNoNilRad(y, nil), Utils.getNoNilRad(z, nil) } -- convert from deg to rad
2383 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotDriveSpring"))
2384 local rotDriveSpring = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2385 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#rotDriveDamping"))
2386 local rotDriveDamping = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2387
2388 jointDesc.rotDriveVelocity = rotDriveVelocity
2389 jointDesc.rotDriveRotation = rotDriveRotation
2390 jointDesc.rotDriveSpring = rotDriveSpring
2391 jointDesc.rotDriveDamping = rotDriveDamping
2392 jointDesc.maxRotDriveForce = maxRotDriveForce
2393
2394 -- Translational drive
2395 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transDriveVelocity"))
2396 local transDriveVelocity = { x,y,z }
2397
2398 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transDrivePosition"))
2399 local transDrivePosition = { x,y,z }
2400
2401 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transDriveSpring"))
2402 local transDriveSpring = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2403
2404 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#transDriveDamping"))
2405 local transDriveDamping = { Utils.getNoNil(x, 1), Utils.getNoNil(y, 1), Utils.getNoNil(z, 1) }
2406
2407 local x, y, z = StringUtil.getVectorFromString(getXMLString(xmlFile, key.."#maxTransDriveForce"))
2408 local maxTransDriveForce = { Utils.getNoNil(x, 0), Utils.getNoNil(y, 0), Utils.getNoNil(z, 0) }
2409
2410 jointDesc.transDriveVelocity = transDriveVelocity
2411 jointDesc.transDrivePosition = transDrivePosition
2412 jointDesc.transDriveSpring = transDriveSpring
2413 jointDesc.transDriveDamping = transDriveDamping
2414 jointDesc.maxTransDriveForce = maxTransDriveForce
2415
2416 jointDesc.jointIndex = 0
2417 end
2418
2419 return true
2420end

createComponentJoint

Description
Create component joint between two components
Definition
createComponentJoint(table component1, table component2, table jointDesc)
Arguments
tablecomponent1component 1
tablecomponent2component 2
tablejointDescjoint desc
Return Values
booleansuccesssuccess
Code
2428function Vehicle:createComponentJoint(component1, component2, jointDesc)
2429 if component1 == nil or component2 == nil or jointDesc == nil then
2430 g_logManager:xmlWarning(self.configFileName, "Could not create component joint. No component1, component2 or jointDesc given!")
2431 return false
2432 end
2433
2434 local constr = JointConstructor:new()
2435 constr:setActors(component1.node, component2.node)
2436
2437 local localPoses1 = jointDesc.jointLocalPoses[1]
2438 local localPoses2 = jointDesc.jointLocalPoses[2]
2439 constr:setJointLocalPositions(localPoses1.trans[1], localPoses1.trans[2], localPoses1.trans[3], localPoses2.trans[1], localPoses2.trans[2], localPoses2.trans[3])
2440 constr:setJointLocalRotations(localPoses1.rot[1], localPoses1.rot[2], localPoses1.rot[3], localPoses2.rot[1], localPoses2.rot[2], localPoses2.rot[3])
2441 --constr:setJointTransforms(jointDesc.jointNode, jointDesc.jointNodeActor1)
2442
2443 constr:setRotationLimitSpring(jointDesc.rotLimitSpring[1], jointDesc.rotLimitDamping[1], jointDesc.rotLimitSpring[2], jointDesc.rotLimitDamping[2], jointDesc.rotLimitSpring[3], jointDesc.rotLimitDamping[3])
2444 constr:setTranslationLimitSpring(jointDesc.transLimitSpring[1], jointDesc.transLimitDamping[1], jointDesc.transLimitSpring[2], jointDesc.transLimitDamping[2], jointDesc.transLimitSpring[3], jointDesc.transLimitDamping[3])
2445 constr:setZRotationXOffset(jointDesc.zRotationXOffset)
2446 for i=1, 3 do
2447 if jointDesc.rotLimit[i] >= jointDesc.rotMinLimit[i] then
2448 constr:setRotationLimit(i-1, jointDesc.rotMinLimit[i], jointDesc.rotLimit[i])
2449 end
2450
2451 if jointDesc.transLimit[i] >= jointDesc.transMinLimit[i] then
2452 constr:setTranslationLimit(i-1, true, jointDesc.transMinLimit[i], jointDesc.transLimit[i])
2453 else
2454 constr:setTranslationLimit(i-1, false, 0, 0)
2455 end
2456 end
2457
2458 constr:setRotationLimitForceLimit(jointDesc.rotLimitForceLimit[1], jointDesc.rotLimitForceLimit[2], jointDesc.rotLimitForceLimit[3])
2459 constr:setTranslationLimitForceLimit(jointDesc.transLimitForceLimit[1], jointDesc.transLimitForceLimit[2], jointDesc.transLimitForceLimit[3])
2460
2461 if jointDesc.isBreakable then
2462 constr:setBreakable(jointDesc.breakForce, jointDesc.breakTorque)
2463 end
2464 constr:setEnableCollision(jointDesc.enableCollision)
2465
2466 for i=1,3 do
2467 if jointDesc.maxRotDriveForce[i] > 0.0001 and (jointDesc.rotDriveVelocity[i] ~= nil or jointDesc.rotDriveRotation[i] ~= nil) then
2468 local pos = Utils.getNoNil(jointDesc.rotDriveRotation[i], 0)
2469 local vel = Utils.getNoNil(jointDesc.rotDriveVelocity[i], 0)
2470 constr:setAngularDrive(i-1, jointDesc.rotDriveRotation[i] ~= nil, jointDesc.rotDriveVelocity[i] ~= nil, jointDesc.rotDriveSpring[i], jointDesc.rotDriveDamping[i], jointDesc.maxRotDriveForce[i], pos, vel)
2471 end
2472 if jointDesc.maxTransDriveForce[i] > 0.0001 and (jointDesc.transDriveVelocity[i] ~= nil or jointDesc.transDrivePosition[i] ~= nil) then
2473 local pos = Utils.getNoNil(jointDesc.transDrivePosition[i], 0)
2474 local vel = Utils.getNoNil(jointDesc.transDriveVelocity[i], 0)
2475 constr:setLinearDrive(i-1, jointDesc.transDrivePosition[i] ~= nil, jointDesc.transDriveVelocity[i] ~= nil, jointDesc.transDriveSpring[i], jointDesc.transDriveDamping[i], jointDesc.maxTransDriveForce[i], pos, vel)
2476 end
2477 end
2478
2479 jointDesc.jointIndex = constr:finalize()
2480
2481 return true
2482end

prefixSchemaOverlayName

Description
Add a mod prefix to a schema overlay name to match name loading in HUD which avoids name collisions.
First checks if there is a matching default schema overlay name and only adds the prefix if there is none.
Definition
prefixSchemaOverlayName(string baseName, string prefix)
Arguments
stringbaseNameBase schema overlay name
stringprefixName prefix to add if the baseName parameter is not one of the default schema overlays
Return Values
stringSchemaoverlay name which was modified if necessary

loadSchemaOverlay

Description
Load schema overlay data from xml file
The HUD draws the schema from this information and handles all required visual components.
Definition
loadSchemaOverlay(integer xmlFile)
Arguments
integerxmlFileid of xml object
Code
2502function Vehicle:loadSchemaOverlay(xmlFile)
2503 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#file") --FS17 to FS19
2504 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#width") --FS17 to FS19
2505 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#height") --FS17 to FS19
2506 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#invisibleBorderRight", "vehicle.base.schemaOverlay#invisibleBorderRight") --FS17 to FS19
2507 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#invisibleBorderLeft", "vehicle.base.schemaOverlay#invisibleBorderLeft") --FS17 to FS19
2508 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#attacherJointPosition", "vehicle.base.schemaOverlay#attacherJointPosition") --FS17 to FS19
2509 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#basePosition", "vehicle.base.schemaOverlay#basePosition") --FS17 to FS19
2510 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#fileSelected") --FS17 to FS19
2511 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#fileTurnedOn") --FS17 to FS19
2512 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.schemaOverlay#fileSelectedTurnedOn") --FS17 to FS19
2513
2514 if hasXMLProperty(xmlFile, "vehicle.base.schemaOverlay") then
2515 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, "vehicle.schemaOverlay.attacherJoint", "vehicle.attacherJoints.attacherJoint.schema") -- FS17
2516
2517 local x, y = StringUtil.getVectorFromString(getXMLString(xmlFile, "vehicle.base.schemaOverlay#attacherJointPosition"))
2518 local baseX, baseY = StringUtil.getVectorFromString(getXMLString(xmlFile, "vehicle.base.schemaOverlay#basePosition"))
2519
2520 if baseX == nil then
2521 baseX = x
2522 end
2523
2524 if baseY == nil then
2525 baseY = y
2526 end
2527
2528 local schemaNameDefault = getXMLString(xmlFile, "vehicle.base.schemaOverlay.default#name") or ""
2529 local schemaNameTurnedOn = getXMLString(xmlFile, "vehicle.base.schemaOverlay.turnedOn#name") or ""
2530 local schemaNameSelected = getXMLString(xmlFile, "vehicle.base.schemaOverlay.selected#name") or ""
2531 local schemaNameSelectedTurnedOn = getXMLString(xmlFile, "vehicle.base.schemaOverlay.turnedOnSelected#name") or ""
2532
2533 local modPrefix = self.customEnvironment or ""
2534 schemaNameDefault = Vehicle.prefixSchemaOverlayName(schemaNameDefault, modPrefix)
2535 schemaNameTurnedOn = Vehicle.prefixSchemaOverlayName(schemaNameTurnedOn, modPrefix)
2536 schemaNameSelected = Vehicle.prefixSchemaOverlayName(schemaNameSelected, modPrefix)
2537 schemaNameSelectedTurnedOn = Vehicle.prefixSchemaOverlayName(schemaNameSelectedTurnedOn, modPrefix)
2538
2539 self.schemaOverlay = VehicleSchemaOverlayData.new(
2540 baseX, baseY,
2541 schemaNameDefault,
2542 schemaNameTurnedOn,
2543 schemaNameSelected,
2544 schemaNameSelectedTurnedOn,
2545 getXMLFloat(xmlFile, "vehicle.base.schemaOverlay#invisibleBorderRight"),
2546 getXMLFloat(xmlFile, "vehicle.base.schemaOverlay#invisibleBorderLeft"))
2547 end
2548end

dayChanged

Description
Called if day changed
Definition
dayChanged()
Code
2556function Vehicle:dayChanged()
2557 self.age = self.age + 1
2558end

getSpeedLimit

Description
Get speed limit
Definition
getSpeedLimit(boolean onlyIfWorking)
Arguments
booleanonlyIfWorkingonly if working
Return Values
floatlimitlimit
booleandoCheckSpeedLimitdo check speed limit
Code
2641function Vehicle:getSpeedLimit(onlyIfWorking)
2642 local limit = math.huge
2643 local doCheckSpeedLimit = self:doCheckSpeedLimit()
2644 if onlyIfWorking == nil or (onlyIfWorking and doCheckSpeedLimit) then
2645 limit = self.speedLimit
2646
2647 local damage = self:getVehicleDamage()
2648 if damage > 0 then
2649 limit = limit * (1 - damage * Vehicle.DAMAGED_SPEEDLIMIT_REDUCTION)
2650 end
2651 end
2652
2653 local attachedImplements
2654 if self.getAttachedImplements ~= nil then
2655 attachedImplements = self:getAttachedImplements()
2656 end
2657 if attachedImplements ~= nil then
2658 for _, implement in pairs(attachedImplements) do
2659 if implement.object ~= nil then
2660 local speed, implementDoCheckSpeedLimit = implement.object:getSpeedLimit(onlyIfWorking)
2661 if onlyIfWorking == nil or (onlyIfWorking and implementDoCheckSpeedLimit) then
2662 limit = math.min(limit, speed)
2663 end
2664 doCheckSpeedLimit = doCheckSpeedLimit or implementDoCheckSpeedLimit
2665 end
2666 end
2667 end
2668 return limit, doCheckSpeedLimit
2669end

getDailyUpkeep

Description
Get daily up keep
Definition
getDailyUpkeep()
Return Values
floatdailyUpkeepdaily up keep
Code
2682function Vehicle:getDailyUpkeep()
2683 local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
2684
2685 local multiplier = 1
2686 if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then
2687 local ageMultiplier = 0.3 * math.min(self.age/storeItem.lifetime, 1)
2688 local operatingTime = self.operatingTime / (1000*60*60)
2689 local operatingTimeMultiplier = 0.7 * math.min(operatingTime / (storeItem.lifetime*EconomyManager.LIFETIME_OPERATINGTIME_RATIO), 1)
2690 multiplier = 1 + EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * (ageMultiplier+operatingTimeMultiplier)
2691 end
2692
2693 return StoreItemUtil.getDailyUpkeep(storeItem, self.configurations) * multiplier
2694end

getReloadXML

Description
Get reload xml
Definition
getReloadXML(table vehicle)
Arguments
tablevehiclevehicle
Return Values
stringxmlxml
Code
2767function Vehicle.getReloadXML(vehicle)
2768
2769 local vehicleXMLFile = createXMLFile("vehicleXMLFile", "", "vehicles")
2770 if vehicleXMLFile ~= nil then
2771 local key = string.format("vehicles.vehicle(%d)", 0)
2772
2773 setXMLInt(vehicleXMLFile, key.."#id", 1)
2774 setXMLString(vehicleXMLFile, key.."#filename", HTMLUtil.encodeToHTML(NetworkUtil.convertToNetworkFilename(vehicle.configFileName)))
2775
2776 vehicle:saveToXMLFile(vehicleXMLFile, key, {})
2777
2778 return vehicleXMLFile
2779 end
2780
2781 return nil
2782end

VehicleCamera

Description

new

Description
Creating vehicle camera
Definition
new(boolean isServer, boolean isClient, table customMt)
Arguments
booleanisServeris server
booleanisClientis client
tablecustomMtcustom metatable
Return Values
tableinstanceInstance of object
Code
23function VehicleCamera:new(vehicle, customMt)
24
25 local instance = {}
26 if customMt ~= nil then
27 setmetatable(instance, customMt)
28 else
29 setmetatable(instance, VehicleCamera_mt)
30 end
31
32
33 instance.vehicle = vehicle
34 instance.isActivated = false
35
36 instance.limitRotXDelta = 0
37
38 instance.raycastDistance = 0
39 instance.normalX = 0
40 instance.normalY = 0
41 instance.normalZ = 0
42
43 instance.raycastNodes = {}
44 instance.disableCollisionTime = -1
45
46 instance.lookAtPosition = {0,0,0}
47 instance.lookAtLastTargetPosition = {0,0,0}
48 instance.position = {0,0,0}
49 instance.lastTargetPosition = {0,0,0}
50
51 instance.lastInputValues = {}
52 instance.lastInputValues.upDown = 0
53 instance.lastInputValues.leftRight = 0
54
55 instance.isCollisionEnabled = not g_modIsLoaded["disableVehicleCameraCollision"]
56
57 return instance
58end

loadFromXML

Description
Load vehicle camera from xml file
Definition
loadFromXML(integer xmlFile, string key)
Arguments
integerxmlFileid of xml object
stringkeykey
Return Values
booleansuccesssuccess
Code
65function VehicleCamera:loadFromXML(xmlFile, key)
66 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.vehicle.configFileName, key .. "#index", "#node") -- FS17 to FS19
67
68 local camIndexStr = getXMLString(xmlFile, key .. "#node")
69 self.cameraNode = I3DUtil.indexToObject(self.vehicle.components, camIndexStr, self.vehicle.i3dMappings)
70 if self.cameraNode == nil or not getHasClassId(self.cameraNode, ClassIds.CAMERA) then
71 g_logManager:xmlWarning(self.vehicle.configFileName, "Invalid camera node for camera '%s'. Must be a camera type!", key)
72 return false
73 end
74
75 self.fovY = calculateFovY(self.cameraNode)
76 setFovY(self.cameraNode, self.fovY)
77
78 self.isRotatable = Utils.getNoNil(getXMLBool(xmlFile, key .. "#rotatable"), false)
79 self.limit = Utils.getNoNil(getXMLBool(xmlFile, key .. "#limit"), false)
80 if self.limit then
81 self.rotMinX = getXMLFloat(xmlFile, key .. "#rotMinX")
82 self.rotMaxX = getXMLFloat(xmlFile, key .. "#rotMaxX")
83
84 self.transMin = getXMLFloat(xmlFile, key .. "#transMin")
85 self.transMax = getXMLFloat(xmlFile, key .. "#transMax")
86 if self.rotMinX == nil or self.rotMaxX == nil or self.transMin == nil or self.transMax == nil then
87 g_logManager:xmlWarning(self.vehicle.configFileName, "Missing 'rotMinX', 'rotMaxX', 'transMin' or 'transMax' for camera '%s'", key)
88 return false
89 end
90 end
91
92 self.isInside = Utils.getNoNil(getXMLBool(xmlFile, key .. "#isInside"), false)
93 if self.isInside then
94 self.defaultLowPassGain = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#defaultLowPassGain"), 0.5)
95 self.defaultVolume = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#defaultVolume"), 0.9)
96 else
97 self.defaultLowPassGain = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#defaultLowPassGain"), 1.0)
98 self.defaultVolume = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#defaultVolume"), 1.0)
99 end
100 self.allowHeadTracking = Utils.getNoNil(getXMLBool(xmlFile, key .. "#allowHeadTracking"), self.isInside)
101
102 local shadowBoxIndexStr = getXMLString(xmlFile, key .. "#shadowFocusBox")
103 self.shadowFocusBoxNode = I3DUtil.indexToObject(self.vehicle.components, shadowBoxIndexStr, self.vehicle.i3dMappings)
104 if self.shadowFocusBoxNode ~= nil and not getHasClassId(self.shadowFocusBoxNode, ClassIds.SHAPE) then
105 g_logManager:xmlWarning(self.vehicle.configFileName, "Invalid camera shadow focus box '%s'. Must be a shape and cpu mesh", getName(shadowFocusBoxNode))
106 self.shadowFocusBoxNode = nil;
107 end
108
109 if self.isInside and self.shadowFocusBoxNode == nil then
110 g_logManager:xmlDevWarning(self.vehicle.configFileName, "Missing shadow focus box for indoor camera '%s'", key)
111 end
112
113 self.useOutdoorSounds = Utils.getNoNil(getXMLBool(xmlFile, key .. "#useOutdoorSounds"), not self.isInside)
114
115 if self.isRotatable then
116 self.rotateNode = I3DUtil.indexToObject(self.vehicle.components, getXMLString(xmlFile, key .. "#rotateNode"), self.vehicle.i3dMappings)
117 self.hasExtraRotationNode = self.rotateNode ~= nil
118 end
119
120 local rotation = StringUtil.getRadiansFromString(getXMLString(xmlFile, key.."#rotation"), 3)
121 if rotation ~= nil then
122 local rotationNode = self.cameraNode
123 if self.rotateNode ~= nil then
124 rotationNode = self.rotateNode
125 end
126 setRotation(rotationNode, unpack(rotation))
127 end
128 local translation = StringUtil.getVectorNFromString(getXMLString(xmlFile, key.."#translation"), 3)
129 if translation ~= nil then
130 setTranslation(self.cameraNode, unpack(translation))
131 end
132
133 self.allowTranslation = (self.rotateNode ~= nil and self.rotateNode ~= self.cameraNode)
134
135 self.useMirror = Utils.getNoNil(getXMLBool(xmlFile, key .. "#useMirror"), false)
136 self.useWorldXZRotation = getXMLBool(xmlFile, key .. "#useWorldXZRotation") -- overrides the ingame setting
137 self.resetCameraOnVehicleSwitch = getXMLBool(xmlFile, key .. "#resetCameraOnVehicleSwitch") -- overrides the ingame setting
138
139 self.positionSmoothingParameter = 0
140 self.lookAtSmoothingParameter = 0
141 local useDefaultPositionSmoothing = Utils.getNoNil(getXMLBool(xmlFile, key .. "#useDefaultPositionSmoothing"), true)
142 if useDefaultPositionSmoothing then
143 if self.isInside then
144 self.positionSmoothingParameter = 0.128 -- 0.095
145 self.lookAtSmoothingParameter = 0.176 -- 0.12
146 else
147 self.positionSmoothingParameter = 0.016
148 self.lookAtSmoothingParameter = 0.022
149 end
150 end
151 self.positionSmoothingParameter = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#positionSmoothingParameter"), self.positionSmoothingParameter)
152 self.lookAtSmoothingParameter = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#lookAtSmoothingParameter"), self.lookAtSmoothingParameter)
153
154 local useHeadTracking = g_gameSettings:getValue("isHeadTrackingEnabled") and isHeadTrackingAvailable() and self.allowHeadTracking
155 if useHeadTracking then
156 self.positionSmoothingParameter = 0
157 self.lookAtSmoothingParameter = 0
158 end
159
160 self.cameraPositionNode = self.cameraNode
161 if self.positionSmoothingParameter > 0 then
162 -- create a node which indicates the target position of the camera
163 self.cameraPositionNode = createTransformGroup("cameraPositionNode")
164 local camIndex = getChildIndex(self.cameraNode)
165 link(getParent(self.cameraNode), self.cameraPositionNode, camIndex)
166 local x,y,z = getTranslation(self.cameraNode)
167 local rx,ry,rz = getRotation(self.cameraNode)
168 setTranslation(self.cameraPositionNode, x,y,z)
169 setRotation(self.cameraPositionNode, rx,ry,rz)
170
171 unlink(self.cameraNode)
172 end
173 self.rotYSteeringRotSpeed = math.rad(Utils.getNoNil(getXMLFloat(xmlFile, key .. "#rotYSteeringRotSpeed"), 0))
174
175 if self.rotateNode == nil or self.rotateNode == self.cameraNode then
176 self.rotateNode = self.cameraPositionNode
177 end
178
179 if useHeadTracking then
180 local dx,dy,dz = localDirectionToLocal(self.cameraPositionNode, getParent(self.cameraPositionNode), 0,0,1)
181 local tx,ty,tz = localToLocal(self.cameraPositionNode, getParent(self.cameraPositionNode), 0,0,0)
182 self.headTrackingNode = createTransformGroup("headTrackingNode")
183 link(getParent(self.cameraPositionNode), self.headTrackingNode)
184 setTranslation(self.headTrackingNode, tx,ty,tz)
185 if math.abs(dx)+math.abs(dz) > 0.0001 then
186 setDirection(self.headTrackingNode, dx, dy, dz, 0,1,0)
187 else
188 setRotation(self.headTrackingNode, 0,0,0)
189 end
190 end
191
192 self.origRotX, self.origRotY, self.origRotZ = getRotation(self.rotateNode)
193 self.rotX = self.origRotX
194 self.rotY = self.origRotY
195 self.rotZ = self.origRotZ
196
197 self.origTransX, self.origTransY, self.origTransZ = getTranslation(self.cameraPositionNode)
198 self.transX = self.origTransX
199 self.transY = self.origTransY
200 self.transZ = self.origTransZ
201
202 local transLength = MathUtil.vector3Length(self.origTransX, self.origTransY, self.origTransZ) + 0.00001 -- prevent devision by zero
203 self.zoom = transLength
204 self.zoomTarget = transLength
205 self.zoomLimitedTarget = -1
206
207 local trans1OverLength = 1.0/transLength
208 self.transDirX = trans1OverLength*self.origTransX
209 self.transDirY = trans1OverLength*self.origTransY
210 self.transDirZ = trans1OverLength*self.origTransZ
211 if self.allowTranslation then
212 if transLength <= 0.01 then
213 g_logManager:xmlWarning(self.vehicle.configFileName, "Invalid camera translation for camera '%s'. Distance needs to be bigger than 0.01", key)
214 end
215 end
216
217 table.insert(self.raycastNodes, self.rotateNode)
218 local i=0
219 while true do
220 local raycastKey = key..string.format(".raycastNode(%d)", i)
221 if not hasXMLProperty(xmlFile, raycastKey) then
222 break
223 end
224
225 XMLUtil.checkDeprecatedXMLElements(xmlFile, self.vehicle.configFileName, raycastKey .. "#index", raycastKey .. "#node") --FS17 to FS19
226
227 local node = I3DUtil.indexToObject(self.vehicle.components, getXMLString(xmlFile, raycastKey .. "#node"), self.vehicle.i3dMappings)
228 if node ~= nil then
229 table.insert(self.raycastNodes, node)
230 end
231
232 i=i+1
233 end
234
235 local sx,sy,sz = getScale(self.cameraNode)
236 if sx ~= 1 or sy ~= 1 or sz ~= 1 then
237 g_logManager:xmlWarning(self.vehicle.configFileName, "Vehicle camera with scale found for camera '%s'. Resetting to scale 1", key)
238 setScale(self.cameraNode, 1,1,1)
239 end
240
241 self.headTrackingPositionOffset = {0, 0, 0}
242 self.headTrackingRotationOffset = {0, 0, 0}
243
244 return true
245end

delete

Description
Deleting vehicle camera
Definition
delete()
Code
249function VehicleCamera:delete()
250 if self.cameraNode ~= nil and self.positionSmoothingParameter > 0 then
251 delete(self.cameraNode)
252 self.cameraNode = nil
253 end
254 setShadowFocusBox(0)
255end

zoomSmoothly

Description
Zoom camera smoothly
Definition
zoomSmoothly(float offset)
Arguments
floatoffsetoffset
Code
260function VehicleCamera:zoomSmoothly(offset)
261 --self.zoomTarget = self.zoomTarget + offset
262 --if self.limit then
263 -- self.zoomTarget = math.min(self.transMax, math.max(self.transMin, self.zoomTarget))
264 --end
265 --self.zoomTarget = math.max(self.zoomTarget, 0.01)
266
267 local zoomTarget = self.zoomTarget
268 if self.transMin ~= nil and self.transMax ~= nil and self.transMin ~= self.transMax then
269 zoomTarget = math.min(self.transMax, math.max(self.transMin, self.zoomTarget + offset))
270 end
271 self.zoomTarget = zoomTarget
272
273end

raycastCallback

Description
Raycast callback
Definition
raycastCallback(integer transformId, float x, float y, float z, float distance, float nx, float ny, float nz)
Arguments
integertransformIdid raycasted object
floatxx raycast position
floatyy raycast position
floatzz raycast position
floatdistancedistance to raycast position
floatnxnormal x
floatnynormal y
floatnznormal z
Code
285function VehicleCamera:raycastCallback(transformId, x, y, z, distance, nx, ny, nz)
286 self.raycastDistance = distance
287 self.normalX = nx
288 self.normalY = ny
289 self.normalZ = nz
290 self.raycastTransformId = transformId
291end

update

Description
Update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
296function VehicleCamera:update(dt)
297 local target = self.zoomTarget
298 if self.zoomLimitedTarget >= 0 then
299 target = math.min(self.zoomLimitedTarget, self.zoomTarget)
300 end
301 self.zoom = target + ( math.pow(0.99579, dt) * (self.zoom - target) )
302
303 --
304 if self.lastInputValues.upDown ~= 0 then
305 local value = self.lastInputValues.upDown * g_gameSettings:getValue(GameSettings.SETTING.CAMERA_SENSITIVITY)
306 self.lastInputValues.upDown = 0
307
308 if self.isRotatable then
309 if self.isActivated and not g_gui:getIsGuiVisible() then
310 if self.limitRotXDelta > 0.001 then
311 self.rotX = math.min(self.rotX - value, self.rotX)
312 elseif self.limitRotXDelta < -0.001 then
313 self.rotX = math.max(self.rotX - value, self.rotX)
314 else
315 self.rotX = self.rotX - value
316 end
317
318 if self.limit then
319 self.rotX = math.min(self.rotMaxX, math.max(self.rotMinX, self.rotX))
320 end
321 end
322 end
323 end
324
325 if self.lastInputValues.leftRight ~= 0 then
326 local value = self.lastInputValues.leftRight * g_gameSettings:getValue(GameSettings.SETTING.CAMERA_SENSITIVITY)
327 self.lastInputValues.leftRight = 0
328
329 if self.isRotatable then
330 if self.isActivated and not g_gui:getIsGuiVisible() then
331 self.rotY = self.rotY - value
332 end
333 end
334 end
335
336 --
337 if g_gameSettings:getValue("isHeadTrackingEnabled") and isHeadTrackingAvailable() and self.allowHeadTracking and self.headTrackingNode ~= nil then
338 local tx,ty,tz = getHeadTrackingTranslation()
339 local pitch,yaw,roll = getHeadTrackingRotation()
340 if pitch ~= nil then
341 local camParent = getParent(self.cameraNode)
342 local ctx,cty,ctz;
343 local crx,cry,crz;
344 if camParent ~= 0 then
345 ctx, cty, ctz = localToLocal(self.headTrackingNode, camParent, tx, ty, tz);
346 crx, cry, crz = localRotationToLocal(self.headTrackingNode, camParent, pitch,yaw,roll);
347 else
348 ctx, cty, ctz = localToWorld(self.headTrackingNode, tx, ty, tz);
349 crx, cry, crz = localRotationToWorld(self.headTrackingNode, pitch,yaw,roll);
350 end
351
352 setRotation(self.cameraNode, crx, cry, crz)
353 setTranslation(self.cameraNode, ctx, cty, ctz)
354 end
355 else
356
357 self:updateRotateNodeRotation()
358
359
360 if self.limit then
361 -- adjust rotation to avoid clipping with terrain
362 if self.isRotatable and ((self.useWorldXZRotation == nil and g_gameSettings:getValue("useWorldCamera")) or self.useWorldXZRotation) then
363
364 local numIterations = 4
365 for i=1, numIterations do
366 local transX, transY, transZ = self.transDirX*self.zoom, self.transDirY*self.zoom, self.transDirZ*self.zoom
367 local x,y,z = localToWorld(getParent(self.cameraPositionNode), transX, transY, transZ)
368
369 local terrainHeight = DensityMapHeightUtil.getHeightAtWorldPos(x,0,z)
370
371 local minHeight = terrainHeight + 0.9
372 if y < minHeight then
373 local h = math.sin(self.rotX)*self.zoom
374 local h2 = h-(minHeight-y)
375 self.rotX = math.asin(MathUtil.clamp(h2/self.zoom, -1, 1))
376 self:updateRotateNodeRotation()
377 else
378 break
379 end
380 end
381 end
382
383 -- adjust zoom to avoid collision with objects
384 if self.allowTranslation then
385
386 self.limitRotXDelta = 0
387 local hasCollision, collisionDistance, nx,ny,nz, normalDotDir = self:getCollisionDistance()
388 if hasCollision then
389 local distOffset = 0.1
390 if normalDotDir ~= nil then
391 local absNormalDotDir = math.abs(normalDotDir)
392 distOffset = MathUtil.lerp(1.2, 0.1, absNormalDotDir*absNormalDotDir*(3-2*absNormalDotDir))
393 end
394 collisionDistance = math.max(collisionDistance-distOffset, 0.01)
395 self.disableCollisionTime = g_currentMission.time+400
396 self.zoomLimitedTarget = collisionDistance
397 if collisionDistance < self.zoom then
398 self.zoom = collisionDistance
399 end
400 if self.isRotatable and nx ~= nil and collisionDistance < self.transMin then
401 local _,lny,_ = worldDirectionToLocal(self.rotateNode, nx,ny,nz)
402 if lny > 0.5 then
403 self.limitRotXDelta = 1
404 elseif lny < -0.5 then
405 self.limitRotXDelta = -1
406 end
407 end
408 else
409 if self.disableCollisionTime <= g_currentMission.time then
410 self.zoomLimitedTarget = -1
411 end
412 end
413 end
414
415 end
416 self.transX, self.transY, self.transZ = self.transDirX*self.zoom, self.transDirY*self.zoom, self.transDirZ*self.zoom
417 setTranslation(self.cameraPositionNode, self.transX, self.transY, self.transZ)
418
419 if self.positionSmoothingParameter > 0 then
420
421 local interpDt = g_physicsDt
422 if g_server == nil then
423 -- on clients, we interpolate the vehicles with dt, thus we need to use the same for camera interpolation
424 interpDt = dt
425 end
426 if interpDt > 0 then
427 local xlook,ylook,zlook = getWorldTranslation(self.rotateNode)
428 local lookAtPos = self.lookAtPosition
429 local lookAtLastPos = self.lookAtLastTargetPosition
430 lookAtPos[1],lookAtPos[2],lookAtPos[3] = self:getSmoothed(self.lookAtSmoothingParameter, lookAtPos[1],lookAtPos[2],lookAtPos[3], xlook,ylook,zlook, lookAtLastPos[1],lookAtLastPos[2],lookAtLastPos[3], interpDt)
431 lookAtLastPos[1],lookAtLastPos[2],lookAtLastPos[3] = xlook,ylook,zlook
432
433 local x,y,z = getWorldTranslation(self.cameraPositionNode)
434 local pos = self.position
435 local lastPos = self.lastTargetPosition
436 pos[1],pos[2],pos[3] = self:getSmoothed(self.positionSmoothingParameter, pos[1],pos[2],pos[3], x,y,z, lastPos[1],lastPos[2],lastPos[3], interpDt)
437 lastPos[1],lastPos[2],lastPos[3] = x,y,z
438
439 self:setSeparateCameraPose()
440 end
441 end
442
443 end
444
445end

getSmoothed

Description
Get smooth camera position
Definition
getSmoothed(float alpha, float curX, float curY, float curZ, float targetX, float targetY, float targetZ, float lastTargetX, float lastTargetY, float lastTargetZ, float dt)
Arguments
floatalphaalpha
floatcurXcurrent x position
floatcurYcurrent y position
floatcurZcurrent z position
floattargetXtarget x position
floattargetYtarget y position
floattargetZtarget z position
floatlastTargetXlast target x position
floatlastTargetYlast target y position
floatlastTargetZlast target z position
floatdttime since last call in ms
Return Values
floatnewXnew x position
floatnewYnew y position
floatnewZnew z position

onActivate

Description
Called on activate
Definition
onActivate()
Code
495function VehicleCamera:onActivate()
496
497 self.isActivated = true
498 if (self.resetCameraOnVehicleSwitch == nil and g_gameSettings:getValue("resetCamera")) or self.resetCameraOnVehicleSwitch then
499 self:resetCamera()
500 end
501 setCamera(self.cameraNode)
502 if self.shadowFocusBoxNode then
503 setShadowFocusBox(self.shadowFocusBoxNode)
504 end
505
506 if self.positionSmoothingParameter > 0 then
507 local xlook,ylook,zlook = getWorldTranslation(self.rotateNode)
508 self.lookAtPosition[1] = xlook
509 self.lookAtPosition[2] = ylook
510 self.lookAtPosition[3] = zlook
511 self.lookAtLastTargetPosition[1] = xlook
512 self.lookAtLastTargetPosition[2] = ylook
513 self.lookAtLastTargetPosition[3] = zlook
514 local x,y,z = getWorldTranslation(self.cameraPositionNode)
515 self.position[1] = x
516 self.position[2] = y
517 self.position[3] = z
518 self.lastTargetPosition[1] = x
519 self.lastTargetPosition[2] = y
520 self.lastTargetPosition[3] = z
521
522
523 local rx,ry,rz = getWorldRotation(self.rotateNode)
524
525 setRotation(self.cameraNode, rx,ry,rz)
526 setTranslation(self.cameraNode, x,y,z)
527 end
528
529 self.lastInputValues = {}
530 self.lastInputValues.upDown = 0
531 self.lastInputValues.leftRight = 0
532
533 -- activate action event callbacks
534 local _, actionEventId1 = g_inputBinding:registerActionEvent(InputAction.AXIS_LOOK_UPDOWN_VEHICLE, self, VehicleCamera.actionEventLookUpDown, false, false, true, true, nil)
535 local _, actionEventId2 = g_inputBinding:registerActionEvent(InputAction.AXIS_LOOK_LEFTRIGHT_VEHICLE, self, VehicleCamera.actionEventLookLeftRight, false, false, true, true, nil)
536 g_inputBinding:setActionEventTextVisibility(actionEventId1, false)
537 g_inputBinding:setActionEventTextVisibility(actionEventId2, false)
538end

onDeactivate

Description
Called on deactivate
Definition
onDeactivate()
Code
542function VehicleCamera:onDeactivate()
543 self.isActivated = false
544 setShadowFocusBox(0)
545
546 -- remove action event callbacks
547 g_inputBinding:removeActionEventsByTarget(self)
548end

resetCamera

Description
Reset camera to original pose
Definition
resetCamera()
Code
571function VehicleCamera:resetCamera()
572 self.rotX = self.origRotX
573 self.rotY = self.origRotY
574 self.rotZ = self.origRotZ
575
576 self.transX = self.origTransX
577 self.transY = self.origTransY
578 self.transZ = self.origTransZ
579
580 local transLength = MathUtil.vector3Length(self.origTransX, self.origTransY, self.origTransZ)
581 self.zoom = transLength
582 self.zoomTarget = transLength
583 self.zoomLimitedTarget = -1
584
585 self:updateRotateNodeRotation()
586 setTranslation(self.cameraPositionNode, self.transX, self.transY, self.transZ)
587
588 if self.positionSmoothingParameter > 0 then
589 local xlook,ylook,zlook = getWorldTranslation(self.rotateNode)
590 self.lookAtPosition[1] = xlook
591 self.lookAtPosition[2] = ylook
592 self.lookAtPosition[3] = zlook
593 local x,y,z = getWorldTranslation(self.cameraPositionNode)
594 self.position[1] = x
595 self.position[2] = y
596 self.position[3] = z
597
598 self:setSeparateCameraPose()
599 end
600end

updateRotateNodeRotation

Description
Update rotation node rotation
Definition
updateRotateNodeRotation()
Code
604function VehicleCamera:updateRotateNodeRotation()
605 local rotY = self.rotY
606 if self.rotYSteeringRotSpeed ~= nil and self.rotYSteeringRotSpeed ~= 0 and self.vehicle.spec_articulatedAxis ~= nil and self.vehicle.spec_articulatedAxis.interpolatedRotatedTime ~= nil then
607 rotY = rotY + self.vehicle.spec_articulatedAxis.interpolatedRotatedTime*self.rotYSteeringRotSpeed
608 end
609
610 if (self.useWorldXZRotation == nil and g_gameSettings:getValue("useWorldCamera")) or self.useWorldXZRotation then
611 local upx,upy,upz = 0,1,0
612
613 local dx,_,dz = localDirectionToWorld(getParent(self.rotateNode), 0,0,1)
614 local invLen = 1/math.sqrt(dx*dx + dz*dz)
615 dx = dx*invLen
616 dz = dz*invLen
617
618
619
620 local newDx = math.cos(self.rotX) * (math.cos(rotY)*dx + math.sin(rotY)*dz)
621 local newDy = -math.sin(self.rotX)
622 local newDz = math.cos(self.rotX) * (-math.sin(rotY)*dx + math.cos(rotY)*dz)
623
624
625 newDx,newDy,newDz = worldDirectionToLocal(getParent(self.rotateNode), newDx,newDy,newDz)
626 upx,upy,upz = worldDirectionToLocal(getParent(self.rotateNode), upx,upy,upz)
627
628 -- worst case check
629 if math.abs(MathUtil.dotProduct(newDx,newDy,newDz, upx,upy,upz)) > ( 0.99 * MathUtil.vector3Length(newDx,newDy,newDz) * MathUtil.vector3Length(upx,upy,upz) ) then
630 setRotation(self.rotateNode, self.rotX, rotY, self.rotZ)
631 else
632 setDirection(self.rotateNode, newDx,newDy,newDz, upx,upy,upz)
633 end
634 else
635 setRotation(self.rotateNode, self.rotX, rotY, self.rotZ)
636 end
637end

setSeparateCameraPose

Description
Set separate camera pose
Definition
setSeparateCameraPose()
Code
641function VehicleCamera:setSeparateCameraPose()
642 if self.rotateNode ~= self.cameraPositionNode then
643 local dx = self.position[1] - self.lookAtPosition[1]
644 local dy = self.position[2] - self.lookAtPosition[2]
645 local dz = self.position[3] - self.lookAtPosition[3]
646
647 local upx,upy,upz = 0,1,0
648 if math.abs(dx) < 0.001 and math.abs(dz) < 0.001 then
649 upx = 0.1
650 end
651
652 setDirection(self.cameraNode, dx,dy,dz, upx,upy,upz)
653 else
654 local rx,ry,rz = getWorldRotation(self.rotateNode)
655 setRotation(self.cameraNode, rx,ry,rz)
656 end
657 setTranslation(self.cameraNode, self.position[1],self.position[2],self.position[3])
658end

getCollisionDistance

Description
Get distance to collision
Definition
getCollisionDistance()
Return Values
booleanhasCollisionhas collision
floatcollisionDistancedistance to collision
floatnormalXnormal x
floatnormalYnormal y
floatnormalZnormal z
floatnormalDotDirnormal dot direction
Code
668function VehicleCamera:getCollisionDistance()
669 if not self.isCollisionEnabled then
670 return false, nil, nil, nil, nil, nil
671 end
672
673 local raycastMask = 32+64+128+256+4096
674
675 local targetCamX, targetCamY, targetCamZ = localToWorld(self.rotateNode, self.transDirX*self.zoomTarget, self.transDirY*self.zoomTarget, self.transDirZ*self.zoomTarget)
676
677 local hasCollision = false
678 local collisionDistance = -1
679 local normalX,normalY,normalZ
680 local normalDotDir
681 for _, raycastNode in ipairs(self.raycastNodes) do
682
683 hasCollision = false
684
685 local nodeX, nodeY, nodeZ = getWorldTranslation(raycastNode)
686 local dirX, dirY, dirZ = targetCamX-nodeX, targetCamY-nodeY, targetCamZ-nodeZ
687 local dirLength = MathUtil.vector3Length(dirX, dirY, dirZ)
688 dirX = dirX / dirLength
689 dirY = dirY / dirLength
690 dirZ = dirZ / dirLength
691
692 local startX = nodeX
693 local startY = nodeY
694 local startZ = nodeZ
695 local currentDistance = 0
696 local minDistance = self.transMin
697
698 while true do
699 if (dirLength-currentDistance) <= 0 then
700 break
701 end
702 self.raycastDistance = 0
703 raycastClosest(startX, startY, startZ, dirX, dirY, dirZ, "raycastCallback", dirLength-currentDistance, self, raycastMask, true)
704
705 if self.raycastDistance ~= 0 then
706 currentDistance = currentDistance + self.raycastDistance+0.001
707 local ndotd = MathUtil.dotProduct(self.normalX, self.normalY, self.normalZ, dirX, dirY, dirZ)
708
709 local isAttachedVehicle = false
710 local object = g_currentMission:getNodeObject(self.raycastTransformId)
711 if object ~= nil then
712 if object ~= self.vehicle then
713 local attached1 = object.getIsAttachedTo ~= nil and object:getIsAttachedTo(self.vehicle)
714 local attached2 = self.vehicle.getIsAttachedTo ~= nil and self.vehicle:getIsAttachedTo(object)
715 isAttachedVehicle = attached1 or attached2
716
717 local mountObject = object.dynamicMountObject
718 if mountObject ~= nil and (mountObject == self.vehicle or mountObject:getRootVehicle() == self.vehicle) then
719 isAttachedVehicle = true
720 end
721 end
722 end
723
724 if isAttachedVehicle or object == self.vehicle then --isAttachedNode or isDynamicallyMounted then
725 if ndotd > 0 then
726 minDistance = math.max(minDistance, currentDistance)
727 end
728 else
729 hasCollision = true
730 -- we take the distance from the rotate node
731 if raycastNode == self.rotateNode then
732 normalX,normalY,normalZ = self.normalX, self.normalY, self.normalZ
733 collisionDistance = math.max(self.transMin, currentDistance)
734 normalDotDir = ndotd
735 end
736 break
737 end
738 startX = nodeX+dirX*currentDistance
739 startY = nodeY+dirY*currentDistance
740 startZ = nodeZ+dirZ*currentDistance
741 else
742 break
743 end
744 end
745 if not hasCollision then
746 break
747 end
748 end
749
750 return hasCollision, collisionDistance, normalX,normalY,normalZ, normalDotDir
751end

VehicleMotor

Description
Class for vehicle motors

new

Description
Creating new motor
Definition
new(integer minRpm, integer maxRpm, float maxForwardSpeed, float maxBackwardSpeed, table torqueCurve, float brakeForce, float forwardGearRatios, float backwardGearRatios, float minForwardGearRatio, float maxForwardGearRatio, float minBackwardGearRatio, float maxBackwardGearRatio, integer ptoMotorRpmRatio)
Arguments
integerminRpmmin rpm
integermaxRpmmax rpm
floatmaxForwardSpeedmax forward speed
floatmaxBackwardSpeedmax backward speed
tabletorqueCurvetorque curve (AnimCurve)
floatbrakeForcebrake force
floatforwardGearRatioslist of gear ratios to use when driving forwards (in decreasing order)
floatbackwardGearRatioslist of gear ratios to use when driving backwards (in decreasing order)
floatminForwardGearRatiomin forward gear ratio
floatmaxForwardGearRatiomax forward gear ratio
floatminBackwardGearRatiomin backward gear ratio
floatmaxBackwardGearRatiomax backward gear ratio
integerptoMotorRpmRatiopto motor rpm ratio
Return Values
tablemotorInstancemotor instance
Code
36function VehicleMotor:new(vehicle, minRpm, maxRpm, maxForwardSpeed, maxBackwardSpeed, torqueCurve, brakeForce, forwardGearRatios, backwardGearRatios, minForwardGearRatio, maxForwardGearRatio, minBackwardGearRatio, maxBackwardGearRatio, ptoMotorRpmRatio, minSpeed)
37
38 local self = {}
39 setmetatable(self, VehicleMotor_mt)
40
41 self.vehicle = vehicle
42 self.minRpm = minRpm
43 self.maxRpm = maxRpm
44 self.minSpeed = minSpeed
45 self.maxForwardSpeed = maxForwardSpeed -- speed in m/s
46 self.maxBackwardSpeed = maxBackwardSpeed
47
48 self.maxClutchTorque = 5 -- amount of torque that can be transferred from motor to clutch/wheels [t m s^-2]
49
50 self.torqueCurve = torqueCurve
51 self.brakeForce = brakeForce
52
53 self.gear = 0
54 self.minGearRatio = 0
55 self.maxGearRatio = 0
56
57 self.forwardGearRatios = forwardGearRatios
58 self.backwardGearRatios = backwardGearRatios
59 self.minForwardGearRatio = minForwardGearRatio
60 self.maxForwardGearRatio = maxForwardGearRatio
61 self.minBackwardGearRatio = minBackwardGearRatio
62 self.maxBackwardGearRatio = maxBackwardGearRatio
63
64 self.manualTargetGear = nil
65 self.targetGear = 0
66 self.previousGear = 0
67 self.gearChangeTimer = -1
68 self.gearChangeTime = 250
69 self.autoGearChangeTimer = -1
70 self.autoGearChangeTime = 1000
71
72 self.lastRealMotorRpm = 0
73 self.lastMotorRpm = 0
74
75 self.rpmLimit = math.huge
76 self.speedLimit = math.huge -- Speed limit in km/h
77 self.speedLimitAcc = math.huge
78
79 self.accelerationLimit = 2 -- m s^-2
80
81 self.equalizedMotorRpm = 0
82
83 self.requiredMotorPower = 0
84
85 if self.maxForwardSpeed == nil then
86 self.maxForwardSpeed = self:calculatePhysicalMaximumForwardSpeed()
87 end
88 if self.maxBackwardSpeed == nil then
89 self.maxBackwardSpeed = self:calculatePhysicalMaximumBackwardSpeed()
90 end
91
92 self.peakMotorTorque = self.torqueCurve:getMaximum()
93
94 -- Calculate peak power. Assume we have a linear interpolation on the torque values
95 -- For each segment, find the maximum power (D[torque(x, i) * x] == 0) and take the maximum segment
96 -- D[ ((x-x0) / (x1-x0) (y1-y0) + y0) x] == 0
97 -- -> (x1 y0 - x0 y1) / (2 (y0 - y1)) if y0 != y1
98 self.peakMotorPower = 0
99 self.peakMotorPowerRotSpeed = 0
100 local numKeyFrames = #self.torqueCurve.keyframes
101 if numKeyFrames >= 2 then
102 for i=2,numKeyFrames do
103 local v0 = self.torqueCurve.keyframes[i-1]
104 local v1 = self.torqueCurve.keyframes[i]
105 local torque0 = self.torqueCurve:getFromKeyframes(v0, v0, i-1, i-1, 0)
106 local torque1 = self.torqueCurve:getFromKeyframes(v1, v1, i, i, 0)
107 local rpm, torque
108 if math.abs(torque0 - torque1) > 0.0001 then
109 rpm = (v1.time * torque0 - v0.time * torque1) / (2.0 * (torque0 - torque1))
110 rpm = math.min(math.max(rpm, v0.time), v1.time)
111 torque = self.torqueCurve:getFromKeyframes(v0, v1, i-1, i, (v1.time - rpm) / (v1.time - v0.time))
112 else
113 rpm = v0.time
114 torque = torque0
115 end
116 local power = torque * rpm
117 if power > self.peakMotorPower then
118 self.peakMotorPower = power
119 self.peakMotorPowerRotSpeed = rpm
120 end
121 end
122 -- Convert from rpm to rad/s
123 self.peakMotorPower = self.peakMotorPower * math.pi/30
124 self.peakMotorPowerRotSpeed = self.peakMotorPowerRotSpeed * math.pi/30
125 else
126 local v = self.torqueCurve.keyframes[1]
127 local rotSpeed = v.time*math.pi/30
128 local torque = self.torqueCurve:getFromKeyframes(v, v, i, i, 0)
129 self.peakMotorPower = rotSpeed*torque
130 self.peakMotorPowerRotSpeed = rotSpeed
131 end
132
133 self.ptoMotorRpmRatio = ptoMotorRpmRatio
134
135 self.rotInertia = 0.001 -- Rotational inertia of the motor, mostly defined by the flywheel [t m^2]
136 self.dampingRateFullThrottle = 0.00015 -- Damping rate of the motor if the acceleration pedal is 1 [t m^2 s^-1]
137 self.dampingRateZeroThrottleClutchEngaged = 0.003 -- Damping rate of the motor if the acceleration pedal is 0 and the clutch is engaged [t m^2 s^-1]
138 self.dampingRateZeroThrottleClutchDisengaged = 0.001 -- Damping rate of the motor if the acceleration pedal is 0 and the clutch is disengaged [t m^2 s^-1]
139
140
141
142 -- Motor properties as read from the physics engine
143 self.gearRatio = 0
144 self.motorRotSpeed = 0 -- motor rotation speed [rad/s]
145 self.motorRotAcceleration = 0 -- motor rotation acceleration [rad/s^2]
146 self.motorRotAccelerationSmoothed = 0 -- motor rotation acceleration smoothed [rad/s^2]
147
148 self.motorAvailableTorque = 0 -- torque that was available to the physics simulation [kN == t m/s^2]
149 self.motorAppliedTorque = 0 -- torque that was applied (<= available), can be smaller when acceleration/speed is limited [kN == t m/s^2]
150 self.motorExternalTorque = 0 -- torque that was removed from the motor and was not applied to the wheels (e.g. PTO) [kN == t m/s^2]
151
152 self.differentialRotSpeed = 0 -- rotation speed of the main differential [rad/s]
153 self.differentialRotAcceleration = 0 -- rotation accleration of the main differential [rad/s^2]
154 self.differentialRotAccelerationSmoothed = 0 -- smoothed rotation accleration of the main differential [rad/s^2]
155
156 return self
157end

setLowBrakeForce

Description
Set low brake force
Definition
setLowBrakeForce(float lowBrakeForceScale, float lowBrakeForceSpeedLimit)
Arguments
floatlowBrakeForceScalelow brake force scale
floatlowBrakeForceSpeedLimitlow brake force speed limit
Code
163function VehicleMotor:setLowBrakeForce(lowBrakeForceScale, lowBrakeForceSpeedLimit)
164 self.lowBrakeForceScale = lowBrakeForceScale
165 self.lowBrakeForceSpeedLimit = lowBrakeForceSpeedLimit
166end

getMaxClutchTorque

Description
Returns max clutch torque
Definition
getMaxClutchTorque()
Return Values
floatmaxClutchTorquemax clutch torque
Code
171function VehicleMotor:getMaxClutchTorque()
172 return self.maxClutchTorque
173end

getRotInertia

Description
Returns rotation inertia
Definition
getRotInertia()
Return Values
floatrotInertiarotation inertia
Code
178function VehicleMotor:getRotInertia()
179 return self.rotInertia
180end

setRotInertia

Description
Sets rotation inertia
Definition
setRotInertia(float rotInertia)
Arguments
floatrotInertiarotation inertia
Code
185function VehicleMotor:setRotInertia(rotInertia)
186 self.rotInertia = rotInertia
187end

getDampingRateFullThrottle

Description
Returns the damping rate of the motor if the acceleration pedal is 1
Definition
getDampingRateFullThrottle()
Return Values
floatdampingRatedamping rate [t m^2 s^-1]
Code
192function VehicleMotor:getDampingRateFullThrottle()
193 return self.dampingRateFullThrottle
194end

getDampingRateZeroThrottleClutchEngaged

Description
Returns the damping rate of the motor if the acceleration pedal is 0 and the clutch is engaged
Definition
getDampingRateZeroThrottleClutchEngaged()
Return Values
floatdampingRatedamping rate [t m^2 s^-1]
Code
199function VehicleMotor:getDampingRateZeroThrottleClutchEngaged()
200 return self.dampingRateZeroThrottleClutchEngaged
201end

getDampingRateZeroThrottleClutchDisengaged

Description
Returns the damping rate of the motor if the acceleration pedal is 0 and the clutch is disengaged
Definition
getDampingRateZeroThrottleClutchDisengaged()
Return Values
floatdampingRatedamping rate [t m^2 s^-1]
Code
206function VehicleMotor:getDampingRateZeroThrottleClutchDisengaged()
207 return self.dampingRateZeroThrottleClutchDisengaged
208end

setDampingRateFullThrottle

Description
Sets the damping rate of the motor if the acceleration pedal is 1
Definition
setDampingRateFullThrottle(float dampingRate)
Arguments
floatdampingRatenew damping rate [t m^2 s^-1]
Code
213function VehicleMotor:setDampingRateFullThrottle(dampingRate)
214 self.dampingRateFullThrottle = dampingRate
215end

setDampingRateZeroThrottleClutchEngaged

Description
Sets the damping rate of the motor if the acceleration pedal is 0 and the clutch is engaged
Definition
setDampingRateZeroThrottleClutchEngaged(float dampingRate)
Arguments
floatdampingRatenew damping rate [t m^2 s^-1]
Code
220function VehicleMotor:setDampingRateZeroThrottleClutchEngaged(dampingRate)
221 self.dampingRateZeroThrottleClutchEngaged = dampingRate
222end

setDampingRateZeroThrottleClutchDisengaged

Description
Sets the damping rate of the motor if the acceleration pedal is 0 and the clutch is disengaged
Definition
setDampingRateZeroThrottleClutchDisengaged(float dampingRate)
Arguments
floatdampingRatenew damping rate [t m^2 s^-1]
Code
227function VehicleMotor:setDampingRateZeroThrottleClutchDisengaged(dampingRate)
228 self.dampingRateZeroThrottleClutchDisengaged = dampingRate
229end

setGearChangeTime

Description
Sets the time it takes change gears
Definition
setGearChangeTime(float gearChangeTime)
Arguments
floatgearChangeTimegear change time [ms]
Code
234function VehicleMotor:setGearChangeTime(gearChangeTime)
235 self.gearChangeTime = gearChangeTime
236 self.gearChangeTimer = math.min(self.gearChangeTimer, gearChangeTime)
237end

setAutoGearChangeTime

Description
Sets the time that needs to pass since the last gear change until an automatic gear change is allowed
Definition
setAutoGearChangeTime(float autoGearChangeTime)
Arguments
floatautoGearChangeTimeautomatic gear change time [ms]
Code
242function VehicleMotor:setAutoGearChangeTime(autoGearChangeTime)
243 self.autoGearChangeTime = autoGearChangeTime
244 self.autoGearChangeTimer = math.min(self.autoGearChangeTimer, autoGearChangeTime)
245end

getPeakTorque

Description
Returns max torque
Definition
getPeakTorque()
Return Values
floatmaxMotorTorquemax motor torque
Code
250function VehicleMotor:getPeakTorque()
251 return self.peakMotorTorque
252end

getBrakeForce

Description
Returns brake force
Definition
getBrakeForce()
Return Values
floatbrakeForcebrake force
Code
257function VehicleMotor:getBrakeForce()
258 return self.brakeForce
259end

getMinRpm

Description
Returns min rpm
Definition
getMinRpm()
Return Values
floatminRpmmin rpm
Code
264function VehicleMotor:getMinRpm()
265 return self.minRpm
266end

getMaxRpm

Description
Returns max rpm
Definition
getMaxRpm()
Return Values
floatmaxRpmmax rpm
Code
271function VehicleMotor:getMaxRpm()
272 return self.maxRpm
273end

getRequiredMotorRpmRange

Description
Returns the currently required motor rpm range (e.g. defined by the activated pto)
Definition
getRequiredMotorRpmRange()
Return Values
floatminRequiredRpmmin required rpm
floatminRequiredRpmmax required rpm
Code
279function VehicleMotor:getRequiredMotorRpmRange()
280 local motorPtoRpm = math.min(PowerConsumer.getMaxPtoRpm(self.vehicle)*self.ptoMotorRpmRatio, self.maxRpm)
281 if motorPtoRpm ~= 0 then
282 return motorPtoRpm, motorPtoRpm
283 end
284 return self.minRpm, self.maxRpm
285end

getLastMotorRpm

Description
Returns last motor rpm damped
Definition
getLastMotorRpm()
Return Values
floatlastMotorRpmlast motor rpm
Code
290function VehicleMotor:getLastMotorRpm()
291 return self.lastMotorRpm
292end

getLastRealMotorRpm

Description
Returns last motor rpm real
Definition
getLastRealMotorRpm()
Return Values
floatlastMotorRpmlast motor rpm
Code
297function VehicleMotor:getLastRealMotorRpm()
298 return self.lastRealMotorRpm
299end

setLastRpm

Description
Sets last motor rpm
Definition
setLastRpm(float lastRpm)
Arguments
floatlastRpmnew last motor rpm
Code
304function VehicleMotor:setLastRpm(lastRpm)
305 self.lastRealMotorRpm = lastRpm
306
307 self.lastMotorRpm = self.lastMotorRpm * 0.95 + self.lastRealMotorRpm * 0.05
308end

getMotorAppliedTorque

Description
Returns the last applied torque to the motor
Definition
getMotorAppliedTorque()
Return Values
floatappliedTorquetorque [kN]
Code
313function VehicleMotor:getMotorAppliedTorque()
314 return self.motorAppliedTorque
315end

getMotorExternalTorque

Description
Returns the last applied external torque (torque used by external power consumers like the PTO)
Definition
getMotorExternalTorque()
Return Values
floatexternalTorqueexternal torque [kN]
Code
320function VehicleMotor:getMotorExternalTorque()
321 return self.motorExternalTorque
322end

getMotorAvailableTorque

Description
Returns the last total available motor torque
Definition
getMotorAvailableTorque()
Return Values
floattorqueexternal torque [kN]
Code
327function VehicleMotor:getMotorAvailableTorque()
328 return self.motorAvailableTorque
329end

getEqualizedMotorRpm

Description
Returns equalized motor rpm
Definition
getEqualizedMotorRpm()
Return Values
floatequalizedMotorRpmequalized motor rpm
Code
334function VehicleMotor:getEqualizedMotorRpm()
335 return self.equalizedMotorRpm
336end

setEqualizedMotorRpm

Description
Sets equalized motor rpm
Definition
setEqualizedMotorRpm(float equalizedMotorRpm)
Arguments
floatequalizedMotorRpmequalized motor rpm
Code
341function VehicleMotor:setEqualizedMotorRpm(rpm)
342 self.equalizedMotorRpm = rpm
343 self:setLastRpm(rpm)
344end

getPtoMotorRpmRatio

Description
Returns pto motor rpm ratio
Definition
getPtoMotorRpmRatio()
Return Values
floatptoMotorRpmRatiopto motor rpm ratio
Code
349function VehicleMotor:getPtoMotorRpmRatio()
350 return self.ptoMotorRpmRatio
351end

getNonClampedMotorRpm

Description
Returns non clamped motor rpm
Definition
getNonClampedMotorRpm()
Return Values
floatnonClampedMotorRpmnon clamped motor rpm
Code
356function VehicleMotor:getNonClampedMotorRpm()
357 return self.motorRotSpeed * 30 / math.pi
358end

getMotorRotSpeed

Description
Returns non clamped motor rpm
Definition
getMotorRotSpeed()
Return Values
floatnonClampedMotorRpmnon clamped motor rpm
Code
363function VehicleMotor:getMotorRotSpeed()
364 return self.motorRotSpeed
365end

getClutchRotSpeed

Description
Returns clutch rpm
Definition
getClutchRotSpeed()
Return Values
floatclutchRpmclutch rpm
Code
371function VehicleMotor:getClutchRotSpeed()
372 return self.differentialRotSpeed * self.gearRatio
373end

getTorqueCurve

Description
Returns torque curve
Definition
getTorqueCurve()
Return Values
tabletorqueCurvetorque curve
Code
378function VehicleMotor:getTorqueCurve()
379 return self.torqueCurve
380end

getTorque

Description
Returns torque of the motor at the current rpm with the given accelerator pedal
Definition
getTorque(float acceleration)
Arguments
floataccelerationacceleration
Return Values
floattorquetorque
Code
386function VehicleMotor:getTorque(acceleration)
387 -- Note: the torque curve is undefined outside the min/max rpm range. Clamping makes the curve flat at the outside range
388 local torque = self:getTorqueCurveValue(MathUtil.clamp(self.motorRotSpeed * 30/math.pi, self.minRpm, self.maxRpm))
389 torque = torque * math.abs(acceleration)
390 return torque
391end

getTorqueCurveValue

Description
Returns torque of the motor at the given rpm
Definition
getTorqueCurveValue(float rpm)
Arguments
floatrpmrpm
Return Values
floattorquetorque
Code
397function VehicleMotor:getTorqueCurveValue(rpm)
398 local damage = 1 - (self.vehicle:getVehicleDamage() * VehicleMotor.DAMAGE_TORQUE_REDUCTION)
399 return self:getTorqueCurve():get(rpm) * damage
400end

getMaximumForwardSpeed

Description
Returns maximum forward speed
Definition
getMaximumForwardSpeed()
Return Values
floatmaxForwardSpeedmaximum forward speed
Code
416function VehicleMotor:getMaximumForwardSpeed()
417 return self.maxForwardSpeed
418end

getMaximumBackwardSpeed

Description
Returns maximum backward speed
Definition
getMaximumBackwardSpeed()
Return Values
floatmaxBackwardSpeedmaximum backward speed
Code
423function VehicleMotor:getMaximumBackwardSpeed()
424 return self.maxBackwardSpeed
425end

calculatePhysicalMaximumForwardSpeed

Description
Returns physical maximum forward speed
Definition
calculatePhysicalMaximumForwardSpeed()
Return Values
floatphysicalMaxForwardSpeedphysical maximum forward speed
Code
430function VehicleMotor:calculatePhysicalMaximumForwardSpeed()
431 return VehicleMotor.calculatePhysicalMaximumSpeed(self.minForwardGearRatio, self.forwardGearRatios, self.maxRpm)
432end

calculatePhysicalMaximumBackwardSpeed

Description
Returns physical maximum backward speed
Definition
calculatePhysicalMaximumBackwardSpeed()
Return Values
floatphysicalMaxBackwardSpeedphysical maximum backward speed
Code
437function VehicleMotor:calculatePhysicalMaximumBackwardSpeed()
438 return VehicleMotor.calculatePhysicalMaximumSpeed(self.minBackwardGearRatio, self.backwardGearRatios, self.maxRpm)
439end

calculatePhysicalMaximumSpeed

Description
Returns physical maximum speed
Definition
calculatePhysicalMaximumSpeed(float minGearRatio, table gearRatios, integer maxRpm)
Arguments
floatminGearRatiomin gear ratio
tablegearRatiosgear ratios
integermaxRpmmax rpm
Return Values
floatphysicalMaxSpeedphysical maximum speed
Code
447function VehicleMotor.calculatePhysicalMaximumSpeed(minGearRatio, gearRatios, maxRpm)
448 local minRatio
449 if minGearRatio ~= nil then
450 minRatio = minGearRatio
451 else
452 minRatio = math.huge
453 for _, ratio in pairs(gearRatios) do
454 minRatio = math.min(minRatio, ratio)
455 end
456 end
457 return maxRpm * math.pi / (30 * minRatio)
458end

update

Description
Update the state of the motor (sync with physics simulation)
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
463function VehicleMotor:update(dt)
464 local vehicle = self.vehicle
465 if next(vehicle.spec_motorized.differentials) ~= nil and vehicle.spec_motorized.motorizedNode ~= nil then
466 -- Only update the physics values if a physics simulation was performed
467 if g_physicsDtNonInterpolated > 0.0 then
468 local lastMotorRotSpeed = self.motorRotSpeed;
469 local lastDiffRotSpeed = self.differentialRotSpeed
470 self.motorRotSpeed, self.differentialRotSpeed, self.gearRatio = getMotorRotationSpeed(vehicle.spec_motorized.motorizedNode)
471
472 self.motorAvailableTorque, self.motorAppliedTorque, self.motorExternalTorque = getMotorTorque(vehicle.spec_motorized.motorizedNode)
473
474
475 local motorRotAcceleration = (self.motorRotSpeed - lastMotorRotSpeed) / (g_physicsDtNonInterpolated*0.001)
476 self.motorRotAcceleration = motorRotAcceleration
477 self.motorRotAccelerationSmoothed = 0.8 * self.motorRotAccelerationSmoothed + 0.2 * motorRotAcceleration
478
479 local diffRotAcc = (self.differentialRotSpeed - lastDiffRotSpeed) / (g_physicsDtNonInterpolated*0.001)
480 self.differentialRotAcceleration = diffRotAcc
481 self.differentialRotAccelerationSmoothed = 0.8 * self.differentialRotAccelerationSmoothed + 0.2 * diffRotAcc
482
483 --print(string.format("update rpms: %.2f %.2f acc: %.2f", self.motorRotSpeed*30/math.pi, self.differentialRotSpeed*self.gearRatio*30/math.pi, motorRotAcceleration))
484 end
485
486 self.requiredMotorPower = math.huge
487
488 else
489 local _, gearRatio = self:getMinMaxGearRatio()
490 self.differentialRotSpeed = WheelsUtil.computeDifferentialRotSpeedNonMotor(vehicle)
491 self.motorRotSpeed = math.max(self.differentialRotSpeed * gearRatio, 0)
492 self.gearRatio = gearRatio
493 end
494
495 -- the clamped motor rpm always is higher-equal than the required rpm by the pto
496 --local ptoRpm = math.min(PowerConsumer.getMaxPtoRpm(self.vehicle)*self.ptoMotorRpmRatio, self.maxRpm)
497 -- smoothing for raise/fall of ptoRpm
498 if self.lastPtoRpm == nil then
499 self.lastPtoRpm = self.minRpm
500 end
501 local ptoRpm = PowerConsumer.getMaxPtoRpm(self.vehicle)*self.ptoMotorRpmRatio
502 if ptoRpm > self.lastPtoRpm then
503 self.lastPtoRpm = math.min(ptoRpm, self.lastPtoRpm + self.maxRpm*dt/2000)
504 elseif ptoRpm < self.lastPtoRpm then
505 self.lastPtoRpm = math.max(self.minRpm, self.lastPtoRpm - self.maxRpm*dt/1000)
506 end
507 local ptoRpm = math.min(self.lastPtoRpm, self.maxRpm)
508
509 local clampedMotorRpm = math.max(self.motorRotSpeed*30/math.pi, ptoRpm, self.minRpm)
510
511 self:setLastRpm(clampedMotorRpm)
512
513 self.equalizedMotorRpm = clampedMotorRpm
514end

getBestGearRatio

Description
Returns best gear ratio
Definition
getBestGearRatio(float wheelSpeedRpm, float minRatio, float maxRatio, float accSafeMotorRpm, float requiredMotorPower, float requiredMotorRpm)
Arguments
floatwheelSpeedRpmwheel speed rpm
floatminRatiomin ratio
floatmaxRatiomax ratio
floataccSafeMotorRpmacc save motor rpm
floatrequiredMotorPowerthe required motor power [kW] (can be bigger than what the motor can actually achieve)
floatrequiredMotorRpmfixed motor rpm to be used (if not 0)
Return Values
floatbestGearRatiobest gear ratio
Code
526function VehicleMotor:getBestGearRatio(wheelSpeedRpm, minRatio, maxRatio, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm)
527
528 if requiredMotorRpm ~= 0 then
529 local gearRatio = math.max(requiredMotorRpm-accSafeMotorRpm, requiredMotorRpm*0.8) / math.max(wheelSpeedRpm, 0.001)
530 gearRatio = MathUtil.clamp(gearRatio, minRatio, maxRatio)
531 return gearRatio
532 end
533
534 -- Use a minimum wheel rpm to avoid that gearRatio is ignored
535 wheelSpeedRpm = math.max(wheelSpeedRpm, 0.0001)
536
537 local bestMotorPower = 0
538 local bestGearRatio = minRatio
539 --local bestRPM = 0
540 -- TODO make this more efficient
541 for gearRatio = minRatio, maxRatio, 0.5 do
542 local motorRpm = wheelSpeedRpm * gearRatio
543 if motorRpm > self.maxRpm - accSafeMotorRpm then
544 break
545 end
546 local motorPower = self:getTorqueCurveValue(math.max(motorRpm, self.minRpm)) * motorRpm *math.pi/30
547 if motorPower > bestMotorPower then
548 bestMotorPower = motorPower
549 bestGearRatio = gearRatio
550 --bestRPM = motorRpm
551 end
552
553 if motorPower >= requiredMotorPower then
554 break
555 end
556 end
557 --print(string.format("Selected best gear: %f, %.2fkW rpm %.2f wheel %.2f", bestGearRatio, bestMotorPower, bestRPM, wheelSpeedRpm,))
558
559 return bestGearRatio
560end

getBestGear

Description
Returns best gear
Definition
getBestGear(float acceleration, float wheelSpeedRpm, float accSafeMotorRpm, float requiredMotorPower, float requiredMotorRpm)
Arguments
floataccelerationacceleration
floatwheelSpeedRpmwheel speed rpm
floataccSafeMotorRpmacc save motor rpm
floatrequiredMotorPowerrequired wheel torque
floatrequiredMotorRpmrequired motor rpm
Return Values
floatbestGearbest gear
floatgearRatiogear ratio
Code
571function VehicleMotor:getBestGear(acceleration, wheelSpeedRpm, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm)
572 if math.abs(acceleration) < 0.001 then
573 acceleration = 1
574 if wheelSpeedRpm < 0 then
575 acceleration = -1
576 end
577 end
578 if acceleration > 0 then
579 if self.minForwardGearRatio ~= nil then
580 local wheelSpeedRpm = math.max(wheelSpeedRpm, 0)
581 local bestGearRatio = self:getBestGearRatio(wheelSpeedRpm, self.minForwardGearRatio, self.maxForwardGearRatio, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm)
582 return 1, bestGearRatio
583 else
584 return 1, self.forwardGearRatios[1]
585 end
586 else
587 if self.minBackwardGearRatio ~= nil then
588 local wheelSpeedRpm = math.max(-wheelSpeedRpm, 0)
589 local bestGearRatio = self:getBestGearRatio(wheelSpeedRpm, self.minBackwardGearRatio, self.maxBackwardGearRatio, accSafeMotorRpm, requiredMotorPower, requiredMotorRpm)
590 return -1, -bestGearRatio
591 else
592 return -1, -self.backwardGearRatios[1]
593 end
594 end
595end

updateGear

Description
Update gear
Definition
updateGear(float acceleratorPedal)
Arguments
floatacceleratorPedalacceleratorPedal
Return Values
floatadjustedAcceleratorPedalthe adjusted accelerator pedal for the current gear situation (e.g. 0 while switching gears)
Code
818function VehicleMotor:updateGear(acceleratorPedal, dt)
819 local adjAcceleratorPedal = acceleratorPedal
820 if self.gearChangeTimer >= 0 then
821 self.gearChangeTimer = self.gearChangeTimer - dt;
822 if self.gearChangeTimer < 0 then
823 if self.targetGear > 0 then
824 -- give the logic another chance to choose a better gear at the time when the gear change should happen
825 self.gear = self:findGearChangeTargetGear(self.targetGear, self.previousGear, self.forwardGearRatios, 1, acceleratorPedal, dt)
826 self.minGearRatio = self.forwardGearRatios[self.gear]
827 else
828 self.gear = -self:findGearChangeTargetGear(-self.targetGear, -self.previousGear, self.backwardGearRatios, -1, acceleratorPedal, dt)
829 self.minGearRatio = -self.backwardGearRatios[-self.gear]
830 end
831 self.maxGearRatio = self.minGearRatio
832 end
833 adjAcceleratorPedal = 0
834 else
835 local gearSign = 0
836 if acceleratorPedal > 0 then
837 if self.minForwardGearRatio ~= nil then
838 self.minGearRatio = self.minForwardGearRatio
839 self.maxGearRatio = self.maxForwardGearRatio
840 else
841 gearSign = 1
842 end
843 elseif acceleratorPedal < 0 then
844 if self.minBackwardGearRatio ~= nil then
845 self.minGearRatio = -self.minBackwardGearRatio
846 self.maxGearRatio = -self.maxBackwardGearRatio
847 else
848 gearSign = -1
849 end
850 else
851 if self.maxGearRatio > 0 then
852 if self.minForwardGearRatio == nil then
853 gearSign = 1
854 end
855 elseif self.maxGearRatio < 0 then
856 if self.minBackwardGearRatio == nil then
857 gearSign = -1
858 end
859 end
860 end
861
862 self.autoGearChangeTimer = self.autoGearChangeTimer - dt
863 local newGear = self.gear
864 if g_manualGearShift then
865 if self.manualTargetGear ~= nil then
866 newGear = self.manualTargetGear
867 self.manualTargetGear = nil
868 end
869 else
870 if gearSign > 0 then
871 if self.gear <= 0 then
872 newGear = 1
873 else
874 if self.autoGearChangeTimer <= 0 then
875 newGear = self:findGearChangeTargetGearPrediction(self.gear, self.forwardGearRatios, 1, self.autoGearChangeTimer, acceleratorPedal, dt)
876 end
877 newGear = math.min(math.max(newGear, 1), #self.forwardGearRatios)
878 end
879 elseif gearSign < 0 then
880 if self.gear >= 0 then
881 newGear = -1
882 else
883 if self.autoGearChangeTimer <= 0 then
884 newGear = -self:findGearChangeTargetGearPrediction(-self.gear, self.backwardGearRatios, -1, self.autoGearChangeTimer, acceleratorPedal, dt)
885 end
886 newGear = math.max(math.min(newGear, -1), -#self.backwardGearRatios)
887 end
888 end
889 end
890 if newGear ~= self.gear then
891 self.targetGear = newGear
892 self.previousGear = self.gear
893 self.gear = 0
894 self.minGearRatio = 0
895 self.maxGearRatio = 0
896 self.autoGearChangeTimer = self.autoGearChangeTime
897 self.gearChangeTimer = self.gearChangeTime
898 adjAcceleratorPedal = 0
899 end
900 end
901 return adjAcceleratorPedal
902end

getMinMaxGearRatio

Description
Returns currently selected minimum and maximum gear ratio
Gear ratios for driving backwards are negative. Min/max always refers to the absolute value
For regular gear box transmission, the minimum and maximum gear ratios are identical
Definition
getMinMaxGearRatio()
Return Values
floatminGearRatiominimum gear ratio
floatmaxGearRatiomaximum gear ratio
Code
910function VehicleMotor:getMinMaxGearRatio()
911 return self.minGearRatio, self.maxGearRatio
912end

getCurMaxRpm

Description
Returns current max rpm
Definition
getCurMaxRpm()
Return Values
integermaxRpmcurrent max rpm
Code
921function VehicleMotor:getCurMaxRpm()
922 local maxRpm = self.maxRpm
923
924 local gearRatio = self:getGearRatio()
925 if gearRatio ~= 0 then
926 --local speedLimit = self.speedLimit * 0.277778
927 local speedLimit = math.min(self.speedLimit, math.max(self.speedLimitAcc, self.vehicle.lastSpeedReal*3600)) * 0.277778
928 if gearRatio > 0 then
929 speedLimit = math.min(speedLimit, self.maxForwardSpeed)
930 else
931 speedLimit = math.min(speedLimit, self.maxBackwardSpeed)
932 end
933
934 maxRpm = math.min(maxRpm, speedLimit * 30 / math.pi * math.abs(gearRatio))
935 end
936
937 maxRpm = math.min(maxRpm, self.rpmLimit)
938 return maxRpm
939end

setSpeedLimit

Description
Sets speed limit
Definition
setSpeedLimit(float limit)
Arguments
floatlimitnew limit
Code
944function VehicleMotor:setSpeedLimit(limit)
945 self.speedLimit = math.max(limit, self.minSpeed)
946end

setRpmLimit

Description
Sets rpm limit
Definition
setRpmLimit(float limit)
Arguments
floatlimitnew limit
Code
963function VehicleMotor:setRpmLimit(rpmLimit)
964 self.rpmLimit = rpmLimit
965end

VehiclePlacementCallback

Description
Placement callback

new

Description
Create instance of class
Definition
new()
Code
11function VehiclePlacementCallback:new()
12 local instance = {}
13 setmetatable(instance, VehiclePlacementCallback_mt)
14
15 return instance
16end

callback

Description
Raycast callback
Definition
callback(integer transformId, float x, float y, float z, float distance)
Arguments
integertransformIdid raycasted object
floatxx raycast position
floatyy raycast position
floatzz raycast position
floatdistancedistance to raycast position
Return Values
booleancontinuecontinue
Code
26function VehiclePlacementCallback:callback(transformName, x, y, z, distance)
27 self.raycastHitName = transformName
28 self.x = x
29 self.y = y
30 self.z = z
31 self.distance = distance
32
33 return true
34end

VehicleTypeManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
17function VehicleTypeManager:new(customMt)
18 local self = AbstractManager:new(customMt or VehicleTypeManager_mt)
19
20 return self
21end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
25function VehicleTypeManager:initDataStructures()
26 self.vehicleTypes = {}
27end

loadMapData

Description
Load data on map load
Definition
loadMapData()
Return Values
booleantrueif loading was successful else false
Code
32function VehicleTypeManager:loadMapData()
33 VehicleTypeManager:superClass().loadMapData(self)
34
35 local xmlFile = loadXMLFile("VehicleTypesXML", "dataS/vehicleTypes.xml")
36
37 local i = 0
38 while true do
39 local key = string.format("vehicleTypes.type(%d)", i)
40 if not hasXMLProperty(xmlFile, key) then
41 break
42 end
43
44 g_deferredLoadingManager:addSubtask(function()
45 self:loadVehicleTypeFromXML(xmlFile, key, nil, nil, nil)
46 end)
47
48 i = i + 1
49 end
50
51 g_deferredLoadingManager:addSubtask(function()
52 delete(xmlFile)
53 end)
54
55 g_deferredLoadingManager:addSubtask(function()
56 print(" Loaded vehicle types")
57 end)
58
59 return true
60end

addVehicleType

Description
Adds a new vehicleType
Definition
addVehicleType(string typeName, string className, string filename, table specializationNames, string customEnvironment)
Arguments
stringtypeNamevehicle type name
stringclassNameclassname
stringfilenamefilename
tablespecializationNameslist of specializations
stringcustomEnvironmenta custom environment
Return Values
booleansuccesstrue if added else false

WheelsUtil

Description

registerTireType

Description
Register new tire type
Definition
registerTireType(string name, table frictionCoeffs, table frictionCoeffsWer)
Arguments
stringnamename of new tire type
tablefrictionCoeffsfriction coeffs
tablefrictionCoeffsWerfriction coeffs wet
Code
30function WheelsUtil.registerTireType(name, frictionCoeffs, frictionCoeffsWet)
31 local tireType = WheelsUtil.getTireType(name)
32 if tireType ~= nil then
33 print("Warning: Adding duplicate tire type '"..name.."'")
34 return
35 end
36
37 local function getNoNilCoeffs(frictionCoeffs)
38 local localCoeffs = {}
39 if frictionCoeffs[1] == nil then
40 localCoeffs[1] = 1.15
41 for i=2,WheelsUtil.NUM_GROUNDS do
42 if frictionCoeffs[i] ~= nil then
43 localCoeffs[1] = frictionCoeffs[i]
44 break
45 end
46 end
47 else
48 localCoeffs[1] = frictionCoeffs[1]
49 end
50 for i=2,WheelsUtil.NUM_GROUNDS do
51 localCoeffs[i] = frictionCoeffs[i] or frictionCoeffs[i-1]
52 end
53 return localCoeffs
54 end
55
56 local tireType = {}
57 tireType.name = name
58 tireType.frictionCoeffs = getNoNilCoeffs(frictionCoeffs)
59 tireType.frictionCoeffsWet = getNoNilCoeffs(frictionCoeffsWet or frictionCoeffs)
60 table.insert(WheelsUtil.tireTypes, tireType)
61end

getTireType

Description
Returns tire type index
Definition
getTireType(string name)
Arguments
stringnamename of tire type
Return Values
integeriindex of tire type
Code
67function WheelsUtil.getTireType(name)
68 for i, t in pairs(WheelsUtil.tireTypes) do
69 if t.name == name then
70 return i
71 end
72 end
73 return nil
74end

updateWheelsPhysics

Description
Updates wheel physics
Definition
updateWheelsPhysics(float dt, float currentSpeed, float acceleration, boolean doHandbrake, boolean stopAndGoBraking)
Arguments
floatdttime since last call in ms
floatcurrentSpeedsigned current speed (m/ms)
floataccelerationtarget acceleration [-1,1]
booleandoHandbrakedo handbrake
booleanstopAndGoBrakingif false, the acceleration needs to be 0 before a change of direction is allowed
Code
194function WheelsUtil.updateWheelsPhysics(self, dt, currentSpeed, acceleration, doHandbrake, stopAndGoBraking)
195--print("function WheelsUtil.updateWheelsPhysics("..tostring(self)..", "..tostring(dt)..", "..tostring(currentSpeed)..", "..tostring(acceleration)..", "..tostring(doHandbrake)..", "..tostring(stopAndGoBraking))
196
197 local acceleratorPedal = 0
198 local brakePedal = 0
199
200 local reverserDirection = 1
201 if self.spec_drivable ~= nil then
202 reverserDirection = self.spec_drivable.reverserDirection
203 acceleration = acceleration * reverserDirection
204 end
205
206 local motor = self.spec_motorized.motor
207
208 local absCurrentSpeed = math.abs(currentSpeed)
209 local accSign = MathUtil.sign(acceleration)
210
211 self.nextMovingDirection = Utils.getNoNil(self.nextMovingDirection, 0)
212
213 local automaticBrake = false
214
215 if math.abs(acceleration) < 0.001 then
216 automaticBrake = true
217
218 -- Non-stop&go only allows change of direction if the vehicle speed is smaller than 1km/h or the direction has already changed (e.g. because the brakes are not hard enough)
219 if stopAndGoBraking or currentSpeed * self.nextMovingDirection < 0.0003 then
220 self.nextMovingDirection = 0
221 end
222 else
223 -- Disable the known moving direction if the vehicle is driving more than 5km/h (0.0014 * 3600 = 5.04km/h) in the opposite direction
224 if self.nextMovingDirection * currentSpeed < -0.0014 then
225 self.nextMovingDirection = 0
226 end
227
228 -- Continue accelerating if we want to go in the same direction
229 -- or if the vehicle is only moving slowly in the wrong direction (0.0003 * 3600 = 1.08 km/h) and we are allowed to change direction
230 if accSign == self.nextMovingDirection or (currentSpeed * accSign > -0.0003 and (stopAndGoBraking or self.nextMovingDirection == 0)) then
231 acceleratorPedal = acceleration
232 brakePedal = 0
233 self.nextMovingDirection = accSign
234 else
235 acceleratorPedal = 0
236 brakePedal = math.abs(acceleration)
237 if stopAndGoBraking then
238 self.nextMovingDirection = accSign
239 end
240 end
241 end
242
243 if automaticBrake then
244 acceleratorPedal = 0
245 end
246
247 acceleratorPedal = motor:updateGear(acceleratorPedal, dt)
248
249 if motor.gear == 0 and motor.targetGear ~= 0 then
250 -- brake automatically if the vehicle is rolling backwards while shifting
251 if currentSpeed * MathUtil.sign(motor.targetGear) < 0 then
252 automaticBrake = true
253 end
254 end
255
256 if automaticBrake then
257 local isSlow = absCurrentSpeed < motor.lowBrakeForceSpeedLimit
258 local isArticulatedSteering = self.spec_articulatedAxis ~= nil and self.spec_articulatedAxis.componentJoint ~= nil and math.abs(self.rotatedTime) > 0.01
259
260 if (isSlow or doHandbrake) and not isArticulatedSteering then
261 brakePedal = 1
262 else
263 -- interpolate between lowBrakeForce and 1 if speed is below 3.6 km/h
264 local factor = math.min(absCurrentSpeed / 0.001, 1)
265 brakePedal = MathUtil.lerp(1, motor.lowBrakeForceScale, factor)
266 end
267 end
268
269 -- ToDo: move to Lights ?!
270 if self.spec_lights ~= nil then
271 if self.setBrakeLightsVisibility ~= nil then
272 self:setBrakeLightsVisibility(not automaticBrake and math.abs(brakePedal) > 0)
273 end
274
275 if self.setReverseLightsVisibility ~= nil then
276 self:setReverseLightsVisibility((currentSpeed < -0.0006 or acceleratorPedal < 0) and reverserDirection == 1)
277 end
278 end
279
280 acceleratorPedal, brakePedal = WheelsUtil.getSmoothedAcceleratorAndBrakePedals(self, acceleratorPedal, brakePedal, dt)
281
282 --active braking if over the speed limit
283 local overSpeedLimit = self:getLastSpeed() - motor:getSpeedLimit()
284 if overSpeedLimit > 0 then
285 brakePedal = math.max(math.min(overSpeedLimit/5, 1), brakePedal)
286 acceleratorPedal = math.min(0, acceleratorPedal)
287 end
288
289 if next(self.spec_motorized.differentials) ~= nil and self.spec_motorized.motorizedNode ~= nil then
290
291 local absAcceleratorPedal = math.abs(acceleratorPedal)
292 local minGearRatio, maxGearRatio = motor:getMinMaxGearRatio()
293
294 local maxSpeed;
295 if maxGearRatio >= 0 then
296 maxSpeed = motor:getMaximumForwardSpeed()
297 else
298 maxSpeed = motor:getMaximumBackwardSpeed()
299 end
300
301 local acceleratorPedalControlsSpeed = false
302 if acceleratorPedalControlsSpeed then
303 maxSpeed = maxSpeed * absAcceleratorPedal
304 if absAcceleratorPedal > 0.001 then
305 absAcceleratorPedal = 1
306 end
307 end
308 maxSpeed = math.min(maxSpeed, motor:getSpeedLimit() / 3.6)
309 local maxAcceleration = motor:getAccelerationLimit()
310 local minMotorRpm, maxMotorRpm = motor:getRequiredMotorRpmRange()
311
312 local neededPtoTorque = PowerConsumer.getTotalConsumedPtoTorque(self) / motor:getPtoMotorRpmRatio();
313
314 --print(string.format("set vehicle props: accPed=%.1f speed=%.1f gearRatio=[%.1f %.1f] rpm=[%.1f %.1f]", absAcceleratorPedal, maxSpeed, minGearRatio, maxGearRatio, minMotorRpm, maxMotorRpm))
315 controlVehicle(self.spec_motorized.motorizedNode, absAcceleratorPedal, maxSpeed, maxAcceleration, minMotorRpm*math.pi/30, maxMotorRpm*math.pi/30, minGearRatio, maxGearRatio, motor:getMaxClutchTorque(), neededPtoTorque)
316 end
317
318 self:brake(brakePedal)
319end

updateWheelPhysics

Description
Update wheel physics
Definition
updateWheelPhysics(table wheel, boolean doHandbrake, float brakePedal, float dt)
Arguments
tablewheelwheel
booleandoHandbrakedoHandbrake
floatbrakePedalbrake pedal
floatdtdt
Code
328function WheelsUtil.updateWheelPhysics(self, wheel, brakePedal, dt)
329 WheelsUtil.updateWheelSteeringAngle(self, wheel, dt)
330
331 if self.isServer and self.isAddedToPhysics then
332 local brakeForce = self:getBrakeForce() * brakePedal
333 setWheelShapeProps(wheel.node, wheel.wheelShape, wheel.torque, brakeForce*wheel.brakeFactor, wheel.steeringAngle, wheel.rotationDamping)
334 end
335end

updateWheelHasGroundContact

Description
Update check if wheel has ground contact
Definition
updateWheelHasGroundContact(table wheel)
Arguments
tablewheelwheel
Code
340function WheelsUtil.updateWheelHasGroundContact(wheel)
341
342 local x,_,_ = getWheelShapeContactPoint(wheel.node, wheel.wheelShape)
343 wheel.hasGroundContact = x~=nil
344 --return wheel.hasGroundContact
345end

updateWheelSteeringAngle

Description
Update wheel steering angle
Definition
updateWheelSteeringAngle(table wheel, float dt)
Arguments
tablewheelwheel
floatdttime since last call in ms
Code
351function WheelsUtil.updateWheelSteeringAngle(self, wheel, dt)
352
353 local steeringAngle = wheel.steeringAngle
354 local rotatedTime = self.rotatedTime
355
356 if wheel.steeringAxleScale ~= nil and wheel.steeringAxleScale ~= 0 then
357 local steeringAxleAngle = 0
358 if self.spec_attachable ~= nil then
359 steeringAxleAngle = self.spec_attachable.steeringAxleAngle
360 end
361 steeringAngle = MathUtil.clamp(steeringAxleAngle * wheel.steeringAxleScale, wheel.steeringAxleRotMin, wheel.steeringAxleRotMax)
362 elseif wheel.versatileYRot and self:getIsVersatileYRotActive(wheel) then
363 if self.isServer then
364 if wheel.forceVersatility or wheel.hasGroundContact then
365 steeringAngle = Utils.getVersatileRotation(wheel.repr, wheel.node, dt, wheel.positionX, wheel.positionY, wheel.positionZ, wheel.steeringAngle, wheel.rotMin, wheel.rotMax)
366 end
367 end
368 elseif wheel.rotSpeed ~= nil and wheel.rotMax ~= nil and wheel.rotMin ~= nil then
369 if rotatedTime > 0 or wheel.rotSpeedNeg == nil then
370 steeringAngle = rotatedTime * wheel.rotSpeed
371 else
372 steeringAngle = rotatedTime * wheel.rotSpeedNeg
373 end
374 if steeringAngle > wheel.rotMax then
375 steeringAngle = wheel.rotMax
376 elseif steeringAngle < wheel.rotMin then
377 steeringAngle = wheel.rotMin
378 end
379 if self.updateSteeringAngle ~= nil then
380 steeringAngle = self:updateSteeringAngle(wheel, dt, steeringAngle)
381 end
382 end
383 wheel.steeringAngle = steeringAngle
384end

computeDifferentialRotSpeedNonMotor

Description
Compute differential rot speed from properties of vehicle other than the motor, e.g. rot speed of wheels or linear speed of vehicle
Definition
computeDifferentialRotSpeedNonMotor()
Return Values
floatdiffRotSpeedrot speed [rad/sec]
Code
389function WheelsUtil.computeDifferentialRotSpeedNonMotor(self)
390 if self.isServer and self.spec_wheels ~= nil and #self.spec_wheels.wheels ~= 0 then
391 local wheelSpeed = 0
392 local numWheels = 0
393 for _, wheel in pairs(self.spec_wheels.wheels) do
394 local axleSpeed = getWheelShapeAxleSpeed(wheel.node, wheel.wheelShape) -- rad/sec
395 if wheel.hasGroundContact then
396 wheelSpeed = wheelSpeed + axleSpeed * wheel.radius
397 numWheels = numWheels+1
398 end
399 end
400
401 if numWheels > 0 then
402 return wheelSpeed/numWheels
403 end
404 return 0
405 else
406 -- v = w*r => w = v/r
407 -- differentials have embeded gear so that r can be considered 1
408 return self.lastSpeedReal*1000
409 end
410end

updateVisualWheel

Description
Update wheel graphics
Definition
updateVisualWheel(table wheel, float x, float y, float z, float x, float suspensionLength)
Arguments
tablewheelwheel
floatxx position
floatyy position
floatzz position
floatxx drive rotation
floatsuspensionLengthlength of suspension
Code
472function WheelsUtil.updateVisualWheel(self, wheel, x, y, z, xDrive, suspensionLength)
473 local changed = false
474
475 local steeringAngle = wheel.steeringAngle
476 if not wheel.showSteeringAngle then
477 steeringAngle = 0
478 end
479
480 local _, oldY, _ = getRotation(wheel.repr)
481 local dirX, dirY, dirZ = localDirectionToLocal(wheel.repr, getParent(wheel.repr), 0, -1, 0)
482 if math.abs(steeringAngle-oldY) > WheelsUtil.STEERING_ANGLE_THRESHOLD then
483 setRotation(wheel.repr, 0, steeringAngle, 0)
484 changed = true
485 end
486
487 local oldX, _, _ = getRotation(wheel.driveNode)
488 if math.abs(xDrive-oldX) > WheelsUtil.STEERING_ANGLE_THRESHOLD then
489 setRotation(wheel.driveNode, xDrive, 0, 0)
490 changed = true
491 end
492
493 if wheel.wheelTire ~= nil then
494 local x, y, z, _ = getShaderParameter(wheel.wheelTire, "morphPosition")
495 local deformation = MathUtil.clamp((wheel.deltaY+0.04-suspensionLength)*0.7, 0, wheel.maxDeformation)
496 if math.abs(deformation - wheel.deformation) > 0.01 then
497 wheel.deformation = deformation
498 setShaderParameter(wheel.wheelTire, "morphPosition", x, y, z, deformation, false)
499
500 if wheel.additionalWheels ~= nil then
501 for _, additionalWheel in pairs(wheel.additionalWheels) do
502 local x, y, z, _ = getShaderParameter(additionalWheel.wheelTire, "morphPosition")
503 setShaderParameter(additionalWheel.wheelTire, "morphPosition", x, y, z, deformation, false)
504 end
505 end
506 changed = true
507 end
508
509 suspensionLength = suspensionLength+deformation
510 end
511
512 suspensionLength = suspensionLength - wheel.deltaY
513
514 if math.abs(wheel.lastMovement-suspensionLength) > WheelsUtil.SUSPENSION_THRESHOLD then
515 local transRatio = wheel.transRatio
516 local movement = suspensionLength * transRatio
517 setTranslation(wheel.repr, wheel.startPositionX + dirX*movement, wheel.startPositionY + dirY*movement, wheel.startPositionZ + dirZ*movement)
518 changed = true
519 if transRatio < 1 then
520 movement = suspensionLength*(1-transRatio)
521 setTranslation(wheel.driveNode, wheel.driveNodeStartPosX + dirX*movement, wheel.driveNodeStartPosY + dirY*movement, wheel.driveNodeStartPosZ + dirZ*movement)
522 end
523
524 wheel.lastMovement = suspensionLength
525 end
526
527 if wheel.steeringNode ~= nil then
528 local refAngle = wheel.steeringNodeMaxRot
529 local refTrans = wheel.steeringNodeMaxTransX
530 local refRot = wheel.steeringNodeMaxRotY
531 if steeringAngle < 0 then
532 refAngle = wheel.steeringNodeMinRot
533 refTrans = wheel.steeringNodeMinTransX
534 refRot = wheel.steeringNodeMinRotY
535 end
536 local steering = 0
537 if refAngle ~= 0 then
538 steering = steeringAngle / refAngle
539 end
540
541 if wheel.steeringNodeMinTransX ~= nil then
542 local x,y,z = getTranslation(wheel.steeringNode)
543 x = refTrans * steering
544 setTranslation(wheel.steeringNode, x, y, z)
545 end
546 if wheel.steeringNodeMinRotY ~= nil then
547 local rotX,rotY,rotZ = getRotation(wheel.steeringNode)
548 rotY = refRot * steering
549 setRotation(wheel.steeringNode, rotX, rotY, rotZ)
550 end
551 end
552
553 if wheel.fenderNode ~= nil then
554 local angleDif = 0
555 if steeringAngle > wheel.fenderRotMax then
556 angleDif = wheel.fenderRotMax - steeringAngle
557 elseif steeringAngle < wheel.fenderRotMin then
558 angleDif = wheel.fenderRotMin - steeringAngle
559 end
560 setRotation(wheel.fenderNode, 0, angleDif, 0)
561 end
562
563 return changed
564end

getTireFriction

Description
Returns tire friction
Definition
getTireFriction(integer tireType, integer groundType, float wetScale)
Arguments
integertireTypetire type index
integergroundTypeground type index
floatwetScalewet scale
Return Values
floattireFrictiontire friction
Code
572function WheelsUtil.getTireFriction(tireType, groundType, wetScale)
573 if wetScale == nil then
574 wetScale = 0
575 end
576 local coeff = WheelsUtil.tireTypes[tireType].frictionCoeffs[groundType]
577 local coeffWet = WheelsUtil.tireTypes[tireType].frictionCoeffsWet[groundType]
578 return coeff + (coeffWet-coeff)*wetScale
579end

getGroundType

Description
Get ground type
Definition
getGroundType(boolean isField, boolean isRoad, float depth)
Arguments
booleanisFieldis on field
booleanisRoadis on road
floatdepthdepth of terrain
Return Values
integergroundTypeground type
Code
587function WheelsUtil.getGroundType(isField, isRoad, depth)
588 -- terrain softness:
589 -- [ 0, 0.1]: road
590 -- [0.1, 0.8]: hard terrain
591 -- [0.8, 1 ]: soft terrain
592 if isField then
593 return WheelsUtil.GROUND_FIELD
594 elseif isRoad or depth < 0.1 then
595 return WheelsUtil.GROUND_ROAD
596 else
597 if depth > 0.8 then
598 return WheelsUtil.GROUND_SOFT_TERRAIN
599 else
600 return WheelsUtil.GROUND_HARD_TERRAIN
601 end
602 end
603end

WorkAreaTypeManager

Description

new

Description
Creating manager
Definition
new()
Return Values
tableinstanceinstance of object
Code
19function WorkAreaTypeManager:new(customMt)
20 local self = AbstractManager:new(customMt or WorkAreaTypeManager_mt)
21
22 return self
23end

initDataStructures

Description
Initialize data structures
Definition
initDataStructures()
Code
27function WorkAreaTypeManager:initDataStructures()
28 self.workAreaTypes = {}
29 self.workAreaTypeNameToInt = {}
30 self.workAreaTypeNameToDesc = {}
31 WorkAreaType = self.workAreaTypeNameToInt
32end

AIConveyorBelt

Description
Specialization for AI converyor belts

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
19function AIConveyorBelt.prerequisitesPresent(specializations)
20 return SpecializationUtil.hasSpecialization(AIVehicle, specializations) and SpecializationUtil.hasSpecialization(Motorized, specializations)
21end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
47function AIConveyorBelt:onLoad(savegame)
48 local spec = self.spec_aiConveyorBelt
49
50 spec.isAllowed = hasXMLProperty(self.xmlFile, "vehicle.ai.conveyorBelt")
51
52 spec.minAngle = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.ai.conveyorBelt#minAngle"), 5)
53 spec.maxAngle = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.ai.conveyorBelt#maxAngle"), 45)
54 spec.stepSize = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.ai.conveyorBelt#stepSize"), 5)
55 spec.currentAngle = spec.maxAngle
56
57 spec.minTargetWorldYRot = 0
58 spec.maxTargetWorldYRot = 0
59 spec.currentDirection = 0
60 spec.currentSpeed = 0
61
62 spec.speed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.ai.conveyorBelt#speed"), 1)
63 spec.direction = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.ai.conveyorBelt#direction"), -1)
64end

onReadStream

Description
Called on client side on join
Definition
onReadStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
82function AIConveyorBelt:onReadStream(streamId, connection)
83 self:setAIConveyorBeltAngle(streamReadInt8(streamId), true)
84end

onWriteStream

Description
Called on server side on join
Definition
onWriteStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
90function AIConveyorBelt:onWriteStream(streamId, connection)
91 streamWriteInt8(streamId, self.spec_aiConveyorBelt.currentAngle)
92end

onUpdate

Description
Called on update
Definition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
99function AIConveyorBelt:onUpdate(dt, isActiveForInput, isSelected)
100 local spec = self.spec_aiConveyorBelt
101 if self.isServer then
102 if self:getIsAIActive() then
103 spec.currentDirection, spec.currentSpeed = self:getDirectionAndSpeedToTargetAngle(spec.currentDirection, spec.minTargetWorldYRot, spec.maxTargetWorldYRot)
104
105 self:getMotor():setSpeedLimit(math.abs(spec.currentSpeed * spec.speed))
106 WheelsUtil.updateWheelsPhysics(self, dt, spec.currentSpeed * spec.speed * spec.direction, spec.currentDirection * spec.direction, false, true)
107 end
108 end
109end

onUpdateTick

Description
Called on updateTick
Definition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
116function AIConveyorBelt:onUpdateTick(dt, isActiveForInput, isSelected)
117 local spec = self.spec_aiConveyorBelt
118 if self.isClient then
119 local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA3]
120 if actionEvent ~= nil then
121 g_inputBinding:setActionEventActive(actionEvent.actionEventId, isActiveForInput)
122 if isActiveForInput then
123 g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText("action_conveyorBeltChangeAngle"), string.format("%.0f", spec.currentAngle)))
124 end
125 end
126 end
127end

AIImplement

Description
Specialization for AI Implements

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
17function AIImplement.prerequisitesPresent(specializations)
18 return true
19end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
97function AIImplement:onLoad(savegame)
98 local spec = self.spec_aiImplement
99
100 local baseName = "vehicle.ai"
101
102 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".areaMarkers#leftIndex", baseName .. ".areaMarkers#leftNode") -- FS17 to FS 19
103 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".areaMarkers#rightIndex", baseName .. ".areaMarkers#rightNode") -- FS17 to FS 19
104 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".areaMarkers#backIndex", baseName .. ".areaMarkers#backNode") -- FS17 to FS 19
105
106 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".sizeMarkers#leftIndex", baseName .. ".sizeMarkers#leftNode") -- FS17 to FS 19
107 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".sizeMarkers#rightIndex", baseName .. ".sizeMarkers#rightNode") -- FS17 to FS 19
108 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".sizeMarkers#backIndex", baseName .. ".sizeMarkers#backNode") -- FS17 to FS 19
109
110 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".trafficCollisionTrigger#index", baseName .. ".collisionTrigger#node") -- FS17 to FS 19
111 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".trafficCollisionTrigger#node", baseName .. ".collisionTrigger#node") -- FS17 to FS 19
112 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".collisionTrigger#index", baseName .. ".collisionTrigger#node") -- FS17 to FS 19
113 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.aiLookAheadSize#value", baseName .. ".lookAheadSize#value") -- FS17 to FS 19
114
115 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".toolReverserDirectionNode#index", baseName .. ".toolReverserDirectionNode#node") -- FS17 to FS 19
116 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".turningRadiusLimiation", baseName .. ".turningRadiusLimitation") -- FS17 to FS 19
117
118 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, baseName .. ".forceTurnNoBackward#value", baseName .. ".allowTurnBackward#value (inverted)") -- FS17 to FS 19
119
120
121 spec.minTurningRadius = getXMLFloat(self.xmlFile, baseName .. ".minTurningRadius#value")
122
123 spec.leftMarker = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".areaMarkers#leftNode"), self.i3dMappings)
124 spec.rightMarker = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".areaMarkers#rightNode"), self.i3dMappings)
125 spec.backMarker = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".areaMarkers#backNode"), self.i3dMappings)
126 spec.aiMarkersInverted = false
127
128 spec.sizeLeftMarker = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".sizeMarkers#leftNode"), self.i3dMappings)
129 spec.sizeRightMarker = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".sizeMarkers#rightNode"), self.i3dMappings)
130 spec.sizeBackMarker = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".sizeMarkers#backNode"), self.i3dMappings)
131
132 spec.collisionTrigger = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".collisionTrigger#node"), self.i3dMappings)
133 if spec.collisionTrigger ~= nil then
134 local rigidBodyType = getRigidBodyType(spec.collisionTrigger)
135 if rigidBodyType ~= "Kinematic" then
136 g_logManager:xmlWarning(self.configFileName, "'aiCollisionTrigger' is not a kinematic body type")
137 end
138 end
139
140 spec.needsLowering = Utils.getNoNil(getXMLBool(self.xmlFile, baseName .. ".needsLowering#value"), true)
141 spec.lowerIfAnyIsLowerd = Utils.getNoNil(getXMLBool(self.xmlFile, baseName .. ".needsLowering#lowerIfAnyIsLowerd"), false)
142
143 spec.allowTurnBackward = Utils.getNoNil(getXMLBool(self.xmlFile, baseName .. ".allowTurnBackward#value"), true)
144
145 spec.toolReverserDirectionNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".toolReverserDirectionNode#node"), self.i3dMappings)
146
147 spec.turningRadiusLimitation = {}
148 spec.turningRadiusLimitation.rotationJoint = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName .. ".turningRadiusLimitation#rotationJointNode"), self.i3dMappings)
149 if spec.turningRadiusLimitation.rotationJoint ~= nil then
150 spec.turningRadiusLimitation.wheelIndices = {StringUtil.getVectorFromString(getXMLString(self.xmlFile, baseName .. ".turningRadiusLimitation#wheelIndices"))}
151 end
152
153 spec.turningRadiusLimitation.radius = getXMLFloat(self.xmlFile, baseName .. ".turningRadiusLimitation#radius")
154
155 spec.lookAheadSize = Utils.getNoNil(getXMLFloat(self.xmlFile, baseName .. ".lookAheadSize#value"), 2)
156 spec.useAttributesOfAttachedImplement = Utils.getNoNil(getXMLBool(self.xmlFile, baseName .. ".useAttributesOfAttachedImplement#value"), false)
157
158 spec.hasNoFullCoverageArea = Utils.getNoNil(getXMLString(self.xmlFile, baseName .. ".hasNoFullCoverageArea#value"), false)
159
160 spec.terrainDetailRequiredValueRanges = {}
161 spec.terrainDetailProhibitedValueRanges = {}
162
163 spec.requiredFruitTypes = {}
164 spec.prohibitedFruitTypes = {}
165
166 spec.isLineStarted = false
167end

AIVehicle

Description
Specialization for AI vehicles

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
62function AIVehicle.prerequisitesPresent(specializations)
63 return SpecializationUtil.hasSpecialization(Drivable, specializations)
64end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
152function AIVehicle:onLoad(savegame)
153 local spec = self.spec_aiVehicle
154
155 spec.aiSteeringSpeed = Utils.getNoNil(getXMLFloat(spec.xmlFile, "vehicle.ai.steeringSpeed"), 1)*0.001
156
157 spec.isActive = false
158
159 spec.aiImplementList = {}
160 spec.aiImplementDataDirtyFlag = true
161
162 spec.taskList = {}
163
164 spec.driveStrategies = {}
165
166 spec.didNotMoveTimeout = Utils.getNoNil( getXMLFloat(spec.xmlFile, "vehicle.ai.didNotMoveTimeout#value"), 5000)
167 if getXMLBool(spec.xmlFile, "vehicle.ai.didNotMoveTimeout#deactivated") then
168 spec.didNotMoveTimeout = math.huge
169 end
170
171 spec.didNotMoveTimer = spec.didNotMoveTimeout
172
173 spec.debugTexts = {}
174 spec.debugLines = {}
175
176 spec.aiTrafficCollision = nil
177 spec.aiTrafficCollisionRemoveDelay = 0
178 spec.aiTrafficCollisionTranslation = {0, 0, 20}
179 spec.aiTrafficCollisionScale = {40, 30, 40}
180
181 spec.pricePerMS = Utils.getNoNil(getXMLFloat(spec.xmlFile, "vehicle.ai.pricePerHour"), 2000)/60/60/1000
182
183 spec.steeringNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.ai.steeringNode#node"), self.i3dMappings)
184end

onReadStream

Description
Called on client side on join
Definition
onReadStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
190function AIVehicle:onReadStream(streamId, connection)
191 if streamReadBool(streamId) then
192 local helperIndex = streamReadUInt8(streamId)
193 local farmId = streamReadUIntN(streamId, FarmManager.FARM_ID_SEND_NUM_BITS)
194 self:startAIVehicle(helperIndex, true, farmId)
195 end
196end

onWriteStream

Description
Called on server side on join
Definition
onWriteStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
202function AIVehicle:onWriteStream(streamId, connection)
203 local spec = self.spec_aiVehicle
204 if streamWriteBool(streamId, self:getIsAIActive()) then
205 streamWriteUInt8(streamId, spec.currentHelper.index)
206 streamWriteUIntN(streamId, spec.startedFarmId, FarmManager.FARM_ID_SEND_NUM_BITS)
207 end
208end

onUpdate

Description
Called on update
Definition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
215function AIVehicle:onUpdate(dt, isActiveForInput, isSelected)
216 local spec = self.spec_aiVehicle
217
218 if VehicleDebug.state == VehicleDebug.DEBUG_AI and isActiveForInput then
219 if #spec.debugTexts > 0 then
220 for i, text in pairs(spec.debugTexts) do
221 renderText(0.7, 0.92-(0.02*i), 0.02, text)
222 end
223 end
224 if #spec.debugLines > 0 then
225 for _, l in pairs(spec.debugLines) do
226 drawDebugLine(l.s[1],l.s[2],l.s[3], l.c[1],l.c[2],l.c[3], l.e[1],l.e[2],l.e[3], l.c[1],l.c[2],l.c[3])
227 end
228 end
229 end
230
231 if spec.aiImplementDataDirtyFlag then
232 spec.aiImplementDataDirtyFlag = false
233 self:updateAIImplementData()
234 end
235
236 if spec.isServer then
237 if self:getIsAIActive() then
238 if spec.driveStrategies ~= nil and #spec.driveStrategies > 0 then
239 for i=1,#spec.driveStrategies do
240 local driveStrategy = spec.driveStrategies[i]
241 driveStrategy:update(dt)
242 end
243 end
244 end
245 end
246
247 -- as long as the ai is turned on we raise active (e.g. if the vehicle stops due a collision the vehicle collision may sleep and stop raising active)
248 if self:getIsAIActive() then
249 self:raiseActive()
250 end
251end

onUpdateTick

Description
Called on update tick
Definition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
258function AIVehicle:onUpdateTick(dt, isActiveForInput, isSelected)
259 local spec = self.spec_aiVehicle
260
261 self:clearAIDebugTexts()
262 self:clearAIDebugLines()
263
264 if self.isServer then
265 if self:getIsAIActive() then
266 local difficultyMultiplier = g_currentMission.missionInfo.buyPriceMultiplier;
267 local price = -dt * difficultyMultiplier * spec.pricePerMS
268
269 -- If field was not owned, it is a mission. Increase the price for balancing.
270 if self.getLastTouchedFarmlandFarmId ~= nil and self:getLastTouchedFarmlandFarmId() == 0 then
271 price = price * MissionManager.AI_PRICE_MULTIPLIER
272 end
273
274 g_currentMission:addMoney(price, spec.startedFarmId, "wagePayment");
275 g_currentMission:addMoneyChange(price, spec.startedFarmId, FSBaseMission.MONEY_TYPE_AI)
276
277 if spec.driveStrategies ~= nil and #spec.driveStrategies > 0 then
278 local vX,vY,vZ = getWorldTranslation(self:getAIVehicleSteeringNode())
279
280 local tX, tZ, moveForwards, maxSpeedStra, maxSpeed, distanceToStop
281 for i=1,#spec.driveStrategies do
282 local driveStrategy = spec.driveStrategies[i]
283 tX, tZ, moveForwards, maxSpeedStra, distanceToStop = driveStrategy:getDriveData(dt, vX,vY,vZ)
284 maxSpeed = math.min(maxSpeedStra or math.huge, maxSpeed or math.huge)
285 if tX ~= nil or not self:getIsAIActive() then
286 break
287 end
288 end
289
290 if tX == nil then
291 if self:getIsAIActive() then -- check if AI is still active, because it might have been kicked by a strategy
292 self:stopAIVehicle(AIVehicle.STOP_REASON_REGULAR)
293 end
294 end
295
296 if not self:getIsAIActive() then
297 return
298 end
299
300 local acceleration = 1.0
301
302 local minimumSpeed = 5
303 local lookAheadDistance = 5
304
305 local distSpeed = math.max(minimumSpeed, maxSpeed * math.min(1, distanceToStop/lookAheadDistance))
306 local speedLimit, _ = self:getSpeedLimit()
307 maxSpeed = math.min(maxSpeed, distSpeed, speedLimit)
308 maxSpeed = math.min(maxSpeed, self:getCruiseControlMaxSpeed())
309
310 local isAllowedToDrive = maxSpeed ~= 0
311
312 local pX, _, pZ = worldToLocal(self:getAIVehicleSteeringNode(), tX,vY,tZ)
313 if not moveForwards and self.spec_articulatedAxis ~= nil then
314 if self.spec_articulatedAxis.aiRevereserNode ~= nil then
315 pX, _, pZ = worldToLocal(self.spec_articulatedAxis.aiRevereserNode, tX,vY,tZ)
316 end
317 end
318
319 AIVehicleUtil.driveToPoint(self, dt, acceleration, isAllowedToDrive, moveForwards, pX, pZ, maxSpeed)
320
321 -- worst case check: did not move but should have moved
322 if isAllowedToDrive and self:getLastSpeed() < 0.5 then
323 spec.didNotMoveTimer = spec.didNotMoveTimer - dt
324 else
325 spec.didNotMoveTimer = spec.didNotMoveTimeout
326 end
327
328 if spec.didNotMoveTimer < 0 then
329 self:stopAIVehicle(AIVehicle.STOP_REASON_BLOCKED_BY_OBJECT)
330 end
331 end
332
333 if #spec.taskList > 0 then
334 for i, task in pairs(spec.taskList) do
335 self:addAIDebugText(string.format("AI TASK: %d - %s", i, task.getFunc))
336 if task.getObject ~= nil then
337 if task.getObject[task.getFunc](task.getObject, unpack(task.getParams)) then
338 task.setObject[task.setFunc](task.setObject, unpack(task.setParams))
339 spec.taskList[i] = nil
340 end
341 else
342 task.setObject[task.setFunc](task.setObject, unpack(task.setParams))
343 spec.taskList[i] = nil
344 end
345 end
346 end
347
348 self:raiseAIEvent("onAIActive", "onAIImplementActive")
349 else
350 if spec.aiTrafficCollisionRemoveDelay > 0 then
351 spec.aiTrafficCollisionRemoveDelay = spec.aiTrafficCollisionRemoveDelay - dt
352 if spec.aiTrafficCollisionRemoveDelay <= 0 then
353 if spec.aiTrafficCollision ~= nil then
354 if entityExists(spec.aiTrafficCollision) then
355 delete(spec.aiTrafficCollision)
356 end
357 end
358 spec.aiTrafficCollisionRemoveDelay = 0
359 end
360 end
361 end
362 end
363
364 if self.isClient then
365 local actionEvent = spec.actionEvents[InputAction.TOGGLE_AI]
366 if actionEvent ~= nil then
367 local showAction = false
368
369 if self:getIsActiveForInput(true, true) then
370 -- if ai is active we always display the dismiss helper action
371 showAction = self:getCanStartAIVehicle() or self:getIsAIActive()
372
373 if showAction then
374 if self:getIsAIActive() then
375 g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_dismissEmployee"))
376 else
377 g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_hireEmployee"))
378 end
379 end
380 end
381
382 g_inputBinding:setActionEventActive(actionEvent.actionEventId, showAction)
383 end
384 end
385end

getCanStartAIVehicle

Description
Returns true if ai can start
Definition
getCanStartAIVehicle()
Return Values
booleancanStartcan start ai
Code
390function AIVehicle:getCanStartAIVehicle()
391 local spec = self.spec_aiVehicle
392
393 if self:getAIVehicleDirectionNode() == nil then
394 return false
395 end
396
397 if g_currentMission.disableAIVehicle then
398 return false
399 end
400
401 if AIVehicle.numHirablesHired >= g_currentMission.maxNumHirables then
402 return false
403 end
404
405 if #spec.aiImplementList == 0 then
406 return false
407 end
408
409 return true
410end

getCanAIVehicleContinueWork

Description
Returns true if ai can contiue
Definition
getCanAIVehicleContinueWork()
Return Values
booleancanContiuecan contiue ai
Code
415function AIVehicle:getCanAIVehicleContinueWork()
416 for _, implement in ipairs(self:getAttachedAIImplements()) do
417 if not implement.object:getCanAIImplementContinueWork() then
418 return false
419 end
420 end
421
422 if SpecializationUtil.hasSpecialization(AIImplement, self.specializations) then
423 if not self:getCanAIImplementContinueWork() then
424 return false
425 end
426 end
427
428 return true
429end

startAIVehicle

Description
Starts ai vehicle
Definition
startAIVehicle(integer helperIndex, boolean noEventSend)
Arguments
integerhelperIndexindex of hired helper
booleannoEventSendno event send
Code
463function AIVehicle:startAIVehicle(helperIndex, noEventSend, startedFarmId)
464 local spec = self.spec_aiVehicle
465
466 if not self:getIsAIActive() then
467 if helperIndex ~= nil then
468 spec.currentHelper = g_helperManager:getHelperByIndex(helperIndex)
469 else
470 spec.currentHelper = g_helperManager:getRandomHelper()
471 end
472
473 g_helperManager:useHelper(spec.currentHelper)
474
475 spec.startedFarmId = startedFarmId
476
477 g_farmManager:getFarmById(startedFarmId).stats:updateStats("workersHired", 1)
478
479 if noEventSend == nil or noEventSend == false then
480 local event = AIVehicleSetStartedEvent:new(self, nil, true, spec.currentHelper, startedFarmId)
481 if g_server ~= nil then
482 g_server:broadcastEvent(event, nil, nil, self)
483 else
484 g_client:getServerConnection():sendEvent(event)
485 end
486 end
487
488 AIVehicle.numHirablesHired = AIVehicle.numHirablesHired + 1
489
490 if self.setRandomVehicleCharacter ~= nil then
491 self:setRandomVehicleCharacter()
492 end
493
494 local hotspotX, _, hotspotZ = getWorldTranslation(spec.rootNode)
495
496 local _, textSize = getNormalizedScreenValues(0, 9)
497 local _, textOffsetY = getNormalizedScreenValues(0, 18)
498 local width, height = getNormalizedScreenValues(24, 24)
499 spec.mapAIHotspot = MapHotspot:new("helper", MapHotspot.CATEGORY_AI)
500 spec.mapAIHotspot:setSize(width, height)
501 spec.mapAIHotspot:setLinkedNode(spec.components[1].node)
502 spec.mapAIHotspot:setText(spec.currentHelper.name)
503 spec.mapAIHotspot:setImage(nil, getNormalizedUVs(MapHotspot.UV.HELPER), {0.052, 0.1248, 0.672, 1})
504 spec.mapAIHotspot:setBackgroundImage(nil, getNormalizedUVs(MapHotspot.UV.HELPER))
505 spec.mapAIHotspot:setIconScale(0.7)
506 spec.mapAIHotspot:setTextOptions(textSize, nil, textOffsetY, {1, 1, 1, 1}, Overlay.ALIGN_VERTICAL_MIDDLE)
507 g_currentMission:addMapHotspot(spec.mapAIHotspot)
508
509 spec.isActive = true
510
511 if spec.isServer then
512 self:updateAIImplementData()
513 self:updateAIDriveStrategies()
514 end
515
516 self:raiseAIEvent("onAIStart", "onAIImplementStart")
517 self:requestActionEventUpdate()
518
519 local collisionRoot = g_i3DManager:loadSharedI3DFile(AIVehicle.TRAFFIC_COLLISION_BOX_FILENAME, self.baseDirectory, false, true, false)
520 if collisionRoot ~= nil and collisionRoot ~= 0 then
521 local collision = getChildAt(collisionRoot, 0)
522
523 link(self.components[1].node, collision)
524
525 setTranslation(collision, unpack(spec.aiTrafficCollisionTranslation))
526 setScale(collision, unpack(spec.aiTrafficCollisionScale))
527 spec.aiTrafficCollision = collision
528
529 delete(collisionRoot)
530 end
531 end
532end

stopAIVehicle

Description
Stops ai vehicle
Definition
stopAIVehicle(integer reason, boolean noEventSend)
Arguments
integerreasonreason
booleannoEventSendno event send
Code
538function AIVehicle:stopAIVehicle(reason, noEventSend)
539 local spec = self.spec_aiVehicle
540
541 if self:getIsAIActive() then
542 if noEventSend == nil or noEventSend == false then
543 local event = AIVehicleSetStartedEvent:new(self, reason, false, nil, spec.startedFarmId)
544
545 if g_server ~= nil then
546 g_server:broadcastEvent(event, nil, nil, self)
547 else
548 g_client:getServerConnection():sendEvent(event)
549 end
550 end
551
552 if self.isClient then
553 if g_currentMission.player ~= nil then
554 if g_currentMission.player.farmId == spec.startedFarmId then
555 if reason ~= nil and reason ~= AIVehicle.STOP_REASON_USER then
556 local notificationType = FSBaseMission.INGAME_NOTIFICATION_CRITICAL
557 if reason == AIVehicle.STOP_REASON_REGULAR then
558 notificationType = FSBaseMission.INGAME_NOTIFICATION_OK
559 end
560
561 g_currentMission:addIngameNotification(notificationType, string.format(g_i18n:getText(AIVehicle.REASON_TEXT_MAPPING[reason]), spec.currentHelper.name))
562 end
563 end
564 end
565 end
566
567 g_helperManager:releaseHelper(spec.currentHelper)
568 spec.currentHelper = nil
569
570 g_farmManager:updateFarmStats(spec.startedFarmId, "workersHired", -1)
571
572 AIVehicle.numHirablesHired = math.max(AIVehicle.numHirablesHired - 1, 0)
573
574 if self.restoreVehicleCharacter ~= nil then
575 self:restoreVehicleCharacter()
576 end
577
578 if spec.mapAIHotspot ~= nil then
579 g_currentMission:removeMapHotspot(spec.mapAIHotspot)
580 spec.mapAIHotspot:delete()
581 spec.mapAIHotspot = nil
582 end
583
584 self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF, true)
585 if spec.isServer then
586 WheelsUtil.updateWheelsPhysics(self, 0, spec.lastSpeedReal*spec.movingDirection, 0, true, true)
587
588 if spec.driveStrategies ~= nil and #spec.driveStrategies > 0 then
589 for i=#spec.driveStrategies,1,-1 do
590 spec.driveStrategies[i]:delete()
591 table.remove(spec.driveStrategies, i)
592 end
593 spec.driveStrategies = {}
594 end
595 end
596
597 spec.isActive = false
598 spec.isTurning = false
599
600 -- move the collision far under the ground and remove it 200ms delayed (avoids problems with the traffic doesn't get the trigger onLeave callback of the collision box)
601 setTranslation(spec.aiTrafficCollision, 0, -1000, 0)
602 spec.aiTrafficCollisionRemoveDelay = 200
603
604 self:raiseAIEvent("onAIEnd", "onAIImplementEnd")
605 self:requestActionEventUpdate()
606 end
607end

getDirectionSnapAngle

Description
Get direction shape angle
Definition
getDirectionSnapAngle()
Return Values
floatdirectionshape angle
Code
635function AIVehicle:getDirectionSnapAngle()
636 return 0
637end

updateAIImplementData

Description
Fills aiImplementList with vehicles to use by ai
Definition
updateAIImplementData()
Code
641function AIVehicle:updateAIImplementData()
642 local spec = self.spec_aiVehicle
643
644 spec.aiImplementList = {}
645 self:addVehicleToAIImplementList(spec.aiImplementList)
646end

updateAIDriveStrategies

Description
Set drive strategies depending on the vehicle
Definition
updateAIDriveStrategies()
Code
658function AIVehicle:updateAIDriveStrategies()
659 local spec = self.spec_aiVehicle
660
661 if #spec.aiImplementList > 0 then
662 if spec.driveStrategies ~= nil and #spec.driveStrategies > 0 then
663 for i=#spec.driveStrategies,1,-1 do
664 spec.driveStrategies[i]:delete()
665 table.remove(spec.driveStrategies, i)
666 end
667 spec.driveStrategies = {}
668 end
669
670 local foundCombine = false
671 local foundBaler = false
672 for _,implement in pairs(spec.aiImplementList) do
673 if SpecializationUtil.hasSpecialization(Combine, implement.object.specializations) then
674 foundCombine = true
675 end
676 if SpecializationUtil.hasSpecialization(Baler, implement.object.specializations) then
677 foundBaler = true
678 end
679 end
680
681 foundCombine = foundCombine or SpecializationUtil.hasSpecialization(Combine, spec.specializations)
682 if foundCombine then
683 local driveStrategyCombine = AIDriveStrategyCombine:new()
684 driveStrategyCombine:setAIVehicle(self)
685