48 std::uniform_real_distribution<float> unit(0.0f, 1.0f);
49 if (unit(random) < kThroughTheGate) {
51 return {.to_x = gate.
x, .to_z = gate.
z, .there =
kGateRadius / 2};
53 const float angle = 2.0f * std::numbers::pi_v<float> * unit(random);
55 const float distance = kReach * std::sqrt(unit(random));
56 return {.to_x = distance * std::cos(angle),
57 .to_z = distance * std::sin(angle)};
81 const protocol::World& world,
float x,
83 for (
const protocol::Monster& monster : world.monsters()) {
84 const auto kind = table.
kinds.find(monster.kind());
85 if (monster.motion() != protocol::MOTION_SKILL ||
86 kind == table.
kinds.end()) {
89 const auto skill = std::ranges::find(kind->second.skills(), monster.skill(),
90 &monsters::Skill::id);
91 if (skill == kind->second.skills().end()) {
94 monsters::Skill clear = *skill;
95 clear.set_size(skill->size() +
kClear);
96 if (!
InShape(clear, {.x = monster.x(), .z = monster.z()}, monster.yaw(),
102 const float dx = x - monster.x();
103 const float dz = z - monster.z();
104 const float away = std::hypot(dx, dz);
105 float out_x = away > 0.0f ? dx / away : 1.0f;
106 float out_z = away > 0.0f ? dz / away : 0.0f;
107 if (skill->shape() == monsters::CONE && skill->arc() < 180.0f) {
109 const float ahead_x = std::sin(monster.yaw());
110 const float ahead_z = std::cos(monster.yaw());
111 const float along = dx * ahead_x + dz * ahead_z;
112 const float across = dx * ahead_z - dz * ahead_x;
114 skill->arc() / 2.0f * std::numbers::pi_v<float> / 180.0f;
115 const float to_side = along * std::tan(half) - std::abs(across);
116 if (to_side < skill->size() - away) {
117 const float side = across >= 0.0f ? 1.0f : -1.0f;
118 out_x = side * ahead_z;
119 out_z = -side * ahead_x;
122 protocol::Input input;
Place RandomGate(std::mt19937 &random, int land)
One of the land's gates, at random, as players go through each of them.