class Demiurge::AgentInternal::WanderIntention

This is a simple Wandering agent for use with TmxLocations and similar grid-based maps.

@api private

Public Class Methods

new(engine, name, *args) click to toggle source

Constructor

# File lib/demiurge/agent.rb, line 305
def initialize(engine, name, *args)
  @name = name
  super(engine, name, "", *args)
end

Public Instance Methods

allowed?() click to toggle source

Always allowed

# File lib/demiurge/agent.rb, line 311
def allowed?
  true
end
apply() click to toggle source

Actually wander to an adjacent position, chosen randomly

# File lib/demiurge/agent.rb, line 322
def apply
  agent = @engine.item_by_name(@name)
  agent.state["wander_counter"] += 1
  wander_every = agent.state["wander_every"] || 3
  return if agent.state["wander_counter"] < wander_every
  next_coords = agent.location.adjacent_positions(agent.position)
  if next_coords.empty?
    @engine.admin_warning("Oh no! Wandering agent #{@name.inspect} is stuck and can't get out!",
                         "zone" => agent.zone_name, "location" => agent.location_name, "agent" => @name)
    return
  end
  chosen = next_coords.sample
  pos = "#{agent.location_name}##{chosen.join(",")}"
  agent.move_to_position(pos, { "method" => "wander" })
  agent.state["wander_counter"] = 0
end
offer() click to toggle source

For now, WanderIntention is unblockable. That's not perfect, but otherwise we have to figure out how to offer an action without an action name.

# File lib/demiurge/agent.rb, line 318
def offer
end