Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Hollow Knight: Gruz Mother, battle gates and arenas

Mason Chend094358c947f
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.bin
index 53fd708e..ae5295e6 100644
Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differ
diff --git a/games/hollowknight/src/data.h b/games/hollowknight/src/data.h
index d460df6e..0713404b 100644
--- a/games/hollowknight/src/data.h
+++ b/games/hollowknight/src/data.h
@@ -325,16 +325,41 @@
#define CLIP_FKHEAD_HEAD_HIT 266
#define CLIP_FKHEAD_HEAD_IDLE 267
#define CLIP_FKHEAD_HEAD_SPAZ 268
-#define CLIP_BULLET_IDLE 269
-#define CLIP_BULLET_IMPACT 270
-#define CLIP_BULLET_SHOCKWAVE_SPURT 271
-#define SPRITE_HERO_LIGHT 1129
-#define SPRITE_DIALOGUE_BACKBOARD 1130
-#define SPRITE_PROMPT_SHADOW 1131
-#define SPRITE_CORPSE_NAIL 1132
-#define SPRITE_FK_BARREL 1133
-#define SPRITE_FK_STAFF 1134
-#define SPRITE_DIGIT0 1321
+#define CLIP_GFLY_BURST 269
+#define CLIP_GFLY_CHARGE 270
+#define CLIP_GFLY_CHARGE_ANTIC 271
+#define CLIP_GFLY_CHARGE_RECOVER 272
+#define CLIP_GFLY_DEATH 273
+#define CLIP_GFLY_FALL 274
+#define CLIP_GFLY_FLY 275
+#define CLIP_GFLY_GURGLE_LOOP 276
+#define CLIP_GFLY_GURGLE_ONCE 277
+#define CLIP_GFLY_SLAM_DOWN 278
+#define CLIP_GFLY_SLAM_END 279
+#define CLIP_GFLY_SLAM_UP 280
+#define CLIP_GFLY_SLEEP 281
+#define CLIP_GFLY_STOP 282
+#define CLIP_GFLY_WAKE 283
+#define CLIP_GFLY_WIGGLE 284
+#define CLIP_BGATE_BG_OPENED 285
+#define CLIP_BGATE_BG_CLOSE_1 286
+#define CLIP_BGATE_BG_CLOSE_2 287
+#define CLIP_BGATE_BG_OPEN 288
+#define CLIP_BGATE_BG_CLOSED 289
+#define CLIP_BGATE_BONE_GATE_OPENED 290
+#define CLIP_BGATE_BONE_GATE_CLOSE 291
+#define CLIP_BGATE_BONE_GATE_CLOSED 292
+#define CLIP_BGATE_BONE_GATE_OPEN 293
+#define CLIP_BULLET_IDLE 294
+#define CLIP_BULLET_IMPACT 295
+#define CLIP_BULLET_SHOCKWAVE_SPURT 296
+#define SPRITE_HERO_LIGHT 1191
+#define SPRITE_DIALOGUE_BACKBOARD 1192
+#define SPRITE_PROMPT_SHADOW 1193
+#define SPRITE_CORPSE_NAIL 1194
+#define SPRITE_FK_BARREL 1195
+#define SPRITE_FK_STAFF 1196
+#define SPRITE_DIGIT0 1383
#define STYLE_DIALOGUE 0
#define STYLE_PROMPT 1
#define TEXT_K 1.333333f
@@ -354,8 +379,9 @@
#define EK_GUARD 13
#define EK_FK 14
#define EK_FKHEAD 15
-#define NUM_KINDS 16
-#define KIND_TABLE {{0}, {EF_CRAWLER, {-1, 150, 149, -1, -1, -1, -1, -1, -1, -1, -1, 152, 153}}, {EF_BUZZER, {155, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 157, 158}}, {EF_SHADE, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_CLIMBER, {-1, -1, 165, 164, -1, -1, -1, -1, -1, -1, -1, 162, 163}}, {EF_BOUNCER, {-1, -1, -1, 168, -1, -1, -1, -1, -1, -1, -1, 166, 167}}, {EF_SPITTER, {-1, -1, -1, 171, 172, 170, -1, -1, -1, -1, -1, 169, -1}}, {EF_ROLLER, {175, -1, -1, 177, 176, 178, -1, -1, -1, -1, -1, 173, 174}}, {EF_BLOCKER, {185, -1, -1, 181, 186, 179, 180, 187, 188, 184, 183, -1, 182}}, {EF_HUSK, {194, 195, 196, 189, 191, 190, -1, -1, -1, -1, -1, 192, 193}}, {EF_HUSK, {202, 203, 204, 197, 199, 198, -1, -1, -1, -1, -1, 200, 201}}, {EF_HUSK, {210, 211, 212, 205, 207, 206, -1, -1, -1, -1, -1, 208, 209}}, {EF_LEAPER, {216, 218, 219, 213, 217, -1, -1, -1, -1, -1, -1, 214, 215}}, {EF_GUARD, {225, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 222, 223}}, {EF_FK, {247, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 245}}, {EF_FKHEAD, {267, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 265}}}
+#define EK_GFLY 16
+#define NUM_KINDS 17
+#define KIND_TABLE {{0}, {EF_CRAWLER, {-1, 150, 149, -1, -1, -1, -1, -1, -1, -1, -1, 152, 153}}, {EF_BUZZER, {155, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 157, 158}}, {EF_SHADE, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_CLIMBER, {-1, -1, 165, 164, -1, -1, -1, -1, -1, -1, -1, 162, 163}}, {EF_BOUNCER, {-1, -1, -1, 168, -1, -1, -1, -1, -1, -1, -1, 166, 167}}, {EF_SPITTER, {-1, -1, -1, 171, 172, 170, -1, -1, -1, -1, -1, 169, -1}}, {EF_ROLLER, {175, -1, -1, 177, 176, 178, -1, -1, -1, -1, -1, 173, 174}}, {EF_BLOCKER, {185, -1, -1, 181, 186, 179, 180, 187, 188, 184, 183, -1, 182}}, {EF_HUSK, {194, 195, 196, 189, 191, 190, -1, -1, -1, -1, -1, 192, 193}}, {EF_HUSK, {202, 203, 204, 197, 199, 198, -1, -1, -1, -1, -1, 200, 201}}, {EF_HUSK, {210, 211, 212, 205, 207, 206, -1, -1, -1, -1, -1, 208, 209}}, {EF_LEAPER, {216, 218, 219, 213, 217, -1, -1, -1, -1, -1, -1, 214, 215}}, {EF_GUARD, {225, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 222, 223}}, {EF_FK, {247, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 245}}, {EF_FKHEAD, {267, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 265}}, {EF_GFLY, {281, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}}
#define TXT_PROMPT_LISTEN 0
#define TXT_PROMPT_REST 1
#define TXT_PROMPT_INSPECT 2
diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.c
index 30d8df75..6bc6fce4 100644
--- a/games/hollowknight/src/enemy.c
+++ b/games/hollowknight/src/enemy.c
@@ -9,14 +9,14 @@
#define DT 0.02f
#define MAX_ENEMIES 24
-#define MAX_GEO 24
+#define MAX_GEO 64
#define TERRAIN_FRICTION 0.2f /* (the Terrain material; with another, their geometric mean) */
/* ---------------------------------------------------------------- what each kind is */
/* (data.h: EK_* each kind, KIND_TABLE: the FSM each runs and the clips its roles play) */
enum {
EF_CRAWLER = 1, EF_BUZZER, EF_SHADE, EF_HUSK, EF_CLIMBER, EF_BOUNCER, EF_SPITTER, EF_ROLLER, EF_BLOCKER, EF_LEAPER, EF_GUARD,
- EF_FK, EF_FKHEAD
+ EF_FK, EF_FKHEAD, EF_GFLY
};
enum { R_IDLE, R_TURN, R_WALK, R_A1, R_A2, R_A3, R_A4, R_A5, R_A6, R_A7, R_A8, R_DEATH_AIR, R_DEATH_LAND, NUM_ROLES };
typedef struct {
@@ -28,7 +28,7 @@ static const Kind kinds[NUM_KINDS] = KIND_TABLE;
#define FSM(e) (kinds[(e)->kind].fsm)
#define NO_ENT 0xFFFF /* (an enemy spawned, not one of the room's) */
/* the records after an enemy's (tools/ents.py: ET_*) */
-enum { ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN, ET_HITBOX };
+enum { ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN, ET_HITBOX, ET_ZONE };
enum { CF_BREAKER = 1, CF_FACES_RIGHT = 2, CF_LOW_ARC = 4, CF_NO_COLLIDER = 32 }; /* a corpse's (ET_CORPSE) */
enum { WF_PAUSES = 1, WF_IGNORE_HOLES = 2, WF_NO_TURN_TO_HERO = 4, WF_START_INACTIVE = 8, WF_AMBUSH = 16, WF_WAIT_HERO_X = 32,
WF_PREVENT_TURN = 64, WF_NO_SCALE = 128, WF_RIGHT_NEG = 256 }; /* a Walker's (ET_WALKER) */
@@ -127,12 +127,16 @@ static void enemy_box(const Enemy *e, float *x0, float *y0, float *x1, float *y1
}
/* ---------------------------------------------------------------- geo (GeoControl) */
+/* (kept small, many at once: its body's place, velocity and first two contacts; a whole Body only as it steps) */
+#define GEO_CONTACTS 2
typedef struct {
- bool on, landed;
+ bool on;
uint8_t type; /* 0 small (1), 1 medium (5), 2 large (25) */
- Body body;
+ uint8_t ncontacts, ccol[GEO_CONTACTS];
+ float x, y, vx, vy;
+ float cnx[GEO_CONTACTS], cny[GEO_CONTACTS];
Anim anim;
- float pickup_t, bounce_speed;
+ float pickup_t;
} Geo;
static Geo geo[MAX_GEO];
static const struct {
@@ -158,13 +162,9 @@ void geo_fling_at(int type, int n, float x, float y, float smin, float smax, flo
if (!g) return;
memset(g, 0, sizeof *g);
g->on = true, g->type = (uint8_t)type;
- Body *b = &g->body;
- b->x = x + rand_range(-spread, spread), b->y = y + rand_range(-spread, spread);
- b->ox = geo_kinds[type].ox * GEO_SCALE, b->oy = geo_kinds[type].oy * GEO_SCALE;
- b->hx = geo_kinds[type].hx * GEO_SCALE, b->hy = geo_kinds[type].hy * GEO_SCALE;
- b->gravity_scale = geo_kinds[type].gravity, b->friction = 0.2f, b->mask = CF_TERRAIN;
+ g->x = x + rand_range(-spread, spread), g->y = y + rand_range(-spread, spread);
float s = rand_range(smin, smax), a = rand_range(amin, amax) * (float)M_PI / 180;
- b->vx = cosf(a) * s, b->vy = sinf(a) * s;
+ g->vx = cosf(a) * s, g->vy = sinf(a) * s;
anim_play(&g->anim, geo_kinds[type].air);
g->pickup_t = 0.25f;
}
@@ -188,33 +188,44 @@ static void geo_tick(void) {
for (int i = 0; i < MAX_GEO; i++) {
Geo *g = &geo[i];
if (!g->on) continue;
- float pvx = g->body.vx, pvy = g->body.vy;
- int had = g->body.ncontacts;
- body_step(&g->body, DT);
- if (g->body.ncontacts > had) {
- bounce(&g->body, pvx, pvy, had, geo_kinds[g->type].bounce);
+ Body b;
+ memset(&b, 0, sizeof b);
+ b.x = g->x, b.y = g->y, b.vx = g->vx, b.vy = g->vy;
+ b.ox = geo_kinds[g->type].ox * GEO_SCALE, b.oy = geo_kinds[g->type].oy * GEO_SCALE;
+ b.hx = geo_kinds[g->type].hx * GEO_SCALE, b.hy = geo_kinds[g->type].hy * GEO_SCALE;
+ b.gravity_scale = geo_kinds[g->type].gravity, b.friction = 0.2f, b.mask = CF_TERRAIN;
+ b.ncontacts = g->ncontacts;
+ for (int c = 0; c < g->ncontacts; c++) b.ccol[c] = g->ccol[c], b.cnx[c] = g->cnx[c], b.cny[c] = g->cny[c];
+ float pvx = b.vx, pvy = b.vy;
+ int had = b.ncontacts;
+ body_step(&b, DT);
+ bool hit = b.ncontacts > had;
+ if (hit) bounce(&b, pvx, pvy, had, geo_kinds[g->type].bounce);
+ g->x = b.x, g->y = b.y, g->vx = b.vx, g->vy = b.vy;
+ g->ncontacts = (uint8_t)(b.ncontacts < GEO_CONTACTS ? b.ncontacts : GEO_CONTACTS);
+ for (int c = 0; c < g->ncontacts; c++) g->ccol[c] = b.ccol[c], g->cnx[c] = b.cnx[c], g->cny[c] = b.cny[c];
+ if (hit) {
/* (OnCollisionEnter2D: the idle animation from a random frame) */
anim_play_from_frame(&g->anim, geo_kinds[g->type].idle, (int)rand_range(0, (float)clip_frames_count(geo_kinds[g->type].idle) - 0.001f));
}
g->anim.events = 0;
anim_update(&g->anim, DT);
if (g->pickup_t > 0) g->pickup_t -= DT;
- float x0 = g->body.x + g->body.ox - g->body.hx, x1 = g->body.x + g->body.ox + g->body.hx;
- float y0 = g->body.y + g->body.oy - g->body.hy, y1 = g->body.y + g->body.oy + g->body.hy;
+ float x0 = b.x + b.ox - b.hx, x1 = b.x + b.ox + b.hx, y0 = b.y + b.oy - b.hy, y1 = b.y + b.oy + b.hy;
if (g->pickup_t <= 0 && !h->hidden && x1 > hx - 0.2277069f && x0 < hx + 0.2277069f && y1 > hy - 0.5848932f &&
y0 < hy + 0.5848932f) {
hero_add_geo(geo_kinds[g->type].value);
g->on = false;
}
- if (g->body.y < -10) g->on = false;
+ if (g->y < -10) g->on = false;
}
}
/* ---------------------------------------------------------------- SpriteFlash */
-static uint8_t flash_tint(const Enemy *e, int slot) {
- if (!e->flashing) return 0;
+static uint8_t flash_tint_at(bool on, float t, int slot) {
+ if (!on || t > 0.27f) return 0;
/* flashInfected: up 0.01 s, stays 0.01 s, down over 0.25 s, to 0.9 of orange */
- float t = e->flash_t, k;
+ float k;
if (t < 0.01f) k = t / 0.01f;
else if (t < 0.02f) k = 1;
else k = 1 - (t - 0.02f) / 0.25f;
@@ -222,6 +233,8 @@ static uint8_t flash_tint(const Enemy *e, int slot) {
return gfx_dyn_flash(slot, 255, 255, 255, 255, 255, 79, 0, (uint8_t)(0.9f * k * 255));
}
+static uint8_t flash_tint(const Enemy *e, int slot) { return flash_tint_at(e->flashing, e->flash_t, slot); }
+
/* ---------------------------------------------------------------- Recoil */
#define RF_NONE 0x80 /* (no Recoil component) */
static void climber_stun(Enemy *e);
@@ -293,9 +306,17 @@ static void corpse_start(Enemy *e, float direction, bool has_direction) {
e->flashing = true, e->flash_t = 0; /* (EmitInfectedEffects: the corpse flashes) */
}
+/* EnemyDeathEffects.EmitEffects: the camera's shake by its enemyDeathType (Infected, LargeInfected; SmallInfected none) */
+static void death_shake(const Enemy *e) {
+ int type = e->ent != NO_ENT ? ent_at(e->ent)->s1 >> EF_DEATH_SHIFT & 15 : 0;
+ if (type == 0) cam_shake(SHAKE_ENEMY_KILL);
+ else if (type == 5) cam_shake(SHAKE_AVERAGE);
+}
+
/* HealthManager.Die, EnemyDeathEffects */
static void shade_killed(Enemy *e);
static void blocker_die(Enemy *e);
+static void gfly_die(Enemy *e);
static void enemy_die(Enemy *e, float direction, bool has_direction) {
if (FSM(e) == EF_SHADE) {
shade_killed(e);
@@ -310,9 +331,14 @@ static void enemy_die(Enemy *e, float direction, bool has_direction) {
geo_fling(0, e->geo_s, x, y, 15, 30, 80, 100);
geo_fling(1, e->geo_m, x, y, 15, 30, 80, 100);
geo_fling(2, e->geo_l, x, y, 15, 30, 80, 100);
- if (e->ent != NO_ENT) persist_set(ent_at(e->ent)->persist), enemy_terrain_off(ent_at(e->ent));
- corpse_start(e, direction, has_direction);
- cam_shake(SHAKE_ENEMY_KILL);
+ if (e->ent != NO_ENT) {
+ const Ent *d = ent_at(e->ent);
+ persist_set(d->persist), enemy_terrain_off(d);
+ if (d->s1 & EF_BATTLE) arena_enemy_died(); /* (its battleScene's Battle Enemies) */
+ }
+ if (FSM(e) == EF_GFLY) gfly_die(e);
+ else corpse_start(e, direction, has_direction);
+ death_shake(e);
FREEZE_MOMENT_1();
}
@@ -865,8 +891,9 @@ static void bouncer_fixed(Enemy *e) {
static void bouncer_update(Enemy *e) {
switch (e->st) {
case BO_WAIT: {
- float dx = e->body.x - g_cam_x, dy = e->body.y - g_cam_y;
- if (dx * dx + dy * dy < 44 * 44) {
+ /* (GetDistance to the main camera, its depth included) */
+ float dx = e->body.x - g_cam_x, dy = e->body.y - g_cam_y, dz = 0.01f - CAM_Z;
+ if (dx * dx + dy * dy + dz * dz < 44 * 44) {
const Ent *v = enemy_rec(e, ET_VARS);
if (v && (v->a & 2)) bouncer_aim(e, 90, 90); /* (Start Up) */
else bouncer_aim(e, 0, 360);
@@ -1348,7 +1375,7 @@ static void blocker_die(Enemy *e) {
geo_fling(1, e->geo_m, e->body.x, e->body.y, 15, 30, 80, 100);
geo_fling(2, e->geo_l, e->body.x, e->body.y, 15, 30, 80, 100);
if (e->ent != NO_ENT) persist_set(ent_at(e->ent)->persist), enemy_terrain_off(ent_at(e->ent));
- cam_shake(SHAKE_ENEMY_KILL);
+ death_shake(e);
FREEZE_MOMENT_1();
/* (the Snail Shaman hears of it) */
if (g_pd.shaman == 3) g_pd.shaman = 4;
@@ -2763,7 +2790,8 @@ static void fk_arena_enter(void) {
const Ent *b = &es[fk.battle];
fk.summon_x0 = 13.18f, fk.summon_x1 = 44.27f, fk.summon_y = 40.98f; /* (summon: Summon Min, Max; its y) */
if (persist_get(b->persist)) {
- /* Activate: the fight over, the floor broken, the armour there */
+ /* Activate: the fight over, the gates open, the floor broken, the armour there */
+ gates_event(BG_QUICK_OPEN);
if (b->p0 >= 0) ent_set_enabled((int)b->p0, false);
if (b->p1 >= 0) ent_set_enabled((int)b->p1, false);
fk.battle_st = BT_DONE;
@@ -2793,12 +2821,13 @@ static void fk_arena_tick(void) {
if (b->p0 >= 0) ent_set_enabled((int)b->p0, true);
if (b->p1 >= 0) ent_set_enabled((int)b->p1, false);
fk.battle_st = BT_FIGHT;
+ gates_event(BG_CLOSE);
fk_battle_start();
}
break;
}
case BT_END_WAIT:
- if ((fk.battle_t += DT) >= 2) fk.battle_st = BT_DONE;
+ if ((fk.battle_t += DT) >= 2) fk.battle_st = BT_DONE, gates_event(BG_OPEN); /* (End) */
break;
}
barrels_tick();
@@ -3188,6 +3217,411 @@ static void balls_tick(void) {
}
/* ---------------------------------------------------------------- the room's */
+/* ---------------------------------------------------------------- Gruz Mother: Big Fly Control (with her bouncer_control);
+ * her corpse (corpse) and its burster (burster), which brings out her young */
+enum { GF_INVINCIBLE, GF_SLEEP, GF_WAKE, GF_FLY, GF_BUZZ, GF_CHARGE_ANTIC, GF_CHARGE, GF_CHARGE_RECOVER, GF_SUPER_END,
+ GF_SLAM_ANTIC, GF_LAUNCH, GF_FLYING, GF_SLAM_HIT, GF_SLAM_END };
+#define GF_SCALE 1.25f
+#define GF_BUZZ_SPEED 5.0f /* (bouncer_control's Speed) */
+#define GF_SLAM_SPEED 50.0f
+/* (her FSM's variables: wait the bouncer's Angle, b1 its Facing Right; ax Charge Angle or Slamming Angle; ay Up Angle,
+ * qx Down Angle; qy Super Wait; tx Slam Time; ty Super End Time; t1 Timer; pause0, pause1 Self Vel; c0, c1 Ct Charge,
+ * Ct Slam; b0 Slamming Up; start_x, start_y where ObjectJitter jitters about; jy Slam Down's dip) */
+
+/* a box and a polygon (any shape: its outline's points) overlap? */
+static bool box_meets_poly(float x0, float y0, float x1, float y1, const float *p, int n) {
+ bool in = false;
+ float cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;
+ for (int i = 0, j = n - 1; i < n; j = i++) {
+ float ax = p[2 * j], ay = p[2 * j + 1], bx = p[2 * i], by = p[2 * i + 1];
+ if (bx >= x0 && bx <= x1 && by >= y0 && by <= y1) return true; /* (a corner in the box) */
+ if ((ay > cy) != (by > cy) && cx < ax + (bx - ax) * (cy - ay) / (by - ay)) in = !in;
+ /* (an edge through the box: clipped to it, something left) */
+ float t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay;
+ const float q[4][2] = {{-dx, ax - x0}, {dx, x1 - ax}, {-dy, ay - y0}, {dy, y1 - ay}};
+ bool cut = true;
+ for (int k = 0; k < 4 && cut; k++) {
+ if (q[k][0] == 0) {
+ if (q[k][1] < 0) cut = false;
+ continue;
+ }
+ float r = q[k][1] / q[k][0];
+ if (q[k][0] < 0) t0 = r > t0 ? r : t0;
+ else t1 = r < t1 ? r : t1;
+ if (t0 > t1) cut = false;
+ }
+ if (cut) return true;
+ }
+ return in; /* (the box's middle in it: the box inside) */
+}
+
+/* the Knight in her Battle Range (ET_ZONE: HERO ENTER, HERO EXIT) */
+static bool gfly_in_range(const Enemy *e) {
+ const Ent *z = enemy_rec(e, ET_ZONE);
+ if (!z || g_hero.hidden) return false;
+ const Body *k = &g_hero.body;
+ float x0 = k->x + k->ox - k->hx, x1 = k->x + k->ox + k->hx, y0 = k->y + k->oy - k->hy, y1 = k->y + k->oy + k->hy;
+ float s = e->sx < 0 ? -1.0f : 1.0f, a0 = e->body.x + (s > 0 ? z->x0 : -z->x1), a1 = e->body.x + (s > 0 ? z->x1 : -z->x0);
+ if (!(x1 > a0 && x0 < a1 && y1 > e->body.y + z->y0 && y0 < e->body.y + z->y1)) return false;
+ float pts[16];
+ int np = (int)z->p0 < 8 ? (int)z->p0 : 8;
+ for (int j = 0; j < np; j++) {
+ const float *f = &z[1 + j / 4].x0;
+ pts[2 * j] = e->body.x + f[2 * (j & 3)] * s, pts[2 * j + 1] = e->body.y + f[2 * (j & 3) + 1];
+ }
+ return box_meets_poly(x0, y0, x1, y1, pts, np);
+}
+
+/* FaceObject (sprite facing left) */
+static void gfly_face_hero(Enemy *e) {
+ if (hero_x() > e->body.x) set_scale_x(e, -GF_SCALE);
+ else if (hero_x() < e->body.x) set_scale_x(e, GF_SCALE);
+}
+
+static void gfly_velocity(Enemy *e, float degrees, float speed) {
+ float a = degrees * (float)M_PI / 180;
+ e->body.vx = cosf(a) * speed, e->body.vy = sinf(a) * speed;
+}
+
+/* bouncer_control's Aim and the angles it takes off what it bumps (Facing Right) */
+static void gfly_aim(Enemy *e, float lo, float hi) {
+ e->wait = rand_range(lo, hi);
+ float a = fmodf(e->wait, 360);
+ if (a < 0) a += 360;
+ e->b1 = a < 90 || a >= 270;
+}
+
+static void gfly_buzz(Enemy *e) {
+ /* Buzz: the bouncer woken (Aim), a while */
+ gfly_aim(e, 0, 360);
+ e->qy = rand_range(2, 2.8f);
+ e->st = GF_BUZZ, e->t0 = 0;
+}
+
+static void gfly_super_end(Enemy *e) {
+ anim_play(&e->anim, CLIP_GFLY_FLY);
+ e->st = GF_SUPER_END, e->t0 = 0;
+ if (e->ty <= 0) gfly_buzz(e); /* (Wait 0: done at once) */
+}
+
+static void gfly_launch(Enemy *e, bool up) {
+ /* Launch Up / Launch Down: off at its angle; Flying the next frame */
+ e->ax = up ? e->ay : e->qx;
+ gfly_velocity(e, e->ax, GF_SLAM_SPEED);
+ e->b0 = up;
+ anim_play(&e->anim, CLIP_GFLY_FLY);
+ e->st = GF_LAUNCH;
+}
+
+static void gfly_choose(Enemy *e) {
+ /* Super Choose: still, the bouncer stopped; a charge or a slam (SendRandomEventV2: three charges, two slams in a
+ * row at most) */
+ e->body.vx = e->body.vy = 0;
+ for (;;) {
+ bool charge = rand_range(0, 1) < 0.5f;
+ if (charge && e->c0 < 3) {
+ e->c0++, e->c1 = 0;
+ /* Charge Antic: back from the Knight a little, then at it */
+ anim_play_from_frame(&e->anim, CLIP_GFLY_CHARGE_ANTIC, 0);
+ gfly_face_hero(e);
+ float a = atan2f(hero_y() - e->body.y, hero_x() - e->body.x) * 180 / (float)M_PI;
+ if (a < 0) a += 360;
+ e->ax = a;
+ gfly_velocity(e, a + 180, 3);
+ e->st = GF_CHARGE_ANTIC, e->t0 = 0;
+ return;
+ }
+ if (!charge && e->c1 < 2) {
+ e->c1++, e->c0 = 0;
+ /* Slam Antic: facing the Knight, shaking */
+ anim_play_from_frame(&e->anim, CLIP_GFLY_CHARGE_ANTIC, 0);
+ gfly_face_hero(e);
+ e->qy = hero_x() - e->body.x;
+ e->t1 = 0, e->tx = rand_range(2.5f, 3);
+ e->start_x = e->body.x, e->start_y = e->body.y;
+ e->st = GF_SLAM_ANTIC, e->t0 = 0;
+ return;
+ }
+ }
+}
+
+static void gfly_start(Enemy *e) {
+ e->st = GF_INVINCIBLE, e->flags |= 4;
+ e->sx = GF_SCALE;
+ anim_play(&e->anim, CLIP(e, R_IDLE));
+}
+
+static int gfly_side(const Enemy *e) {
+ static const int order[4] = {1, 0, 3, 2}; /* (CheckCollisionSide: up, right, down, left) */
+ for (int i = 0; i < 4; i++)
+ if (side_hit(e, order[i])) return order[i];
+ return -1;
+}
+
+static void gfly_fixed(Enemy *e) {
+ switch (e->st) {
+ case GF_BUZZ:
+ gfly_velocity(e, e->wait, GF_BUZZ_SPEED); /* (Fly 2: SetVelocityAsAngle) */
+ break;
+ case GF_SLAM_ANTIC:
+ e->body.x = e->start_x + rand_range(-0.1f, 0.1f), e->body.y = e->start_y + rand_range(-0.1f, 0.1f);
+ break;
+ case GF_FLYING:
+ gfly_velocity(e, e->ax, GF_SLAM_SPEED);
+ break;
+ case GF_SLAM_END:
+ e->body.vx *= 0.85f, e->body.vy *= 0.85f; /* (DecelerateV2) */
+ break;
+ }
+ /* (Slam Down's half unit into the floor, pushed out over a few steps: Box2D's position correction) */
+ if (e->jy < 0) e->jy = e->jy * 0.8f > -0.005f ? 0 : e->jy * 0.8f;
+}
+
+static void gfly_update(Enemy *e) {
+ bool done = (e->anim.events & ANIM_DONE) != 0, hit = (e->flags & 8) != 0;
+ e->t0 += DT;
+ switch (e->st) {
+ case GF_INVINCIBLE:
+ if (gfly_in_range(e)) e->st = GF_SLEEP, e->flags &= (uint8_t)~4;
+ break;
+ case GF_SLEEP:
+ if (hit) {
+ /* Wake: the arena's fight starts */
+ cam_shake(SHAKE_AVERAGE);
+ arena_start();
+ anim_play_from_frame(&e->anim, CLIP_GFLY_WAKE, 0);
+ e->body.vy = 2.5f;
+ e->st = GF_WAKE, e->t0 = 0;
+ } else if (!gfly_in_range(e))
+ e->st = GF_INVINCIBLE, e->flags |= 4;
+ break;
+ case GF_WAKE:
+ if (done) {
+ /* Fly: still a moment; she hurts now (Hero Damager) */
+ anim_play(&e->anim, CLIP_GFLY_FLY);
+ e->body.vx = e->body.vy = 0;
+ e->hb_on |= 1;
+ e->st = GF_FLY, e->t0 = 0;
+ }
+ break;
+ case GF_FLY:
+ if (e->t0 >= 1) gfly_buzz(e);
+ break;
+ case GF_BUZZ: {
+ /* (the bouncer: FaceDirection, sprite facing left; off what it bumps) */
+ if (e->body.vx != 0) set_scale_x(e, e->body.vx > 0 ? -GF_SCALE : GF_SCALE);
+ if (e->body.ncontacts) {
+ float a = fmodf(e->wait, 360);
+ if (a < 0) a += 360;
+ switch (gfly_side(e)) {
+ case 1: if (e->b1) gfly_aim(e, 320, 350); else gfly_aim(e, 190, 220); break;
+ case 3: if (e->b1) gfly_aim(e, 10, 40); else gfly_aim(e, 140, 170); break;
+ case 0: if (a < 180) gfly_aim(e, 140, 170); else gfly_aim(e, 190, 220); break;
+ case 2: if (a < 180) gfly_aim(e, 10, 40); else gfly_aim(e, 320, 350); break;
+ }
+ }
+ if (e->t0 >= e->qy) gfly_choose(e);
+ break;
+ }
+ case GF_CHARGE_ANTIC:
+ if (e->t0 >= 0.75f) {
+ anim_play(&e->anim, CLIP_GFLY_CHARGE);
+ gfly_velocity(e, e->ax, 26);
+ e->pause0 = e->body.vx, e->pause1 = e->body.vy;
+ e->st = GF_CHARGE, e->t0 = 0;
+ }
+ break;
+ case GF_CHARGE: {
+ int side = e->body.ncontacts ? gfly_side(e) : -1;
+ if (side < 0) break;
+ /* Charge Recover: off the wall, half as fast */
+ cam_shake(SHAKE_AVERAGE);
+ anim_play_from_frame(&e->anim, CLIP_GFLY_CHARGE_RECOVER, 0);
+ if (side == 0 || side == 2) e->body.vx = -e->pause0 / 2, e->body.vy = e->pause1 / 2;
+ else e->body.vx = e->pause0 / 2, e->body.vy = -e->pause1 / 2;
+ e->st = GF_CHARGE_RECOVER, e->t0 = 0;
+ break;
+ }
+ case GF_CHARGE_RECOVER:
+ if (e->t0 >= 0.3f) {
+ e->body.vx = e->body.vy = 0; /* (Recover End) */
+ e->ty = 0.5f;
+ gfly_super_end(e);
+ }
+ break;
+ case GF_SUPER_END:
+ if (e->t0 >= e->ty) gfly_buzz(e);
+ break;
+ case GF_SLAM_ANTIC:
+ if (e->t0 >= 0.5f) {
+ /* Check Direction: up and down angles towards the Knight */
+ if (e->qy <= 0) e->ay = 100, e->qx = 260;
+ else e->ay = 80, e->qx = 280;
+ gfly_launch(e, true);
+ }
+ break;
+ case GF_LAUNCH:
+ e->st = GF_FLYING;
+ break;
+ case GF_FLYING: {
+ e->t1 += DT;
+ int side = e->body.ncontacts ? gfly_side(e) : -1;
+ if (side == 1 || side == 3) {
+ /* Slam Up / Slam Down: stopped against it a moment */
+ e->body.vx = e->body.vy = 0;
+ anim_play_from_frame(&e->anim, side == 3 ? CLIP_GFLY_SLAM_DOWN : CLIP_GFLY_SLAM_UP, 0);
+ if (side == 3) e->jy = -0.5f;
+ cam_shake(SHAKE_AVERAGE);
+ e->b0 = side == 3; /* (then up after a slam down, down after a slam up) */
+ e->st = GF_SLAM_HIT;
+ } else if (side == 0 || side == 2) {
+ /* Turn Left / Turn Right, then on the same way up or down */
+ set_scale_x(e, side == 0 ? GF_SCALE : -GF_SCALE);
+ if (side == 0) e->ay = 100, e->qx = 260;
+ else e->ay = 80, e->qx = 280;
+ gfly_launch(e, e->b0);
+ } else if (e->t1 > e->tx) {
+ /* Slam End */
+ anim_play_from_frame(&e->anim, CLIP_GFLY_SLAM_END, 0);
+ e->ty = 0;
+ e->st = GF_SLAM_END, e->t0 = 0;
+ }
+ break;
+ }
+ case GF_SLAM_HIT:
+ if (done) gfly_launch(e, e->b0);
+ break;
+ case GF_SLAM_END:
+ if (e->t0 >= 0.75f) gfly_super_end(e);
+ break;
+ }
+}
+
+/* her corpse: Init, Steam, Ready, Blow; its burster: Initiate, Geo, In Air, Landed, Stop Emit, Stop, Gurgles, Burst,
+ * Spawn */
+enum { GC_NONE, GC_INIT, GC_STEAM, GC_READY };
+enum { GB_NONE, GB_INITIATE, GB_IN_AIR, GB_LANDED, GB_STOP_EMIT, GB_STOP, GB_GURG1, GB_GURG2, GB_GURG3, GB_BURST, GB_DONE };
+static struct {
+ uint8_t corpse, burster;
+ float ct, bt, flash_t;
+ float x, y, sx; /* (the corpse) */
+ float spawn_x, spawn_y; /* (Fly Spawn's place) */
+ Anim canim, banim;
+ Body body; /* (the burster) */
+} gm;
+
+static void gfly_die(Enemy *e) {
+ memset(&gm, 0, sizeof gm);
+ const Ent *v = enemy_rec(e, ET_VARS);
+ gm.spawn_x = v ? v->p0 : e->body.x, gm.spawn_y = v ? v->p1 : e->body.y;
+ /* (the corpse where she was, her way; no body: it stays there) */
+ gm.x = e->body.x, gm.y = e->body.y, gm.sx = e->sx;
+ anim_play(&gm.canim, CLIP_GFLY_FLY); /* (its default clip, till Steam) */
+ gm.corpse = GC_INIT, gm.ct = 0;
+ arena_set_activated();
+ e->mode = EM_OFF;
+}
+
+static void gfly_corpse_tick(void) {
+ if (gm.corpse) {
+ gm.canim.events = 0;
+ anim_update(&gm.canim, DT);
+ gm.ct += DT, gm.flash_t += DT;
+ if (gm.corpse == GC_INIT && gm.ct >= 0.5f) {
+ anim_play_from_frame(&gm.canim, CLIP_GFLY_DEATH, 0);
+ cam_shake(SHAKE_BIG);
+ cam_rumble(RUMBLE_MED);
+ gm.corpse = GC_STEAM, gm.ct = 0;
+ } else if (gm.corpse == GC_STEAM && gm.ct >= 3)
+ gm.corpse = GC_READY, gm.ct = 0;
+ else if (gm.corpse == GC_READY && gm.ct >= 1) {
+ /* Blow: the burster out, up and its way */
+ Body *b = &gm.body;
+ memset(b, 0, sizeof *b);
+ float k = fabsf(gm.sx);
+ b->x = gm.x, b->y = gm.y;
+ b->ox = 0.0469f * gm.sx, b->oy = -0.6484f * GF_SCALE, b->hx = 2.4375f / 2 * k, b->hy = 1.7031f / 2 * GF_SCALE;
+ b->vx = gm.sx * 10, b->vy = 20;
+ b->gravity_scale = 1, b->friction = 0.2f, b->mask = CF_TERRAIN;
+ anim_play(&gm.banim, CLIP_GFLY_FALL);
+ gm.burster = GB_INITIATE, gm.bt = 0;
+ cam_rumble(RUMBLE_OFF);
+ gm.corpse = GC_NONE;
+ }
+ }
+ if (gm.burster) {
+ Body *b = &gm.body;
+ float pvx = b->vx, pvy = b->vy;
+ int had = b->ncontacts;
+ body_step(b, DT);
+ bounce(b, pvx, pvy, had, 0.5f); /* (ObjectBounce) */
+ gm.banim.events = 0;
+ anim_update(&gm.banim, DT);
+ gm.bt += DT;
+ switch (gm.burster) {
+ case GB_INITIATE:
+ if (gm.bt >= 0.1f) {
+ geo_fling_at(0, 50, b->x, b->y, 15, 30, 80, 100, 0.75f); /* (Geo) */
+ gm.burster = GB_IN_AIR;
+ }
+ break;
+ case GB_IN_AIR: {
+ bool ground = false;
+ for (int c = 0; c < b->ncontacts; c++) ground |= b->cny[c] > 0.5f;
+ if (ground) anim_play_from_frame(&gm.banim, CLIP_GFLY_WIGGLE, 0), gm.burster = GB_LANDED, gm.bt = 0;
+ break;
+ }
+ case GB_LANDED:
+ if (gm.bt >= 1) gm.burster = GB_STOP_EMIT, gm.bt = 0;
+ break;
+ case GB_STOP_EMIT:
+ if (gm.bt >= 0.5f) anim_play_from_frame(&gm.banim, CLIP_GFLY_STOP, 0), gm.burster = GB_STOP, gm.bt = 0;
+ break;
+ case GB_STOP:
+ case GB_GURG1:
+ if (gm.bt >= 2) anim_play_from_frame(&gm.banim, CLIP_GFLY_GURGLE_ONCE, 0), gm.burster++, gm.bt = 0;
+ break;
+ case GB_GURG2:
+ if (gm.bt >= 2) {
+ cam_rumble(RUMBLE_SMALL);
+ anim_play_from_frame(&gm.banim, CLIP_GFLY_GURGLE_LOOP, 0);
+ gm.burster = GB_GURG3, gm.bt = 0;
+ }
+ break;
+ case GB_GURG3:
+ if (gm.bt >= 1.9f) anim_play_from_frame(&gm.banim, CLIP_GFLY_BURST, 0), gm.burster = GB_BURST, gm.bt = 0;
+ break;
+ case GB_BURST:
+ if (gm.bt >= 0.16f) {
+ /* Spawn: her young where it is (Fly Spawn moved there) */
+ cam_rumble(RUMBLE_OFF);
+ cam_shake(SHAKE_AVERAGE);
+ for (int i = 0; i < MAX_ENEMIES; i++) {
+ Enemy *f = &en[i];
+ if (f->mode != EM_ALIVE || f->ent == NO_ENT || !(ent_at(f->ent)->s1 & EF_SPAWNED)) continue;
+ const Ent *d = ent_at(f->ent);
+ f->body.x = b->x + d->x0 - gm.spawn_x, f->body.y = b->y + d->y0 - gm.spawn_y;
+ }
+ gm.burster = GB_DONE;
+ }
+ break;
+ }
+ }
+}
+
+static void gfly_corpse_draw(void) {
+ Inst in;
+ if (gm.corpse) {
+ /* (EmitLargeInfectedEffects: the corpse flashes) */
+ sprite_inst(gm.canim.sprite, gm.x, gm.y, 0.0085f, gm.sx, GF_SCALE, flash_tint_at(true, gm.flash_t, 10), &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ }
+ if (gm.burster) {
+ sprite_inst(gm.banim.sprite, gm.body.x, gm.body.y, 0.0085f, gm.sx, GF_SCALE, 0, &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ }
+}
+
void enemies_enter(void) {
memset(en, 0, sizeof en);
memset(geo, 0, sizeof geo);
@@ -3197,7 +3631,7 @@ void enemies_enter(void) {
for (int i = 0; i < n && k < MAX_ENEMIES; i++) {
const Ent *d = &es[i];
if (d->type != ENT_OBJ || d->flags != OK_ENEMY) continue;
- if (persist_get(d->persist)) {
+ if (persist_get(d->persist) || ((d->s1 & EF_ARENA_GONE) && arena_done())) {
enemy_terrain_off(d);
continue;
}
@@ -3232,6 +3666,7 @@ void enemies_enter(void) {
else if (FSM(e) == EF_GUARD) guard_start(e);
else if (FSM(e) == EF_FK) fk_start(e);
else if (FSM(e) == EF_FKHEAD) fk_head_start(e);
+ else if (FSM(e) == EF_GFLY) gfly_start(e);
for (int h = 0; h < 8; h++) {
const Ent *r = hitbox_rec(e, h);
if (!r) break;
@@ -3250,6 +3685,7 @@ void enemies_enter(void) {
memset(bullets, 0, sizeof bullets);
memset(waves, 0, sizeof waves);
memset(spurts, 0, sizeof spurts);
+ memset(&gm, 0, sizeof gm);
shade_spawn_check();
}
@@ -3286,6 +3722,7 @@ void enemies_fixed(void) {
else if (FSM(e) == EF_ROLLER) roller_fixed(e);
else if (FSM(e) == EF_LEAPER) leaper_fixed(e);
else if (FSM(e) == EF_GUARD) guard_fixed(e);
+ else if (FSM(e) == EF_GFLY) gfly_fixed(e);
recoil_fixed(e);
body_step(&e->body, DT);
} else if (FSM(e) != EF_BLOCKER) {
@@ -3321,6 +3758,7 @@ void enemies_fixed(void) {
waves_tick();
fk_arena_tick();
fk_head_place();
+ gfly_corpse_tick();
}
/* Update: the FSMs' every-frame actions, the animations, the timers */
@@ -3346,6 +3784,7 @@ void enemies_update(void) {
else if (FSM(e) == EF_LEAPER) leaper_update(e);
else if (FSM(e) == EF_GUARD) guard_update(e);
else if (FSM(e) == EF_FK) fk_update(e);
+ else if (FSM(e) == EF_GFLY) gfly_update(e);
if (FSM(e) == EF_FK) {
/* (its Hitter: on till its FSM turns it off) */
e->sub.events = 0;
@@ -3388,6 +3827,7 @@ void enemies_draw(void) {
bullets_draw();
spurts_draw();
fk_arena_draw();
+ gfly_corpse_draw();
for (int i = 0; i < MAX_BALLS; i++) {
const Ball *b = &balls[i];
if (!b->on) continue;
@@ -3399,7 +3839,7 @@ void enemies_draw(void) {
const Geo *g = &geo[i];
if (!g->on) continue;
Inst in;
- sprite_inst(g->anim.sprite, g->body.x, g->body.y, 0.0015f, GEO_SCALE, GEO_SCALE, 0, &in);
+ sprite_inst(g->anim.sprite, g->x, g->y, 0.0015f, GEO_SCALE, GEO_SCALE, 0, &in);
gfx_actor(&in, SORT_KEY(0, 0));
}
}
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index 517b7cef..e99c549c 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -52,8 +52,20 @@ void save_set_respawn(const char *marker, bool facing_right); /* (Bench Contro
/* ---------------------------------------------------------------- the room's game objects (tools/ents.py) */
enum { ENT_CAMLOCK = 1, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_MASK, ENT_DAMAGE, ENT_SHAPE,
ENT_BOX, ENT_OBJ, ENT_PIECE, ENT_SHADE_MARKER }; /* (shape, box, piece: more of the record before) */
-enum { OK_BREAKABLE = 1, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH, OK_BATTLE, OK_FK_FLOOR }; /* objects (ENT_OBJ's flags) */
-#define EF_PREBATTLE 4 /* (an enemy record's s1: one of an arena's Pre Battle Enemies) */
+enum { OK_BREAKABLE = 1, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH, OK_BATTLE, OK_FK_FLOOR, OK_BGATE,
+ OK_ARENA, OK_EVENT }; /* objects (ENT_OBJ's flags) */
+/* an enemy record's s1: one of an arena's Pre Battle Enemies; its death counts for its arena; gone once its arena's
+ * fight is over; spawned by its mother's burster; then its death's effects (EF_DEATH_SHIFT: enemyDeathType, and
+ * 12-13: which EnemyDeathEffects) */
+enum { EF_PREBATTLE = 4, EF_BATTLE = 8, EF_ARENA_GONE = 16, EF_SPAWNED = 32 };
+#define EF_DEATH_SHIFT 8
+/* battle gates (BG Control: their events) and arenas (Battle Control: obj.c) */
+enum { BG_CLOSE, BG_QUICK_CLOSE, BG_OPEN, BG_QUICK_OPEN, BG_DESTROY };
+void gates_event(int ev);
+void arena_start(void); /* START (sent by an enemy) */
+void arena_enemy_died(void); /* (one it counts) */
+void arena_set_activated(void); /* Activated: its fight over (and saved) */
+bool arena_done(void);
enum { HB_BOUNCE = 1, HB_RECOIL = 2 }; /* a hit box (ENT_BOX's flags): a down slash bounces off it, a slash recoils */
enum { HAZ_NONE, HAZ_NORMAL, HAZ_SPIKES, HAZ_ACID, HAZ_LAVA, HAZ_PIT }; /* DamageHero.hazardType */
enum { MK_SECRET = 1, MK_REMASK = 2, MK_SIMPLE = 4 }; /* masks: the unmasker, remasker and inverse FSMs */
diff --git a/games/hollowknight/src/obj.c b/games/hollowknight/src/obj.c
index e7d6dec8..a49f5c8d 100644
--- a/games/hollowknight/src/obj.c
+++ b/games/hollowknight/src/obj.c
@@ -2,6 +2,10 @@
* breakables and the debris they fling. */
#include <math.h>
#include "game.h"
+#ifdef HOST
+#include <stdio.h>
+#include <stdlib.h>
+#endif
#define DT 0.02f
#define MAX_OBJS 64
@@ -303,19 +307,175 @@ static void chest_draw(const Obj *o, const Ent *e) {
}
}
+/* ---------------------------------------------------------------- battle gates (BG Control; or Control: closed till a
+ * PlayerData bool is set) */
+enum { BGF_START_CLOSED = 1, BGF_BONE = 2, BGF_PD = 4 };
+enum { GT_OPENED, GT_CLOSE1, GT_CLOSE2, GT_OPEN, GT_QUICK_CLOSE, GT_DOUBLE_CLOSE, GT_GONE };
+enum { GC_OPENED, GC_CLOSE1, GC_CLOSE2, GC_OPEN, GC_CLOSED };
+
+static int gate_clip(const Ent *e, int which) {
+ static const int16_t clips[2][5] = {
+ {CLIP_BGATE_BG_OPENED, CLIP_BGATE_BG_CLOSE_1, CLIP_BGATE_BG_CLOSE_2, CLIP_BGATE_BG_OPEN, CLIP_BGATE_BG_CLOSED},
+ {CLIP_BGATE_BONE_GATE_OPENED, CLIP_BGATE_BONE_GATE_CLOSE, CLIP_BGATE_BONE_GATE_CLOSED, CLIP_BGATE_BONE_GATE_OPEN,
+ CLIP_BGATE_BONE_GATE_CLOSED}};
+ return clips[(e->s0 & BGF_BONE) != 0][which];
+}
+
+static void gate_collider(const Ent *e, bool on) {
+ for (int c = e->a; c < e->a + e->group; c++) phys_collider_enable(c, on);
+}
+
+static void gate_set(Obj *o, const Ent *e, int state, int clip, bool solid) {
+ anim_play_from_frame(&o->anim, gate_clip(e, clip), 0);
+ gate_collider(e, solid);
+ o->state = (uint8_t)state;
+}
+
+static void gate_gone(Obj *o, const Ent *e) {
+ gate_collider(e, false);
+ o->state = GT_GONE;
+}
+
+static void gate_enter(Obj *o, const Ent *e) {
+ if (e->s0 & BGF_PD) {
+ gate_set(o, e, GT_DOUBLE_CLOSE, GC_CLOSED, true);
+ if (pd_flag((int)e->p1)) gate_gone(o, e); /* (Check) */
+ } else if (e->s0 & BGF_START_CLOSED) {
+ gate_set(o, e, GT_QUICK_CLOSE, GC_CLOSED, true), o->t = 0.2f;
+ } else
+ gate_set(o, e, GT_OPENED, GC_OPENED, false);
+}
+
+static void gate_event(Obj *o, const Ent *e, int ev) {
+ if (o->state == GT_GONE) return;
+ if (e->s0 & BGF_PD) {
+ if (ev == BG_OPEN || ev == BG_QUICK_OPEN) gate_gone(o, e);
+ return;
+ }
+ if (ev == BG_DESTROY) gate_gone(o, e);
+ else if (ev == BG_QUICK_OPEN) gate_set(o, e, GT_OPENED, GC_OPENED, false); /* (Quick Open: as Opened) */
+ else if (o->state == GT_OPENED || o->state == GT_OPEN) {
+ if (ev == BG_CLOSE) gate_set(o, e, GT_CLOSE1, GC_CLOSE1, true);
+ else if (ev == BG_QUICK_CLOSE) gate_set(o, e, GT_QUICK_CLOSE, GC_CLOSED, true), o->t = 0.2f;
+ } else if (ev == BG_OPEN && (o->state == GT_CLOSE2 || o->state == GT_QUICK_CLOSE || o->state == GT_DOUBLE_CLOSE))
+ gate_set(o, e, GT_OPEN, GC_OPEN, false);
+}
+
+static void gate_tick(Obj *o, const Ent *e) {
+ if (o->state == GT_CLOSE1 && (o->anim.events & ANIM_DONE)) {
+ /* Close 2: slammed shut */
+ anim_play_from_frame(&o->anim, gate_clip(e, GC_CLOSE2), 0);
+ cam_shake(SHAKE_ENEMY_KILL);
+ o->state = GT_CLOSE2;
+ } else if (o->state == GT_QUICK_CLOSE && (o->t -= DT) <= 0) {
+ anim_play_from_frame(&o->anim, gate_clip(e, GC_CLOSED), 0); /* (Double Close) */
+ o->state = GT_DOUBLE_CLOSE;
+ }
+}
+
+void gates_event(int ev) {
+#ifdef HOST
+ if (getenv("HKOBJ")) fprintf(stderr, "gates event %d\n", ev);
+#endif
+ for (int k = 0; k < nobjs; k++)
+ if (objs[k].kind == OK_BGATE) gate_event(&objs[k], ent_at(objs[k].ent), ev);
+}
+
+/* ---------------------------------------------------------------- arenas (Battle Control; the False Knight's is enemy.c's) */
+enum { ARF_TRIGGER = 1, ARF_DESTROY_GATES = 2, ARF_QUICK_OPEN = 4 };
+enum { AR_DETECT, AR_FIGHT, AR_END_WAIT, AR_DONE };
+static struct {
+ int16_t ent; /* (-1: none) */
+ uint8_t st;
+ int16_t count; /* Battle Enemies */
+ float t;
+} arena;
+
+static const Ent *arena_rec(void) {
+ int n;
+ const Ent *es = room_ents(&n);
+ for (int i = 0; i < n; i++)
+ if (es[i].type == ENT_OBJ && es[i].flags == OK_ARENA) return &es[i];
+ return NULL;
+}
+
+bool arena_done(void) {
+ const Ent *e = arena_rec();
+ return e && persist_get(e->persist);
+}
+
+static void arena_enter(void) {
+ const Ent *e = arena_rec();
+ int n;
+ arena.ent = e ? (int16_t)(e - room_ents(&n)) : -1;
+ if (!e) return;
+ arena.count = (int16_t)e->p2;
+ /* Init: its camera lock off; Activate if its fight is over */
+ if (e->p0 >= 0) ent_set_enabled((int)e->p0, false);
+ if (persist_get(e->persist)) {
+ arena.st = AR_DONE;
+ if (e->a & ARF_DESTROY_GATES) gates_event(BG_DESTROY);
+ else if (e->a & ARF_QUICK_OPEN) gates_event(BG_QUICK_OPEN);
+ } else
+ arena.st = AR_DETECT;
+}
+
+void arena_start(void) {
+ if (arena.ent < 0 || arena.st != AR_DETECT) return;
+ const Ent *e = ent_at(arena.ent);
+ /* Start: BATTLE START, the gates shut, its camera lock on */
+ arena.count = (int16_t)e->p2;
+ gates_event(BG_CLOSE);
+ if (e->p0 >= 0) ent_set_enabled((int)e->p0, true);
+ arena.st = AR_FIGHT;
+}
+
+void arena_enemy_died(void) {
+ if (arena.ent >= 0) arena.count--;
+}
+
+void arena_set_activated(void) {
+ if (arena.ent >= 0) persist_set(ent_at(arena.ent)->persist);
+}
+
+static void arena_tick(void) {
+ if (arena.ent < 0) return;
+ const Ent *e = ent_at(arena.ent);
+ switch (arena.st) {
+ case AR_DETECT:
+ if (e->a & ARF_TRIGGER) {
+ const Body *k = &g_hero.body;
+ float x0 = k->x + k->ox - k->hx, x1 = k->x + k->ox + k->hx, y0 = k->y + k->oy - k->hy, y1 = k->y + k->oy + k->hy;
+ if (!g_hero.hidden && x1 > e->x0 && x0 < e->x1 && y1 > e->y0 && y0 < e->y1) arena_start();
+ }
+ break;
+ case AR_FIGHT:
+ if (arena.count <= 0) arena.st = AR_END_WAIT, arena.t = 0;
+ break;
+ case AR_END_WAIT:
+ if ((arena.t += DT) >= e->p3) {
+ /* End: Activated, the gates open, its camera lock off */
+ persist_set(e->persist);
+ gates_event(BG_OPEN);
+ if (e->p0 >= 0) ent_set_enabled((int)e->p0, false);
+ arena.st = AR_DONE;
+ }
+ break;
+ }
+}
+
/* ---------------------------------------------------------------- the room */
void obj_enter(void) {
nobjs = 0;
phys_colliders_reset();
- enemies_enter();
- benches_enter();
memset(pieces, 0, sizeof pieces);
memset(swing_hit, 0, sizeof swing_hit);
int n;
const Ent *es = room_ents(&n);
for (int i = 0; i < n && nobjs < MAX_OBJS; i++) {
if (es[i].type != ENT_OBJ) continue;
- if (es[i].flags == OK_ENEMY || es[i].flags == OK_BENCH) continue; /* (enemy.c's, npc.c's) */
+ if (es[i].flags == OK_ENEMY || es[i].flags == OK_BENCH || es[i].flags == OK_ARENA || es[i].flags == OK_EVENT)
+ continue; /* (enemy.c's, npc.c's; below) */
Obj *o = &objs[nobjs++];
memset(o, 0, sizeof *o);
o->kind = es[i].flags, o->ent = (uint16_t)i;
@@ -323,7 +483,21 @@ void obj_enter(void) {
else if (o->kind == OK_GREAT_DOOR) great_door_enter(o, &es[i]);
else if (o->kind == OK_GEO_ROCK) georock_enter(o, &es[i]);
else if (o->kind == OK_CHEST) chest_enter(o, &es[i]);
+ else if (o->kind == OK_BGATE) gate_enter(o, &es[i]);
}
+ /* (then what sends the gates their events: SendPlaymakerEventOnEnable, the arenas) */
+ for (int i = 0; i < n; i++)
+ if (es[i].type == ENT_OBJ && es[i].flags == OK_EVENT) gates_event(es[i].a);
+ enemies_enter();
+ benches_enter();
+ arena_enter();
+#ifdef HOST
+ if (getenv("HKOBJ"))
+ for (int k = 0; k < nobjs; k++) {
+ const Ent *e = ent_at(objs[k].ent);
+ fprintf(stderr, "obj %d kind %d state %d at %.2f,%.2f sprite %d\n", k, objs[k].kind, objs[k].state, e->x0, e->y0, objs[k].anim.sprite);
+ }
+#endif
}
void obj_tick(void) {
@@ -335,7 +509,9 @@ void obj_tick(void) {
if (o->kind == OK_GREAT_DOOR) great_door_tick(o, e);
else if (o->kind == OK_GEO_ROCK) georock_tick(o, e);
else if (o->kind == OK_CHEST) chest_tick(o, e);
+ else if (o->kind == OK_BGATE) gate_tick(o, e);
}
+ arena_tick();
pieces_tick();
enemies_update();
}
@@ -353,6 +529,10 @@ void obj_draw(void) {
gfx_actor(&in, SORT_KEY(0, 0));
} else if (o->kind == OK_CHEST)
chest_draw(o, e);
+ else if (o->kind == OK_BGATE && o->state != GT_GONE) {
+ sprite_inst(o->anim.sprite, e->x0, e->y0, e->x1, e->y1, e->p0, 0, &in);
+ gfx_actor(&in, SORT_KEY(0, 0));
+ }
}
pieces_draw();
enemies_draw();
diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.py
index 90fb0821..65b6caf5 100644
--- a/games/hollowknight/tools/actors.py
+++ b/games/hollowknight/tools/actors.py
@@ -52,6 +52,10 @@ ENEMY_KINDS = [
"Stun Open", "Stun Hit", "Stun Recover", "Rage", "Death Fall", "Death Land", "Death Head 1", "Death Head 2",
"Death Spaz", "Body", "Stun Opened"]),
("fkhead", "Health Check", ("sharedassets47.assets", 9), "FKHEAD", {"IDLE": "Head Idle"}, ["Head Hit", "Head Spaz"]),
+ # (Gruz Mother; her corpse's and its burster's clips are hers too)
+ ("gfly", "Big Fly Control", ("sharedassets32.assets", 765), "GFLY", {"IDLE": "Sleep"},
+ ["Wake", "Fly", "Charge Antic", "Charge", "Charge Recover", "Slam Down", "Slam Up", "Slam End", "Death", "Fall",
+ "Wiggle", "Stop", "Gurgle Once", "Gurgle Loop", "Burst"]),
]
ENEMY_CORPSE_LIBS = {} # (name -> its corpse's library, if not its own)
@@ -105,6 +109,9 @@ ACTORS = {"knight": KNIGHT,
"Retreat Start", "Retreat End", "Death Start", "Death", "Depart",
"Appear", "Fireball", "Fireball End", "Cast Ring"])}
ACTORS.update(_enemy_actors())
+# battle gates (BG Control: the plain ones and the bone ones)
+ACTORS["bgate"] = ("sharedassets9.assets", 197, ["BG Opened", "BG Close 1", "BG Close 2", "BG Open", "BG Closed",
+ "Bone Gate Opened", "Bone Gate Close", "Bone Gate Closed", "Bone Gate Open"])
# enemies' shots (EnemyBullet)
ACTORS["bullet"] = ("sharedassets32.assets", 745, ["Idle", "Impact", "Shockwave Spurt"])
diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.py
index 69c2a0e7..f146cfce 100644
--- a/games/hollowknight/tools/ents.py
+++ b/games/hollowknight/tools/ents.py
@@ -8,7 +8,15 @@ import numpy as np
ENT_CAMLOCK, ENT_GATE, ENT_HAZARD_MARKER, ENT_RESPAWN, ENT_HAZARD_TRIGGER, ENT_MASK, ENT_DAMAGE, ENT_SHAPE, ENT_BOX, \
ENT_OBJ, ENT_PIECE, ENT_SHADE_MARKER = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
# objects (ENT_OBJ's flags: src/obj.c)
-OK_BREAKABLE, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH, OK_BATTLE, OK_FK_FLOOR = 1, 2, 3, 4, 5, 6, 7, 8
+OK_BREAKABLE, OK_ENEMY, OK_GREAT_DOOR, OK_GEO_ROCK, OK_CHEST, OK_BENCH, OK_BATTLE, OK_FK_FLOOR, OK_BGATE, OK_ARENA, \
+ OK_EVENT = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+# the battle gates' events (src/game.h: BG_*)
+BG_EVENTS = ["BG CLOSE", "BG QUICK CLOSE", "BG OPEN", "BG QUICK OPEN", "BG DESTROY"]
+# battle gates (BG Control: OK_BGATE's s0): closed at first, the bone ones' clips, gone once a PlayerData bool is set
+BGF_START_CLOSED, BGF_BONE, BGF_PD = 1, 2, 4
+# arenas (Battle Control, but the False Knight's: OK_ARENA's a): started by its trigger (else by an enemy), its
+# Activate destroys the gates (else opens them at once)
+ARF_TRIGGER, ARF_DESTROY_GATES, ARF_QUICK_OPEN = 1, 2, 4
# enemies (an OK_ENEMY's a: src/enemy.c), by their FSM and animation library
import actors as _actors
# enemies: by the FSM (or component) that runs them and their animation library -> their kind (actors.ENEMY_KINDS)
@@ -21,9 +29,12 @@ ENEMY_VARS = {"Zombie Swipe": (["Lunge Speed", "Idle Time"], ["Coward"]),
"Zombie Leap": (["Idle Time"], []),
"Zombie Guard": (["Chase Distance", "Roam Distance"], ["Start Facing Left"])}
# what follows an enemy's record: ENT_BOX records, tagged
-ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN, ET_HITBOX = 0, 1, 2, 3, 4, 5, 6, 7, 8
-EF_START, EF_STARTLES, EF_PREBATTLE = 1, 2, 4 # (FSM bools: First Crawler or Start Alert; Startles; one of an arena's
-# Pre Battle Enemies)
+ET_COLLIDER, ET_ALERT, ET_RANGE, ET_WALKER, ET_RECOIL, ET_CORPSE, ET_VARS, ET_TERRAIN, ET_HITBOX, ET_ZONE = \
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+# (FSM bools: First Crawler or Start Alert; Startles; one of an arena's Pre Battle Enemies; its death counts for its
+# arena (HealthManager.battleScene); gone once its arena's fight is over; spawned by its mother's burster (Fly Spawn))
+EF_START, EF_STARTLES, EF_PREBATTLE, EF_BATTLE, EF_ARENA_GONE, EF_SPAWNED = 1, 2, 4, 8, 16, 32
+EF_DEATH_SHIFT = 8 # (bits 8-11: its enemyDeathType; 12-13: EnemyDeathEffects (0), Uninfected, NoEffect, BlackKnight)
# the layers the nail's slashes touch (Physics2D's collision matrix, layer 17 Attack)
ATTACK_HITS = {3, 6, 7, 8, 11, 12, 17, 19, 20, 21, 25, 31}
MAX_GROUPS = 256
@@ -192,6 +203,20 @@ def rec(type_, flags=0, box=(0, 0, 0, 0), p=(0, 0, 0, 0), a=0, group=0, group2=0
return struct.pack(REC, type_, flags, group, group2, a, persist, *box, *p, s0, s1)
+def pd_flags():
+ """PlayerData's bools as the game numbers them (src/game.h: PDF_*), by their names in the game ("falseKnightDefeated")"""
+ import os, re
+ src = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "game.h")).read()
+ names = re.search(r"enum \{\s*(PDF_AT_BENCH[^}]*)\}", src).group(1)
+ ids = [n.strip() for n in names.replace("\n", " ").split(",") if n.strip() and n.strip() != "PDF_COUNT"]
+ camel = lambda n: "".join(w.capitalize() for w in n[4:].lower().split("_"))
+ out = {}
+ for i, n in enumerate(ids):
+ c = camel(n)
+ out[c[0].lower() + c[1:]] = i
+ return out
+
+
def _fsm(o, names):
for c in o["c"]:
f = c.get("fsm")
@@ -349,6 +374,13 @@ def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):
fl |= EF_START
if (var.get("Startles") or [0, False])[1]:
fl |= EF_STARTLES
+ if hm.get("battleScene"):
+ fl |= EF_BATTLE
+ # (its death's effects: EnemyDeathEffects' enemyDeathType, and which of its kinds runs them)
+ dcls = next((c.get("class") for c in o["c"] if (c.get("class") or "").startswith("EnemyDeathEffects")), None)
+ dv = next((c.get("v") for c in o["c"] if c.get("class") == dcls and c.get("v")), None) or {}
+ fl |= (dv.get("enemyDeathType", 0) & 15) << EF_DEATH_SHIFT
+ fl |= {"EnemyDeathEffectsUninfected": 1, "EnemyDeathEffectsNoEffect": 2, "EnemyDeathEffectsBlackKnight": 3}.get(dcls, 0) << 12
rb = next((c["v"] for c in o["c"] if c["type"] == "Rigidbody2D" and c.get("v")), {})
out = [rec(ENT_BOX, ET_COLLIDER, box=(box["m_Offset"]["x"] * abs(sx), box["m_Offset"]["y"] * abs(sy),
box["m_Size"]["x"] / 2 * abs(sx), box["m_Size"]["y"] / 2 * abs(sy)),
@@ -369,18 +401,21 @@ def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):
out.append(rec(ENT_BOX, ET_RANGE, box=r, p=k, s0=strings.id(q["name"]) if strings else 0))
# its attacks: children that hurt the Knight (DamageHero), their outlines in its own units (x as if facing its
# scale's way), then their shapes' points; a: on at first; s0: the child's name
+ # (and the same for a range the Knight is in or not (Battle Range: HERO ENTER, HERO EXIT), no damage)
sgn = -1.0 if o["lscale"][0] < 0 else 1.0
for ch in o.get("children", []):
q = by_id[ch]
qd = next((c.get("v") for c in q["c"] if c.get("class") == "DamageHero" and c.get("v") is not None), None)
qc = next((c for c in q["c"] if c["type"] in ("BoxCollider2D", "PolygonCollider2D") and c.get("v") and
c["v"].get("m_IsTrigger") and c["v"].get("m_Enabled", 1)), None)
- if qd is None or qc is None:
+ zone = q["name"] == "Battle Range"
+ if (qd is None and not zone) or qc is None:
continue
pts = [((x - o["pos"][0]) * sgn, y - o["pos"][1]) for x, y in _shape(q, qc)][:8]
xs, ys = [t[0] for t in pts], [t[1] for t in pts]
nrec = (len(pts) + 3) // 4
- out.append(rec(ENT_BOX, ET_HITBOX, box=(min(xs), min(ys), max(xs), max(ys)),
+ qd = qd or {"damageDealt": 0, "hazardType": 0}
+ out.append(rec(ENT_BOX, ET_ZONE if zone else ET_HITBOX, box=(min(xs), min(ys), max(xs), max(ys)),
p=(len(pts), qd.get("damageDealt", 1), qd.get("hazardType", 1), 0), a=1 if q["self_active"] else 0,
group=nrec, s0=strings.id(q["name"]) if strings else 0))
for i in range(nrec):
@@ -409,6 +444,11 @@ def _enemy(o, by_id, persist, name, d=None, strings=None, owners=None):
vals = [float((var.get(k) or [0, 0])[1] or 0) for k in nums] + [0.0] * (8 - len(nums))
bits = sum(1 << i for i, k in enumerate(bools) if (var.get(k) or [0, False])[1])
out.append(rec(ENT_BOX, ET_VARS, p=tuple(vals[:4]), box=tuple(vals[4:8]), a=bits))
+ if fsm.get("name") == "Big Fly Control" and d is not None:
+ # (Gruz Mother: where her young wait, Fly Spawn; her burster brings them there)
+ fs = next((q for q in d["objects"] if q["name"] == "Fly Spawn"), None)
+ if fs:
+ out.append(rec(ENT_BOX, ET_VARS, p=(fs["pos"][0], fs["pos"][1], 0, 0)))
rc = next((c.get("v") for c in o["c"] if c.get("class") == "Recoil" and c.get("v")), None)
if rc:
out.append(rec(ENT_BOX, ET_RECOIL, box=(rc.get("recoilSpeedBase", 15), rc.get("recoilDuration", 0.15), 0, 0),
@@ -523,6 +563,84 @@ def _props(d, o, by_id, rooms, strings, persist, sprites, owners, name):
return None
+def _go_var(d, o, f, var, by_id):
+ """An FSM's GameObject variable -> the object's id (a reference, or what FindGameObject or FindChild sets it to),
+ or None."""
+ v = (f.get("vars") or {}).get(var)
+ if v and isinstance(v[1], list) and v[1][0] == "ref" and v[1][2] in by_id:
+ return v[1][2]
+ for st in f["states"]:
+ for a in st["actions"]:
+ if not a.get("enabled", True):
+ continue
+ if a["name"] == "FindGameObject" and _param(a, "store") == "$" + var:
+ q = next((q for q in d["objects"] if q["name"] == _param(a, "objectName") and q["active"]), None)
+ if q:
+ return q["id"]
+ if a["name"] in ("FindChild", "GetChild") and _param(a, "storeResult") == "$" + var:
+ q = next((by_id[c] for c in o.get("children", []) if by_id[c]["name"] == _param(a, "childName")), None)
+ if q:
+ return q["id"]
+ return None
+
+
+def _arenas(d, by_id):
+ """The arenas (Battle Control, but the False Knight's) -> (the objects their Activate destroys or hides, the enemies
+ they count: SetBattleScene's)."""
+ gone, counted = set(), set()
+ for o in d["objects"]:
+ f = _fsm(o, ("Battle Control",)) if o["active"] else None
+ if not f or "False Knight" in f["vars"]:
+ continue
+ act = _state(f, "Activate")
+ for a in act["actions"] if act else []:
+ if not a.get("enabled", True):
+ continue
+ if a["name"] == "DestroyObject" or a["name"] == "ActivateGameObject" and _param(a, "activate") is False:
+ g = _param(a, "gameObject")
+ q = _go_var(d, o, f, g[1:], by_id) if isinstance(g, str) and g.startswith("$") else None
+ todo = [q] if q is not None else []
+ while todo:
+ i = todo.pop()
+ gone.add(i)
+ todo += by_id[i].get("children", [])
+ for st in f["states"]:
+ for a in st["actions"]:
+ if a["name"] == "SetBattleScene" and a.get("enabled", True):
+ g = _param(a, "target")
+ q = _go_var(d, o, f, g[1:], by_id) if isinstance(g, str) and g.startswith("$") else None
+ if q is not None:
+ counted.add(q)
+ return gone, counted
+
+
+def _gate(d, o, owners):
+ """A battle gate (BG Control, or a gate closed till a PlayerData bool is set) -> its record, or None."""
+ f = _fsm(o, ("BG Control",))
+ fp = _fsm(o, ("Control",)) if f is None and "Battle Gate" in o["name"] else None
+ check = _state(fp, "Check") if fp else None
+ test = next((a for a in check["actions"] if a["name"] == "PlayerDataBoolTest"), None) if check else None
+ if f is None and test is None:
+ return None
+ fl, pd = 0, 0
+ if f:
+ clip = {st["name"]: next((_param(a, "clipName") for a in st["actions"]
+ if a["name"].startswith("Tk2dPlayAnimation") and a.get("enabled", True)), None)
+ for st in f["states"]}
+ if (clip.get("Opened") or "").startswith("Bone"):
+ fl |= BGF_BONE
+ if (f["vars"].get("Start Closed") or [0, False])[1]:
+ fl |= BGF_START_CLOSED
+ else:
+ fl |= BGF_PD | BGF_START_CLOSED
+ pd = pd_flags()[_param(test, "boolName")]
+ c0, cn = _subcols(d, owners, o["id"]) if owners else (0, 0)
+ m = np.array(o["m3"]).reshape(3, 3)
+ sx = float(np.hypot(m[0, 0], m[1, 0])) * (-1.0 if np.linalg.det(m[:2, :2]) < 0 else 1.0)
+ sy = float(np.hypot(m[0, 1], m[1, 1]))
+ return rec(ENT_OBJ, OK_BGATE, (o["pos"][0], o["pos"][1], o["pos"][2], sx), (sy, pd, 0, 0), a=c0, group=cn, s0=fl)
+
+
def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0, col_base=0, group_base=0):
"""-> (packed records, {object id: render group}). owners: each collider's object (coll.room); sprites: where the
objects' own sprites go (Sprites)."""
@@ -536,6 +654,7 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0
marker_index = {}
objs = [o for o in d["objects"] if o["active"]]
by_id = {o["id"]: o for o in d["objects"]}
+ arena_gone, arena_counted = _arenas(d, by_id)
def subtree(oid, g):
groups[oid] = g
@@ -618,6 +737,38 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0
battles.append((len(recs), (ref("CameraLock 1") or [0, 0, 0])[2], (ref("CameraLock 2") or [0, 0, 0])[2]))
recs.append(rec(ENT_OBJ, OK_BATTLE, _trigger(o) or (0, 0, 0, 0), (-1, -1, 1, 0), group=g_arm,
persist=persist.id(name, o["path"]) if persistent else NO_PERSIST))
+ if f and "False Knight" not in f["vars"]:
+ # an arena: its trigger (or none: an enemy starts it), its camera lock (fixed up below), how many it counts
+ # down and the wait after
+ acts = lambda n: [a for a in ((_state(f, n) or {}).get("actions") or []) if a.get("enabled", True)]
+ sends = lambda n: [_param(a, "sendEvent") for a in acts(n) if a["name"] == "SendEventByName"]
+ fl = 0
+ if any(a["name"] == "Trigger2dEvent" for a in acts("Detect")):
+ fl |= ARF_TRIGGER
+ if "BG DESTROY" in sends("Activate"):
+ fl |= ARF_DESTROY_GATES
+ if "BG QUICK OPEN" in sends("Activate"):
+ fl |= ARF_QUICK_OPEN
+ count = next((_param(a, "intValue") for a in acts("Start") + acts("Wave 1") if a["name"] == "SetIntValue"),
+ (f["vars"].get("Battle Enemies") or [0, 0])[1])
+ wait = next((_param(a, "time") for a in acts("End Wait") if a["name"] == "Wait"), 2)
+ for k in ("Wave 2", "Complete", "Kill Zombies"):
+ if _state(f, k):
+ print("ents: %s: %s: arena state %s not handled" % (name, o["path"], k))
+ persistent = any(c.get("class") == "PersistentBoolItem" for c in o["c"])
+ battles.append((len(recs), _go_var(d, o, f, "Camera Lock", by_id), None))
+ recs.append(rec(ENT_OBJ, OK_ARENA, _trigger(o) or (0, 0, 0, 0), (-1, -1, count, wait), a=fl,
+ persist=persist.id(name, o["path"]) if persistent else NO_PERSIST))
+ g = _gate(d, o, owners)
+ if g:
+ recs.append(g)
+ ev = next((c.get("v") for c in o["c"] if c.get("class") == "SendPlaymakerEventOnEnable" and c.get("v")), None)
+ if ev:
+ # (an event broadcast as the room starts)
+ if ev.get("eventName") in BG_EVENTS:
+ recs.append(rec(ENT_OBJ, OK_EVENT, a=BG_EVENTS.index(ev["eventName"])))
+ else:
+ print("ents: %s: %s: event %s not handled" % (name, o["path"], ev.get("eventName")))
f = _fsm(o, ("Floor Control",))
if f:
# the False Knight's floor: the colliders it loses (Break Floor's), its whole sprites' group, then a record
@@ -647,9 +798,13 @@ def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0
recs += extra
en = _enemy(o, by_id, persist, name, d, strings, owners) or _props(d, o, by_id, rooms, strings, persist, sprites, owners, name)
if en:
- if o["id"] in prebattle and en[0][1] == OK_ENEMY:
+ if en[0][1] == OK_ENEMY:
+ fl = EF_PREBATTLE if o["id"] in prebattle else 0
+ fl |= EF_BATTLE if o["id"] in arena_counted else 0
+ fl |= EF_ARENA_GONE if o["id"] in arena_gone else 0
+ fl |= EF_SPAWNED if by_id.get(o.get("parent"), {}).get("name") == "Fly Spawn" else 0
b = bytearray(en[0])
- struct.pack_into("<H", b, 42, struct.unpack_from("<H", b, 42)[0] | EF_PREBATTLE)
+ struct.pack_into("<H", b, 42, struct.unpack_from("<H", b, 42)[0] | fl)
en[0] = bytes(b)
recs += en
br = next((c for c in o["c"] if c.get("class") == "Breakable" and c.get("v") is not None), None)
diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.py
index 35a04147..e1bff37f 100644
--- a/games/hollowknight/tools/pack.py
+++ b/games/hollowknight/tools/pack.py
@@ -59,17 +59,7 @@ SECTIONS = ["TEX", "TMAP", "PAL", "BIDX", "BLK", "ROOMS", "RBLOB", "PRIOR", "SOF
def _pdf_flags():
- """PlayerData's bools as the game numbers them (src/game.h: PDF_*), by their names in the game ("falseKnightDefeated")"""
- import re
- src = open(os.path.join(SRC, "game.h")).read()
- names = re.search(r"enum \{\s*(PDF_AT_BENCH[^}]*)\}", src).group(1)
- ids = [n.strip() for n in names.replace("\n", " ").split(",") if n.strip() and n.strip() != "PDF_COUNT"]
- camel = lambda n: "".join(w.capitalize() for w in n[4:].lower().split("_"))
- out = {}
- for i, n in enumerate(ids):
- c = camel(n)
- out[c[0].lower() + c[1:]] = i
- return out
+ return ents.pd_flags()
BLENDS = {"alpha": 0, "add": 1, "screen": 2, "linearlight": 3, "overlay": 4, "multiply": 5}
F_LIT, F_ROT, F_SOLID, F_DYN, F_GRASS = 8, 16, 32, 64, 128