Update: Translations from eints
[openttd-github.git] / src / script / api / script_base.cpp
blob18c3519b65ab696a6bb4fc30afe3ded59e7f1ab8
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 */
8 /** @file script_base.cpp Implementation of ScriptBase. */
10 #include "../../stdafx.h"
11 #include "script_base.hpp"
12 #include "script_error.hpp"
14 #include "../../safeguards.h"
16 /* static */ SQInteger ScriptBase::Rand()
18 return ScriptObject::GetRandomizer().Next();
21 /* static */ SQInteger ScriptBase::RandItem(SQInteger)
23 return ScriptBase::Rand();
26 /* static */ SQInteger ScriptBase::RandRange(SQInteger max)
28 max = Clamp<SQInteger>(max, 0, UINT32_MAX);
29 return ScriptObject::GetRandomizer().Next(max);
32 /* static */ SQInteger ScriptBase::RandRangeItem(SQInteger, SQInteger max)
34 return ScriptBase::RandRange(max);
37 /* static */ bool ScriptBase::Chance(SQInteger out, SQInteger max)
39 out = Clamp<SQInteger>(out, 0, UINT32_MAX);
40 max = Clamp<SQInteger>(max, 0, UINT32_MAX);
41 EnforcePrecondition(false, out <= max);
42 return ScriptBase::RandRange(max) < out;
45 /* static */ bool ScriptBase::ChanceItem(SQInteger, SQInteger out, SQInteger max)
47 return ScriptBase::Chance(out, max);