Stress for create networks
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
// create's blocks that do something: so far what turns (create:kinetic), the hand crank that turns it, and the
|
||||
// mechanical press
|
||||
import type { BlockRef, EntityRef, Id, ServerContext } from "bworld/server";
|
||||
import { along, kinetic_shape, type KineticParams } from "./kinetics/connections.ts";
|
||||
import { handle_added, handle_removed, type KineticWorld, type Pos, update_generated } from "./kinetics/spreading.ts";
|
||||
import { actual_speed, along, kinetic_shape, type KineticParams, type Pos } from "./kinetics/connections.ts";
|
||||
import { handle_added, handle_removed, type KineticWorld, update_generated } from "./kinetics/spreading.ts";
|
||||
import {
|
||||
PRESSING,
|
||||
processing_for,
|
||||
@@ -18,9 +18,13 @@ import { CYCLE, cycle_rate, PRESS_AT, type PressShown, SCAN_TICKS } from "./proc
|
||||
interface Config {
|
||||
max_speed: number;
|
||||
crank_hunger: number;
|
||||
// by block id, what each block takes per rpm and what each generator makes per rpm, like create's CStress. 0 for a
|
||||
// block that isn't there
|
||||
stress: { impact: Record<Id, number>; capacity: Record<Id, number> };
|
||||
}
|
||||
|
||||
// a kinetic block's tile data, see KineticNode. its speed is its "speed" client data, which its visual turns it by
|
||||
// a kinetic block's tile data, see KineticNode. its speed is its "speed" client data, and whether its network is
|
||||
// overstressed its "overstressed" client data, which its visual turns it by
|
||||
interface KineticData {
|
||||
source?: Pos;
|
||||
network?: string;
|
||||
@@ -127,7 +131,7 @@ function register_press(ctx: ServerContext, recipes: ProcessingRecipe[]) {
|
||||
ctx.components.register_block("create:mechanical_press", {
|
||||
on_tick(block) {
|
||||
const data: PressData = block.data ?? {};
|
||||
const rate = cycle_rate(block.get_client_data<number>("speed") ?? 0);
|
||||
const rate = cycle_rate(actual_speed(block));
|
||||
if (data.pressing === undefined) {
|
||||
// a block that starts turning ticks again, see kinetic_world
|
||||
if (rate === 0) {
|
||||
@@ -163,8 +167,8 @@ function register_press(ctx: ServerContext, recipes: ProcessingRecipe[]) {
|
||||
});
|
||||
}
|
||||
|
||||
// the world as rotation spreading sees it: blocks with create:kinetic, their speed in client data and where it comes
|
||||
// from in tile data
|
||||
// the world as rotation spreading sees it: blocks with create:kinetic, their speed and whether they're overstressed in
|
||||
// client data, and where their speed comes from in tile data
|
||||
function kinetic_world(ctx: ServerContext, config: Config): KineticWorld {
|
||||
// components never change once loaded, so each block's are looked up once
|
||||
const params = new Map<Id, { kinetic?: KineticParams; crank?: CrankParams }>();
|
||||
@@ -207,6 +211,9 @@ function kinetic_world(ctx: ServerContext, config: Config): KineticWorld {
|
||||
source: data.source,
|
||||
network: data.network,
|
||||
generated,
|
||||
impact: config.stress.impact[block.id] ?? 0,
|
||||
capacity: config.stress.capacity[block.id] ?? 0,
|
||||
overstressed: block.get_client_data<boolean>("overstressed") ?? false,
|
||||
};
|
||||
},
|
||||
set(at, speed, source, network) {
|
||||
@@ -220,6 +227,12 @@ function kinetic_world(ctx: ServerContext, config: Config): KineticWorld {
|
||||
break(at) {
|
||||
ctx.world.break_block(...at);
|
||||
},
|
||||
set_overstressed(at, overstressed) {
|
||||
const block = block_at(at);
|
||||
// like a block that starts turning, see set
|
||||
if (!overstressed && block.get_client_data("speed")) block.set_ticking(true);
|
||||
block.set_client_data("overstressed", overstressed || undefined);
|
||||
},
|
||||
max_speed: config.max_speed,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user