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



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

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)


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

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



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/demiurge/agent.rb', line 328

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.



324
325
# File 'lib/demiurge/agent.rb', line 324

def offer
end