Creeps and neutral camps
Camps of creeps that guard their ground: the whole camp answers a hit, goes for whoever hurt it most, gives up what it cannot catch, and walks home healing. They sleep at night and can respawn. Camps come with the heroes pack (packs: [heroesPack()], see Packs); without it, creeps are ordinary units that fight back.
Quick start
import { heroesPack, spawnCamp, type Rules } from '@v12-engine/engine'
export const myGame: Rules = { ...game, packs: [heroesPack()] }
// in your scene's start: two gnolls and an ogre guarding a spot, for the map's creeps player
spawnCamp(world, CREEPS, { x: 40, z: 40 }, ['gnoll', 'gnoll', 'ogre'])The camp stands at the point. Hit one creep and all three come for you, the one who did the most damage first. Walk more than 14 cells away and they go home.
Common tasks
Make camps hold tighter ground and never sleep
settings: { camps: { leash: 10, chaseTime: 3, sleep: false } }Respawn camps
settings: { camps: { respawn: 120 } } // seconds after a camp is cleared, once no one else stands in itChange one camp while the game runs
campNamed(world, 'ogres')!.resetAfter = 12 // a camp's own number wins over the rules'Taunt a camp
aggroCamp(world, camp, hero, 500) // as if the hero had done 500 damage; the camp comes at onceReset or bring back a camp now
resetCamp(world, camp) // drop the fight and walk home
respawnCamp(world, camp) // bring a cleared camp backTake over a creep's idle behaviour
Add your own idle hook handler before the camps' ('guardCamp', in campHooks) and set event.handled.
Place camps from a prefab or the map
Camps on a map, and in a prefab's contents.camps, are spawned with the map (Components and prefabs). Neutral buildings (shops, taverns, a fountain) are ordinary units owned by the neutral player: see Heroes and Economy.
Reference
Camp rules (Rules.settings.camps)
| Rule | Default | What it says | A camp's own |
|---|---|---|---|
leash | 14 | How far from the camp's centre its creeps fight | Camp.leash, spawnCamp(…, leash) |
chaseTime | 5 | Seconds chasing with no blow either way before taking the next target | Camp.chaseTime |
resetAfter | 6 | Seconds without a blow before the camp goes home | Camp.resetAfter |
helpAtOnce | true | The whole camp answers a hit the tick it lands; false waits for each creep's look round (every fourth tick) | Camp.helpAtOnce |
sleep | true | Creeps sleep at home at night | |
respawn | none | Seconds after clearing before it comes back (never if left out) | Camp.respawn |
States
| State | What the creeps do | Until |
|---|---|---|
| Asleep | Stand at home at night, see nothing | A hit on one of them, or day |
| Guarding | Stand at home, look round every fourth tick | Something comes in range, or a hit |
| Aggro | The whole camp goes for the best of the aggro list | The list is empty and nothing is in range |
| Chase | A creep after its target | A blow either way (clock restarts), chaseTime without one, or the leash |
| Reset | Creeps with nothing to fight wait where they stand | Something to fight, or resetAfter since the last blow |
| Home | Walk home, healing 10% a second; deaf for RETURN_GRACE (1.5 s) | Home, or a hit after the grace |
How a camp fights
- The aggro list (
Camp.aggro:{ id, threat, lastHitAt }): threat is the damage done to the camp. A creep picks the most threat, then the nearest (campTarget, through thetargetScorehook: threat × 1000 less the distance), then what comes near, then its last attacker. - All at once: a hit wakes and calls every creep of the camp, except those already fighting, those with an order, and those standing down (
CombatState.passive). - Giving up: a target not hit nor hitting for
chaseTime, or a chase stuck pastgiveUpChase(1 s), is shunned forSHUN_TIME(4 s). - The leash is measured from the camp's centre, not each creep's home. A creep more than two cells past it turns back.
- A camp belongs to the map's creeps player (
creeps: true, everyone's enemy). Its members and homes areCamp.members,campMember,CampMember.home,CampMember.returning. - Events:
campCleared,campReturned. - The list, the creeps' state and the last blow (
Camp.foughtAt) are saved, so a fight resumes after a load.
Hooks
| Hook | Use |
|---|---|
targetScore | Change what a creep goes for, as for any unit (Combat) |
idle | The camps' guarding is the 'guardCamp' handler |
canAttack | What a creep may attack |
Functions
| Call | What it does |
|---|---|
spawnCamp(world, owner, point, types, leash?) | Puts a camp on the map |
campsOf(world), campNamed(world, name) | All camps; the one of a name |
campTarget(world, creep, camp) | What the creep would go for now |
aggroCamp(world, camp, unit, threat?) | A taunt |
resetCamp(world, camp) | Gives up the fight now |
respawnCamp(world, camp) | Brings a cleared camp back now |
campHooks, campListeners | Turn camps on without the heroes pack |