Class: Demiurge::AgentInternal::WanderIntention Private

Inherits:
Demiurge::ActionItemInternal::ActionIntention show all
Defined in:
lib/demiurge/agent.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Instance Attribute Summary

Attributes inherited from Demiurge::ActionItemInternal::ActionIntention

#action_args, #action_name

Instance Method Summary collapse

Methods inherited from Demiurge::ActionItemInternal::ActionIntention

#apply_notification, #cancel_notification

Methods inherited from Intention

#apply_notification, #cancel, #cancel_notification, #cancelled?, #try_apply

Constructor Details

#initialize(engine, name, *args) ⇒ WanderIntention

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Constructor



305
306
307
308
# File 'lib/demiurge/agent.rb', line 305

def initialize(engine, name, *args)
  @name = name
  super(engine, name, "", *args)
end

Instance Method Details

#allowed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Always allowed

Returns:

  • (Boolean)


311
312
313
# File 'lib/demiurge/agent.rb', line 311

def allowed?
  true
end

#applyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Actually wander to an adjacent position, chosen randomly



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# 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

#offerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



318
319
# File 'lib/demiurge/agent.rb', line 318

def offer
end