OpenTTDDevBlackBook/NoAI/Adding a squirrel function

From OpenTTD
Jump to: navigation, search
HAL (Hardware Abstraction Layer)


Window System

Using the Window System
Colour codes that exist in OpenTTD
Adding a text box
Understanding the widget focus system


Add a setting
Add a squirrel function
Do a savegame BUMP

The Map / Scenario

Understanding the Dynamic Landscape Array
Understanding the SaveGame Handler
HOWTO - Create good Scenarios
HOWTO - Add New Town Name Generators

The actual simulation

Using Orders
Train Acceleration

Language and Strings

Format of langfiles
Using OpenTTD Strings
List of Special Strings


The Core Interface

Starting a Server
Connecting to a Server
Using the list of LAN/Internet Games

The OpenTTD TCP Protocol
The OpenTTD UDP Protocol
HOWTO - Debug desyncs

Ingame Console

The Console Window
Using Console Scripting
HOWTO - Add Functions/Commands to the Console
HOWTO - Add Variables to the Console
HOWTO - Direct Variable Access using ICONSOLE_VAR_POINTER
OpenTTD Console Commands
OpenTTD Console Variables
Development History

Adding a squirrel function

To make a new C++ function available to the Squirrel code of the NoAI framework, do

  • Implement the function
    • Add the function declaration to one of the classes in src/ai/api/ai_*.hpp,
    • Also add an implementation in the .cpp file,
    • To make Squirrel aware of the changes, generate a new Squirrel interface file with Call that script from within the src/ai/api directory.
  • Recompile OpenTTD in the usual way to make the new function available to the NoAI framework.
  • Write test-cases for the new function in bin/ai/regression.
    • In regression.nut, add Squirrel code that tests your new function, and outputs results.
    • In regression.txt, add the new expected output.
  • Run the regression test by executing make regression. When differences are found, they will be displayed.
  • Add the function to the NoAI changelog in src/ai/api/ai_changelog.hpp.

When all works as expected, you can write some Squirrel code to enjoy using your new function.

Personal tools