-
Notifications
You must be signed in to change notification settings - Fork 18
Creep Roles.md
Mirroar edited this page May 27, 2025
·
1 revision
Creep roles in Hivemind define the behavior and logic for each type of creep in your empire. The creep manager uses these roles to determine what each creep should do every tick, based on the role property in the creep's memory.
- Each creep has a
roleproperty in its memory (e.g.,creep.memory.role = 'builder'). - The creep manager (
CreepManager) is responsible for running the correct logic for each creep, based on its role. - Roles are registered with the creep manager, and each role is a class that extends the base
Roleclass. - On each tick, the creep manager iterates over all creeps and calls the
runmethod of the appropriate role class.
To add a new role, create a new class that extends Role (see src/role/role.ts):
import Role from 'role/role';
export default class MyCustomRole extends Role {
run(creep: Creep) {
// Your custom logic here
if (!creep.memory.working && creep.store.getFreeCapacity() === 0) {
creep.memory.working = true;
} else if (creep.memory.working && creep.store[RESOURCE_ENERGY] === 0) {
creep.memory.working = false;
}
if (creep.memory.working) {
// Do work
} else {
// Gather energy
}
}
}Register your new role with the creep manager (usually in the spawn manager or using the onGlobalReset callback):
creepManager.registerCreepRole('myCustomRole', new MyCustomRole());A creep's role is usually set when it is spawned, based on the desired behavior. You can change a creep's role at any time by updating its memory:
creep.memory.role = 'myCustomRole';- The creep manager uses throttling to limit how often each creep's logic runs, especially under CPU pressure.
- Each role can define its own
throttleAtandstopAtvalues (inherited from theRolebase class), which control when creeps of that role are skipped based on available bucket. - Creeps at room borders are never throttled, to avoid getting stuck.
- Throttled creeps will have their logic skipped for the tick, and statistics are tracked and reported to the console.
- Creeps are throttled individually, so if one creep of a role is throttled, others can still run. Roughly, the percentage of creeps that run is determined by how much bucket is available compared to the
throttleAtandstopAtvalues.
- Keep role logic focused and modular—each role should only handle one type of behavior.
- Use the
preRunmethod for checks or setup before the mainrunlogic. - Adjust
throttleAtandstopAtif your role is critical or can be deprioritized under CPU pressure.