1 /*
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/>.
6  */
7 
8 /** @file script_base.hpp Everything to query basic things. */
9 
10 #ifndef SCRIPT_BASE_HPP
11 #define SCRIPT_BASE_HPP
12 
13 #include "script_object.hpp"
14 
15 /**
16  * Class that handles some basic functions.
17  * @api ai game
18  *
19  * @note The random functions are not called Random and RandomRange, because
20  *        RANDOM_DEBUG does some tricky stuff, which messes with those names.
21  * @note In MP we cannot use Random because that will cause desyncs (scripts are
22  *        ran on the server only, not on all clients). This means that
23  *        we use InteractiveRandom in MP. Rand() takes care of this for you.
24  */
25 class ScriptBase : public ScriptObject {
26 public:
27 	/**
28 	 * Get a random value.
29 	 * @return A random value between 0 and MAX(uint32).
30 	 */
31 	static uint32 Rand();
32 
33 	/**
34 	 * Get a random value.
35 	 * @param unused_param This parameter is not used, but is needed to work with lists.
36 	 * @return A random value between 0 and MAX(uint32).
37 	 */
38 	static uint32 RandItem(int unused_param);
39 
40 	/**
41 	 * Get a random value in a range.
42 	 * @param max The first number this function will never return (the maximum it returns is max - 1).
43 	 * @return A random value between 0 .. max - 1.
44 	 */
45 	static uint RandRange(uint max);
46 
47 	/**
48 	 * Get a random value in a range.
49 	 * @param unused_param This parameter is not used, but is needed to work with lists.
50 	 * @param max The first number this function will never return (the maximum it returns is max - 1).
51 	 * @return A random value between 0 .. max - 1.
52 	 */
53 	static uint RandRangeItem(int unused_param, uint max);
54 
55 	/**
56 	 * Returns approximately 'out' times true when called 'max' times.
57 	 *   After all, it is a random function.
58 	 * @param out How many times it should return true.
59 	 * @param max Out of this many times.
60 	 * @pre \a out is at most equal to \a max.
61 	 * @return True if the chance worked out.
62 	 */
63 	static bool Chance(uint out, uint max);
64 
65 	/**
66 	 * Returns approximately 'out' times true when called 'max' times.
67 	 *   After all, it is a random function.
68 	 * @param unused_param This parameter is not used, but is needed to work with lists.
69 	 * @param out How many times it should return true.
70 	 * @param max Out of this many times.
71 	 * @pre \a out is at most equal to \a max.
72 	 * @return True if the chance worked out.
73 	 */
74 	static bool ChanceItem(int unused_param, uint out, uint max);
75 };
76 
77 #endif /* SCRIPT_BASE_HPP */
78