Curation round 17: Theora and Vorbis cutscene videos, Ludovico, Epic and Dr. Fetus, Tractor Beam and Eye of the Occult, familiars and blue spiders, fortune teller and restock, the Bag of Crafting and four tainted characters, ten enemies, water and the ultra secret door, Isaac, ???, the Lamb and Hush
This commit is contained in:
1 parent
e9de039d0f
commit
024cb12016
133 files changed
+13325
-2520
No files matched your search
+174
-11
@@ -1,6 +1,7 @@
|
||||
#include "homing_laser.h"
|
||||
#include "boss_ai.h"
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_knife.h"
|
||||
#include "entity_laser.h"
|
||||
#include "entity_player.h"
|
||||
#include "entity_tear.h"
|
||||
@@ -27,6 +28,19 @@ constexpr size_t HUNT_MAX_POINTS = 25;
|
||||
constexpr float HUNT_TENSION = 0.4f;
|
||||
constexpr float HUNT_MIN_LENGTH_SQUARED = 0.01f;
|
||||
|
||||
// A homing path: up to six points, pulled only off segments at least 120 long and not within 80 of their ends.
|
||||
constexpr size_t HOMING_MAX_POINTS = 6;
|
||||
constexpr float HOMING_SEGMENT_MIN_SQUARED = 14400;
|
||||
constexpr float HOMING_END_CLEARANCE_SQUARED = 6400;
|
||||
|
||||
// Eye of the Occult's bend: the thirds of the curve, the margin its end keeps from the wall, its handles' length and
|
||||
// the kink near the start of a player's loop.
|
||||
constexpr float OCCULT_THIRD = 0.333f;
|
||||
constexpr float OCCULT_TWO_THIRDS = 0.666f;
|
||||
constexpr float OCCULT_WALL_MARGIN = 20;
|
||||
constexpr float OCCULT_HANDLE = 50;
|
||||
constexpr float OCCULT_KINK = 35;
|
||||
|
||||
// A point on the cubic curve from one bezier point to the next, t from 0 to 1.
|
||||
static Vector bezier_evaluate(const BezierPoint& from, const BezierPoint& to, float t)
|
||||
{
|
||||
@@ -165,9 +179,122 @@ static void homing_hunt(HomingLaser& path, const std::vector<Entity*>& targets)
|
||||
path.compute_bezier_handles(HUNT_TENSION);
|
||||
}
|
||||
|
||||
// Eye of the Occult's bend for a laser no player aims: a curve through the target, a third and two thirds of the way
|
||||
// along the straight beam stretched to the target's distance, going on past the target to the wall.
|
||||
static void occult_curve(HomingLaser& path, const Vector& target)
|
||||
{
|
||||
Vector origin = path.origin;
|
||||
Vector toTarget = vector_sub(target, origin);
|
||||
Vector line = vector_sub(path.endPoint, origin);
|
||||
float lineLength = vector_length(line);
|
||||
if (lineLength > 0) line = vector_scale(line, vector_length(toTarget) / lineLength);
|
||||
|
||||
Vector stretched = vector_sub(vector_add(origin, line), origin);
|
||||
auto blend = [&](float t) {
|
||||
Vector along = vector_add(vector_scale(stretched, t), origin);
|
||||
return vector_add(vector_scale(vector_sub(vector_add(vector_scale(toTarget, t), origin), along), t), along);
|
||||
};
|
||||
Vector first = blend(OCCULT_THIRD);
|
||||
Vector second = blend(OCCULT_TWO_THIRDS);
|
||||
path.endPoint = Entity_Laser::CalculateEndPoint(target, vector_sub(target, second), {}, nullptr, OCCULT_WALL_MARGIN);
|
||||
|
||||
Vector beyond = vector_sub(path.endPoint, target);
|
||||
path.bezier.clear();
|
||||
path.bezier.push_back({origin, origin, first});
|
||||
path.bezier.push_back({target, second, vector_add(vector_scale(beyond, OCCULT_THIRD), target)});
|
||||
path.bezier.push_back({path.endPoint, vector_add(vector_scale(beyond, OCCULT_TWO_THIRDS), target), path.endPoint});
|
||||
}
|
||||
|
||||
// Eye of the Occult's bend for a player's laser: the path's last point is swung out past a kink near its start, then
|
||||
// through the target and back to where it ended, with axis-aligned handles.
|
||||
static void occult_loop(HomingLaser& path, const Vector& target)
|
||||
{
|
||||
size_t count = path.bezier.size();
|
||||
Vector start = count < 2 ? path.origin : path.bezier[count - 2].point;
|
||||
Vector last = count == 0 ? path.endPoint : path.bezier[count - 1].point;
|
||||
Vector toTarget = vector_normalized(vector_sub(target, start));
|
||||
Vector back = vector_normalized(vector_sub(last, target));
|
||||
Vector line = vector_normalized(vector_sub(last, start));
|
||||
Vector handle = vector_scale(line, OCCULT_HANDLE);
|
||||
if (count > 1) path.bezier.pop_back();
|
||||
if (path.bezier.empty()) path.bezier.push_back({start, start, vector_add(start, handle)});
|
||||
|
||||
Vector kink = vector_add(vector_add(vector_make(-line.y, line.x), vector_scale(line, OCCULT_KINK)), start);
|
||||
path.bezier.push_back({kink, vector_sub(kink, handle), vector_add(kink, vector_scale(toTarget, OCCULT_HANDLE))});
|
||||
path.bezier.push_back({target, vector_sub(target, handle), vector_add(target, handle)});
|
||||
path.bezier.push_back({last, vector_sub(last, vector_scale(back, OCCULT_HANDLE)), last});
|
||||
path.compute_axis_bezier_handles();
|
||||
}
|
||||
|
||||
// Eye of the Occult: a laser carrying it bends toward its target position, or its player's Marked target.
|
||||
static void occult_bend(HomingLaser& path)
|
||||
{
|
||||
Entity_Laser* laser = path.owner && path.owner->type == ENTITY_LASER ? static_cast<Entity_Laser*>(path.owner) : nullptr;
|
||||
if (!laser || !laser->tearFlags[TEAR_OCCULT]) return;
|
||||
|
||||
Vector target = laser->targetPosition;
|
||||
Entity* spawner = laser->spawnerEntity;
|
||||
Entity_Player* player = spawner && spawner->is_player() ? spawner->ToPlayer() : nullptr;
|
||||
if (player && player->markedTarget) target = player->markedTarget->pos;
|
||||
if (vector_is_zero(target)) return;
|
||||
if (player) occult_loop(path, target);
|
||||
else occult_curve(path, target);
|
||||
}
|
||||
|
||||
// A homing straight path pulls a point onto each target it passes near (closer than the reach, ahead of the point and
|
||||
// not within 80 of either end of a segment at least 120 long), up to six points. A longer path moves its inner points
|
||||
// onto the targets they pass near instead.
|
||||
static void homing_bend(HomingLaser& path, std::vector<Entity*>& targets)
|
||||
{
|
||||
float reachSquared = path.reach * path.reach;
|
||||
float unusedT = 0;
|
||||
if (path.bezier.size() != 2)
|
||||
{
|
||||
bool isMoved = false;
|
||||
for (size_t i = 1; i + 1 < path.bezier.size(); i++)
|
||||
for (auto target = targets.begin(); target != targets.end(); target++)
|
||||
{
|
||||
Vector spot = (*target)->pos;
|
||||
if (bezier_closest_point(spot, path.bezier[i], path.bezier[i + 1], unusedT) >= reachSquared) continue;
|
||||
path.bezier[i].point = spot;
|
||||
targets.erase(target);
|
||||
isMoved = true;
|
||||
break;
|
||||
}
|
||||
if (isMoved) path.compute_axis_bezier_handles();
|
||||
return;
|
||||
}
|
||||
|
||||
bool isInserted = true;
|
||||
while (isInserted && path.bezier.size() < HOMING_MAX_POINTS)
|
||||
{
|
||||
isInserted = false;
|
||||
for (size_t segment = 0; segment + 1 < path.bezier.size() && !isInserted; segment++)
|
||||
{
|
||||
BezierPoint& from = path.bezier[segment];
|
||||
Vector to = path.bezier[segment + 1].point;
|
||||
if (vector_length_squared(vector_sub(to, from.point)) < HOMING_SEGMENT_MIN_SQUARED) continue;
|
||||
for (auto target = targets.begin(); target != targets.end(); target++)
|
||||
{
|
||||
Vector spot = (*target)->pos;
|
||||
if (bezier_closest_point(spot, from, path.bezier[segment + 1], unusedT) >= reachSquared) continue;
|
||||
bool isAhead = vector_dot(vector_sub(from.handleOut, from.point), vector_sub(spot, from.point)) > 0;
|
||||
if (!isAhead || vector_length_squared(vector_sub(spot, from.point)) <= HOMING_END_CLEARANCE_SQUARED ||
|
||||
vector_length_squared(vector_sub(spot, to)) <= HOMING_END_CLEARANCE_SQUARED)
|
||||
continue;
|
||||
path.bezier.insert(path.bezier.begin() + (long)segment + 1, {spot, {}, {}});
|
||||
targets.erase(target);
|
||||
isInserted = true;
|
||||
path.compute_axis_bezier_handles();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0099c790 Lays out the path's bezier points: a straight one from the origin to the end unless some are already
|
||||
// there, then for a path that hits players one hunting its targets. Eye of the Occult's bend and the homing and
|
||||
// other types' bends toward their targets are not reconstructed yet.
|
||||
// there, bent by Eye of the Occult, then toward its targets for a homing path, through every target of another type
|
||||
// for that path type, or hunting its targets for a path that hits players.
|
||||
void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source)
|
||||
{
|
||||
if (bezier.empty())
|
||||
@@ -179,12 +306,14 @@ void HomingLaser::build_bezier_path(BezierPathType pathType, Entity* source)
|
||||
|
||||
std::vector<Entity*> targets;
|
||||
if (pathType != BEZIER_PATH_STRAIGHT) targets = homing_targets_get(pathType, source);
|
||||
Entity_Laser* laser = owner && owner->type == ENTITY_LASER ? static_cast<Entity_Laser*>(owner) : nullptr;
|
||||
if (laser && laser->tearFlags[TEAR_OCCULT])
|
||||
reconstruction_missing("HomingLaser::build_bezier_path 0099c790: Eye of the Occult's bend");
|
||||
if (pathType == BEZIER_PATH_HOMING || pathType == BEZIER_PATH_OTHER_TYPES)
|
||||
reconstruction_missing("HomingLaser::build_bezier_path 0099c790: a homing path");
|
||||
if (pathType == BEZIER_PATH_WITH_PLAYERS && bezier.size() == 2) homing_hunt(*this, targets);
|
||||
occult_bend(*this);
|
||||
if (pathType == BEZIER_PATH_HOMING) homing_bend(*this, targets);
|
||||
else if (pathType == BEZIER_PATH_OTHER_TYPES && bezier.size() == 2)
|
||||
{
|
||||
for (Entity* target : targets) bezier.insert(bezier.end() - 1, {target->pos, {}, {}});
|
||||
compute_axis_bezier_handles();
|
||||
}
|
||||
else if (pathType == BEZIER_PATH_WITH_PLAYERS && bezier.size() == 2) homing_hunt(*this, targets);
|
||||
}
|
||||
|
||||
// 0099e360 Samples the bezier path evenly along its length, then eases the kept samples toward them: a ring all at
|
||||
@@ -361,12 +490,46 @@ Entity* HomingLaser::find_targets(Vector& outPosition, Vector& outDirection, int
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The path shapes of the tear flags and homing are not reconstructed yet.
|
||||
// The axis a vector leans along most, keeping its length along it (vertical on a tie).
|
||||
static Vector vector_axis_part(Vector v)
|
||||
{
|
||||
return std::fabs(v.x) <= std::fabs(v.y) ? vector_make(0, v.y) : vector_make(v.x, 0);
|
||||
}
|
||||
|
||||
// 0099dca0
|
||||
// 0099dca0 Gives the path right-angled handles: the first point's out handle runs along the axis its handle leans
|
||||
// along, half way to the next point. Each inner point's handles run across the axis its neighbours' directions add
|
||||
// up along, toward the previous point, half way to each neighbour (twice as far when the previous point's handle
|
||||
// points away from it). The last point's in handle runs half way along the axis toward the point before it.
|
||||
void HomingLaser::compute_axis_bezier_handles()
|
||||
{
|
||||
reconstruction_missing("HomingLaser::compute_axis_bezier_handles 0099dca0");
|
||||
if (bezier.size() < 2) return;
|
||||
|
||||
BezierPoint& first = bezier[0];
|
||||
Vector firstAxis = vector_cardinal(vector_sub(first.handleOut, first.point));
|
||||
Vector firstReach = vector_scale(firstAxis, vector_length(vector_sub(bezier[1].point, first.point)) * BEZIER_HALF);
|
||||
first.handleOut = vector_add(first.point, firstReach);
|
||||
bezier[1].handleIn = vector_sub(bezier[1].point, firstReach);
|
||||
|
||||
for (size_t i = 1; i + 1 < bezier.size(); i++)
|
||||
{
|
||||
BezierPoint& previous = bezier[i - 1];
|
||||
BezierPoint& point = bezier[i];
|
||||
Vector toPrevious = vector_sub(previous.point, point.point);
|
||||
Vector toNext = vector_sub(bezier[i + 1].point, point.point);
|
||||
float nextLength = vector_length(toNext);
|
||||
Vector sum = vector_add(vector_normalized(toNext), vector_normalized(toPrevious));
|
||||
Vector axis = vector_cardinal(sum);
|
||||
Vector across = vector_make(axis.y, -axis.x);
|
||||
if (vector_dot(toPrevious, across) < 0) across = vector_scale(across, -1);
|
||||
if (vector_dot(vector_sub(previous.handleOut, previous.point), vector_sub(point.point, previous.point)) < 0)
|
||||
across = vector_scale(across, 2);
|
||||
point.handleOut = vector_add(point.point, vector_scale(across, -nextLength * BEZIER_HALF));
|
||||
point.handleIn = vector_add(point.point, vector_scale(across, vector_length(toPrevious) * BEZIER_HALF));
|
||||
}
|
||||
|
||||
BezierPoint& last = bezier.back();
|
||||
Vector toPrevious = vector_axis_part(vector_sub(bezier[bezier.size() - 2].point, last.point));
|
||||
last.handleIn = vector_add(last.point, vector_scale(toPrevious, BEZIER_HALF));
|
||||
}
|
||||
|
||||
// 0099e160 Smooths the path: each point's handles lie along the line from its neighbours, scaled by the tension
|
||||
|
||||
Reference in new issue
Block a user