mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47:06 +01:00
559d105aa4
A grazing deer takes fright when the train is deer.reactiontime seconds of its speed away (default 3.5 s: it needs 2.0-2.75 s from the alarm to be off the track), but no nearer than deer.reactiondistance (default 20 m) for a slow or a standing train. So the slower the train, the closer it gets before the deer runs. The horn (deer.hornrange) sends it off sooner, as before. deer.fleedistance, of the test builds of this feature only and never in a release, goes; an eu07.ini that still has it is read with its value passed over. The way a deer runs away may go down the slope of an embankment (to 6 m below the sleepers) or up the one of a cutting (to 4 m above them), no steeper than 35 degrees between the samples of the ground, now 17 of them, about 1.5 m apart. Water, walls and cliffs still keep a deer away. Running, the deer leans up and down the slope by the ground under its hooves (at most 30 degrees, smoothed, about its side axis, which keeps the turn the shader reads the clip and the moment from), and grazes leaning where it stopped, drawn on its own, out of the groups of the instances of its model. No change to the assets: the same models and textures of the deer (models/animals/jelen_*.t3d, textures/animals/jelen_*). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GXgG7F4L42c2F9sDSAJbT2
92 lines
3.9 KiB
C++
92 lines
3.9 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <vector>
|
|
#include <glm/glm.hpp>
|
|
|
|
class TAnimModel;
|
|
class TDynamicObject;
|
|
namespace scene
|
|
{
|
|
class basic_region;
|
|
}
|
|
|
|
// deer at the tracks (Global.deer, off unless eu07.ini turns it on): every Global.deer_interval metres the train of the player
|
|
// covers, a deer is put (with the chance Global.deer_chance) on the path the train goes along, Global.deer_distance metres ahead
|
|
// of it, grazing (the model animals/jelen_je, animated by textures). the horn of the train within Global.deer_hornrange of it, or
|
|
// the train coming closer than Global.deer_reactiontime seconds of its speed (Global.deer_reactiondistance at least), frightens it:
|
|
// it raises its head (animals/jelen_zryw), looks at the train and runs away from the tracks in bounds (animals/jelen_skok, moved by
|
|
// the game along with the hooves, over the ground, leaning up and down its slopes), and grazes again where it stopped. the game picks the clip and the moment of each of the models (shader vat, vat_random -1), so one hands over to the next
|
|
// in the very same pose. the deer go once the train is past them. they aren't parts of the scenery (not saved, not edited)
|
|
namespace simulation
|
|
{
|
|
|
|
class deer_herd
|
|
{
|
|
public:
|
|
// after the trains moved, Deltatime: the time of the simulation the frame took, seconds
|
|
void update(double const Deltatime);
|
|
// deer about at the moment
|
|
std::size_t count() const
|
|
{
|
|
return m_deer.size();
|
|
}
|
|
|
|
private:
|
|
// the ground under the way the deer runs, at equal steps from its start to its end
|
|
static constexpr std::size_t Groundsamples{17};
|
|
enum class deer_state
|
|
{
|
|
grazing, // till it hears the horn or the train comes close (deer.reactiontime of its speed away)
|
|
alarmed, // grazing still, till the moment of the grazing its startle starts from (time)
|
|
startled, // raises its head (since time)
|
|
fleeing, // looks at the train and runs away (since time)
|
|
resting // grazes where it stopped, for good
|
|
};
|
|
struct deer
|
|
{
|
|
TAnimModel *model{nullptr};
|
|
glm::dvec3 start{0.0}; // where it stood when it started to run, or stands
|
|
glm::dvec3 heading{0.0, 0.0, 1.0}; // where its head points, level, of length 1
|
|
deer_state state{deer_state::grazing};
|
|
double frame{0.0}; // of the grazing at the time time
|
|
double time{0.0}; // of the simulation (Timer::GetTime()), seconds; see deer_state
|
|
int clip{0}; // of the startle: the moment of the grazing it starts from
|
|
int look{0}; // the clip of the flight which looks at the train
|
|
double closest{1e9}; // the train came this close, metres
|
|
std::array<double, Groundsamples> ground{}; // heights of the ground along the way it runs
|
|
double pitch{0.0}; // up the slope it runs on, degrees
|
|
double moved{0.0}; // the time of the simulation it was last moved at, seconds
|
|
};
|
|
// the train at Train going Speed (m/s), its horn sounding, at the time Now: the deer takes fright, runs, or goes (true) once the
|
|
// train is past it
|
|
bool tend(deer &Animal, glm::dvec3 const &Train, double const Speed, bool const Horn, double const Now) const;
|
|
// puts a deer on the path ahead of the train, where it's plain track (no switch) with ground beside it it can run over (slopes
|
|
// of embankments and cuttings too) and no platform near;
|
|
// false where there's none
|
|
bool spawn(TDynamicObject const &Vehicle);
|
|
// the deer took fright: when it starts, where it looks
|
|
void alarm(deer &Animal, glm::dvec3 const &Train, double const Now) const;
|
|
// the deer starts to run
|
|
void flee(deer &Animal) const;
|
|
// moves a running deer, true when it stopped
|
|
bool run(deer &Animal, double const Now) const;
|
|
|
|
std::vector<deer> m_deer;
|
|
double m_travelled{0.0}; // by the train since the last deer, metres
|
|
scene::basic_region const *m_region{nullptr}; // of the scenery the deer were put in
|
|
};
|
|
|
|
extern deer_herd Deer;
|
|
|
|
} // namespace simulation
|