Skip to content

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 ​

ts
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 ​

ts
settings: { camps: { leash: 10, chaseTime: 3, sleep: false } }

Respawn camps ​

ts
settings: { camps: { respawn: 120 } } // seconds after a camp is cleared, once no one else stands in it

Change one camp while the game runs ​

ts
campNamed(world, 'ogres')!.resetAfter = 12 // a camp's own number wins over the rules'

Taunt a camp ​

ts
aggroCamp(world, camp, hero, 500) // as if the hero had done 500 damage; the camp comes at once

Reset or bring back a camp now ​

ts
resetCamp(world, camp) // drop the fight and walk home
respawnCamp(world, camp) // bring a cleared camp back

Take 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) ​

RuleDefaultWhat it saysA camp's own
leash14How far from the camp's centre its creeps fightCamp.leash, spawnCamp(…, leash)
chaseTime5Seconds chasing with no blow either way before taking the next targetCamp.chaseTime
resetAfter6Seconds without a blow before the camp goes homeCamp.resetAfter
helpAtOncetrueThe whole camp answers a hit the tick it lands; false waits for each creep's look round (every fourth tick)Camp.helpAtOnce
sleeptrueCreeps sleep at home at night
respawnnoneSeconds after clearing before it comes back (never if left out)Camp.respawn

States ​

StateWhat the creeps doUntil
AsleepStand at home at night, see nothingA hit on one of them, or day
GuardingStand at home, look round every fourth tickSomething comes in range, or a hit
AggroThe whole camp goes for the best of the aggro listThe list is empty and nothing is in range
ChaseA creep after its targetA blow either way (clock restarts), chaseTime without one, or the leash
ResetCreeps with nothing to fight wait where they standSomething to fight, or resetAfter since the last blow
HomeWalk 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 the targetScore hook: 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 past giveUpChase (1 s), is shunned for SHUN_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 are Camp.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 ​

HookUse
targetScoreChange what a creep goes for, as for any unit (Combat)
idleThe camps' guarding is the 'guardCamp' handler
canAttackWhat a creep may attack

Functions ​

CallWhat 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, campListenersTurn camps on without the heroes pack