Curation round 14: console and Lua API, effects, lasers, enemies, eleven bosses, the Depths and Mom, status effects, the playable characters
This commit is contained in:
1 parent
8ae02a8422
commit
6e3da161fc
138 files changed
+16754
-6825
No files matched your search
@@ -0,0 +1,107 @@
|
||||
#include "entity_familiar.h"
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_poop.h"
|
||||
#include "npc_ai.h"
|
||||
#include "platform.h"
|
||||
#include "room_grid.h"
|
||||
|
||||
// A player keeps at most this many Dips, the first dip subtype a thrown poop turns into a plain Dip, and the last.
|
||||
constexpr int DIP_OWNED_LIMIT = 32;
|
||||
constexpr int DIP_PLAIN_FROM = POOP_GIGA_TOP_LEFT;
|
||||
constexpr int DIP_PLAIN_TO = POOP_CHARMING;
|
||||
// How much a Dip is worth keeping by subtype, above how long it has lived: corn first to go, the rarer ones last.
|
||||
constexpr float DIP_KEEP_SCORES[] = {0, 10000, -200, 20000, 20000, 10000, 20000, 0, 0, 0, 0, 0, 10000, 10000, 10000};
|
||||
constexpr float DIP_KEEP_SCORE_MAX = 1e10f;
|
||||
// A Dip thrown toward a spot: how far around a free spot it lands, its speed toward it and its lift.
|
||||
constexpr float DIP_SPOT_DISTANCE = 80;
|
||||
constexpr float DIP_LANDING_SPREAD = 20;
|
||||
constexpr float DIP_THROW_SPEED = 0.04f;
|
||||
constexpr float DIP_THROW_LIFT = -8;
|
||||
constexpr int DIP_THROWN_STATE = 2;
|
||||
// The share of a versus player's color a Dip's glow takes, and the color slot of a player without one.
|
||||
constexpr float DIP_VERSUS_GLOW = 0.25f;
|
||||
constexpr int DIP_VERSUS_NO_SLOT = 5;
|
||||
|
||||
// 00639000 Spawns a Dip of a subtype for its owner (the poop variants without a Dip of their own give a plain one),
|
||||
// first killing the owner's least worth keeping while it has more than 32. In versus it takes its player's color.
|
||||
Entity* Entity_Familiar::ThrowDip(int subType, const Vector& position, Entity* spawner)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Entity_Familiar* worst = nullptr;
|
||||
float worstScore = DIP_KEEP_SCORE_MAX;
|
||||
int count = 0;
|
||||
for (Entity_Familiar* dip : familiar_query(DIP))
|
||||
{
|
||||
if (dip->isDead || dip->player != spawner) continue;
|
||||
|
||||
float score = dip->subtype >= 0 && dip->subtype < (int)std::size(DIP_KEEP_SCORES)
|
||||
? DIP_KEEP_SCORES[dip->subtype]
|
||||
: 0;
|
||||
score -= (float)(g_game->frameCount - dip->spawnFrame);
|
||||
if (score < worstScore)
|
||||
{
|
||||
worst = dip;
|
||||
worstScore = score;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (count <= DIP_OWNED_LIMIT) break;
|
||||
if (!worst)
|
||||
{
|
||||
log_printf(LOG_WARN, "Entity_Familiar::ThrowDip: couldn't find a candidate for removal, remaining: %d\n",
|
||||
count);
|
||||
break;
|
||||
}
|
||||
worst->Kill(EntityRef());
|
||||
}
|
||||
|
||||
bool isPlain = subType >= DIP_PLAIN_FROM && subType <= DIP_PLAIN_TO;
|
||||
Entity* dip = g_game->Spawn({.position = position,
|
||||
.spawner = spawner,
|
||||
.subType = isPlain ? 0 : subType,
|
||||
.type = ENTITY_FAMILIAR,
|
||||
.variant = DIP,
|
||||
.seed = Random()});
|
||||
dip->ClearEntityFlags(FLAG_APPEAR);
|
||||
if (!g_game->deathmatchManager.is_active() || !spawner || spawner->type != ENTITY_PLAYER) return dip;
|
||||
|
||||
std::array<int, COOP_SLOT_COUNT>& slots = g_game->playerManager.colorControllers;
|
||||
auto slot = std::ranges::find(slots, static_cast<Entity_Player*>(spawner)->controllerIndex);
|
||||
int colorSlot = slot == slots.end() ? DIP_VERSUS_NO_SLOT : (int)(slot - slots.begin());
|
||||
KColor color = PlayerManager::GetPlayerColorValue(colorSlot);
|
||||
dip->sprite.color = {{color._red, color._green, color._blue, 1},
|
||||
{0, 0, 0, 0},
|
||||
{color._red * DIP_VERSUS_GLOW, color._green * DIP_VERSUS_GLOW, color._blue * DIP_VERSUS_GLOW}};
|
||||
return dip;
|
||||
}
|
||||
|
||||
// 006393a0 Throws a Dip from a position to a target, or without one to a random spot near a free one 80 away. It
|
||||
// arcs there, as thrown Dips do.
|
||||
Entity* spawn_dip_at(int subType, const Vector* position, Entity* spawner, const Vector* targetPosition)
|
||||
{
|
||||
Vector target = *targetPosition;
|
||||
if (vector_is_zero(target))
|
||||
{
|
||||
Vector direction = random_direction();
|
||||
Vector probe = vector_make(direction.x * DIP_SPOT_DISTANCE + position->x,
|
||||
direction.y * DIP_SPOT_DISTANCE + position->y);
|
||||
Vector spot = room_free_pickup_position_find(
|
||||
{.position = probe, .step = DIP_SPOT_DISTANCE, .isAvoidActiveEntities = true});
|
||||
Vector landing = random_direction();
|
||||
float spread = random_unit();
|
||||
target = vector_make(landing.x * spread * DIP_LANDING_SPREAD + spot.x,
|
||||
landing.y * spread * DIP_LANDING_SPREAD + spot.y);
|
||||
}
|
||||
|
||||
Vector velocity =
|
||||
vector_make((target.x - position->x) * DIP_THROW_SPEED, (target.y - position->y) * DIP_THROW_SPEED);
|
||||
Entity_Familiar& dip = *static_cast<Entity_Familiar*>(Entity_Familiar::ThrowDip(subType, *position, spawner));
|
||||
dip.targetPosition = target;
|
||||
dip.velocity = velocity;
|
||||
dip.orbitSpeed = DIP_THROW_LIFT;
|
||||
dip.orbitDistance = velocity;
|
||||
dip.state = DIP_THROWN_STATE;
|
||||
return &dip;
|
||||
}
|
||||
Reference in new issue
Block a user