38 counts[type] += c->group_all[type].num_vehicle;
44 uint total_weight = 0;
46 weights[type] =
IntSqrt(counts[type]);
47 total_weight += weights[type];
51 if (total_weight == 0)
return nullptr;
54 uint r = InteractiveRandomRange(total_weight);
56 while (r >= weights[type]) {
61 assert(weights[type] > 0);
64 uint n = InteractiveRandomRange(counts[type]);
70 if (v->type != type)
continue;
73 if (!v->IsPrimaryVehicle())
continue;
76 if (n-- == 0)
return v;
102 static int movement_bias = 48;
105 if (exit_on_invalid && main_win->
viewport->follow_vehicle == VehicleID::Invalid()) {
116 if (v->cur_speed > 0 && !
Chance16I(1, movement_bias, InteractiveRandom())) {
123 if (v->cur_speed == 0 &&
Chance16I(3, 4, InteractiveRandom())) {
134 if (new_vehicle ==
nullptr)
return;
137 main_win->
viewport->CancelFollow(*main_win);
138 main_win->
viewport->follow_vehicle = new_vehicle->index;
173 main_win->
viewport->CancelFollow(*main_win);
199 _switch_timer = std::make_unique<IntervalTimer<TimerGameTick>>(
Iterate a range of enum values.
@ None
These timers can be executed in any order; the order is not relevant.
Definition of stuff that is very close to a company, like the company struct itself.
uint32_t IntSqrt(uint32_t num)
Compute the integer square root.
Pseudo random number generator.
bool Chance16I(const uint32_t a, const uint32_t b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
A number of safeguards to prevent using unsafe methods.
static const auto _screensaver_check_interval
We use a fixed period for updating the screensaver's followed vehicle, stored in this variable.
static const Vehicle * PickRandomVehicle()
Selects a random vehicle, picking the type by the square root of its number of vehicles,...
static void SwitchVehicle(bool exit_on_invalid=true)
Switches the current followed vehicle to a new random one.
void ToggleScreensaverMode()
Enters or exits "Screensaver Mode".
void ExitScreensaverMode()
Exits "Screensaver Mode".
static std::unique_ptr< IntervalTimer< TimerGameTick > > _switch_timer
The screensaver runs on an interval timer, stored in this pointer when it is running and freed when i...
Exports a function to turn on and off a screensaver mode.
Definition of base types and functions in a cross-platform compatible way.
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static Vehicle * GetIfValid(auto index)
Data structure for an opened window.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition of Interval and OneShot timers.
Definition of the tick-based game-timer.
Base class for all vehicles.
Types related to vehicles.
VehicleType
Available vehicle types.
@ CompanyEnd
Last company-ownable type.
EnumIndexArray< T, VehicleType, Tend > VehicleTypeIndexArray
Array with VehicleType as index.
Window * GetMainWindow()
Get the main window, i.e.
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.