Loading

Paste #plegjbi4y

  1. Index: src/script/api/script_controller.hpp
  2. ===================================================================
  3. --- src/script/api/script_controller.hpp        (revision 27110)
  4. +++ src/script/api/script_controller.hpp        (working copy)
  5. @@ -18,8 +18,26 @@
  6.  
  7.  /**
  8.   * The Controller, the class each Script should extend. It creates the Script,
  9. - *  makes sure the logic kicks in correctly, and that GetTick() has a valid
  10. + *  makes sure the logic kicks in correctly, and that #GetTick() has a valid
  11.   *  value.
  12. + *
  13. + * When starting a new game, or when loading a game, OpenTTD tries to match a
  14. + *  script that matches to the specified version as close as possible. It tries
  15. + *  (from first to last, stopping as soon as the attempt succeeds)
  16. + *
  17. + *  - load the exact same version of the same script,
  18. + *  - load the latest version of the same script that supports loading data from
  19. + *    the saved version (the version of saved data must be equal or greater
  20. + *    than ScriptInfo::MinVersionToLoad),
  21. + *  - load the latest version of the same script (ignoring version requirements),
  22. + *  - (for AIs) load a random AI, and finally
  23. + *  - (for AIs) load the dummy AI.
  24. + *
  25. + * If a script was found, an instance is constructed of the class derived from ScriptController.
  26. + * If there is script data available in the loaded game, #Load is called with the data.
  27. + * Finally, #Start is called to start execution of the script.
  28. + * See also http://wiki.openttd.org/AI:Save/Load for more details.
  29. + *
  30.   * @api ai game
  31.   */
  32.  class ScriptController {
  33. @@ -46,7 +64,49 @@
  34.          */
  35.         void Start();
  36.  
  37. +#ifdef DOXYGEN_API
  38.         /**
  39. +        * Save the state of the script.
  40. +        *
  41. +        * By implementing this function, you can store some data inside the savegame.
  42. +        *   The function should return a table with the information you want to store.
  43. +        *   You can only store:
  44. +        *
  45. +        *   - integers,
  46. +        *   - strings,
  47. +        *   - arrays (max. 25 levels deep),
  48. +        *   - tables (max. 25 levels deep),
  49. +        *   - booleans, and
  50. +        *   - nulls.
  51. +        *
  52. +        * In particular, instances of classes can't be saved including
  53. +        *   ScriptList. Such a list should be converted to an array or table on
  54. +        *   save and converted back on load.
  55. +        *
  56. +        * The function is called as soon as the user saves the game,
  57. +        *   independently of other activities of the script. The script is not
  58. +        *   notified of the call. To avoid race-conditions between #Save and the
  59. +        *   other script code, change variables directly after a #Sleep, it is
  60. +        *   very unlikely, to get interrupted at that point in the execution.
  61. +        * See also http://wiki.openttd.org/AI:Save/Load for more details.
  62. +        *
  63. +        * @note No other information is saved than the table returned by #Save.
  64. +        *   For example all pending events are lost as soon as the game is loaded.
  65. +        *
  66. +        * @return Data of the script that should be stored in the save game.
  67. +        */
  68. +       SquirrelTable Save();
  69. +
  70. +       /**
  71. +        * Load saved data just before calling #Start.
  72. +        * The function is only called when there is data to load.
  73. +        * @param version Version number of the script that created the \a data.
  74. +        * @param data Data that was saved (return value of #Save).
  75. +        */
  76. +       void Load(int version, SquirrelTable data);
  77. +#endif /* DOXYGEN_API */
  78. +
  79. +       /**
  80.          * Find at which tick your script currently is.
  81.          * @return returns the current tick.
  82.          */

Comments