2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file script_base.hpp Everything to query basic things. */
10 #ifndef SCRIPT_BASE_HPP
11 #define SCRIPT_BASE_HPP
13 #include "script_object.hpp"
16 * Class that handles some basic functions.
19 * @note The random functions are not called Random and RandomRange, because
20 * RANDOM_DEBUG does some tricky stuff, which messes with those names.
22 class ScriptBase
: public ScriptObject
{
26 * @return A random value between 0 and MAX(uint32_t).
28 static SQInteger
Rand();
32 * @param unused_param This parameter is not used, but is needed to work with lists.
33 * @return A random value between 0 and MAX(uint32_t).
35 static SQInteger
RandItem(SQInteger unused_param
);
38 * Get a random value in a range.
39 * @param max The first number this function will never return (the maximum it returns is max - 1).
40 * The value will be clamped to 0 .. MAX(uint32_t).
41 * @return A random value between 0 .. max - 1.
43 static SQInteger
RandRange(SQInteger max
);
46 * Get a random value in a range.
47 * @param unused_param This parameter is not used, but is needed to work with lists.
48 * @param max The first number this function will never return (the maximum it returns is max - 1).
49 * The value will be clamped to 0 .. MAX(uint32_t).
50 * @return A random value between 0 .. max - 1.
52 static SQInteger
RandRangeItem(SQInteger unused_param
, SQInteger max
);
55 * Returns approximately 'out' times true when called 'max' times.
56 * After all, it is a random function.
57 * @param out How many times it should return true.
58 * The value will be clamped to 0 .. MAX(uint32_t).
59 * @param max Out of this many times.
60 * The value will be clamped to 0 .. MAX(uint32_t).
61 * @pre \a out is at most equal to \a max.
62 * @return True if the chance worked out.
64 static bool Chance(SQInteger out
, SQInteger max
);
67 * Returns approximately 'out' times true when called 'max' times.
68 * After all, it is a random function.
69 * @param unused_param This parameter is not used, but is needed to work with lists.
70 * @param out How many times it should return true.
71 * The value will be clamped to 0 .. MAX(uint32_t).
72 * @param max Out of this many times.
73 * The value will be clamped to 0 .. MAX(uint32_t).
74 * @pre \a out is at most equal to \a max.
75 * @return True if the chance worked out.
77 static bool ChanceItem(SQInteger unused_param
, SQInteger out
, SQInteger max
);
80 #endif /* SCRIPT_BASE_HPP */