Class: Demiurge::Zone

Inherits:
Container show all
Defined in:
lib/demiurge/zone.rb

Overview

A simplistic engine may contain only a small number of top-level areas, each a zone in itself. A complex engine may have a small number of areas, but each does extensive managing of its sub-locations.

Direct Known Subclasses

RoomZone, TileZone

Constant Summary

Constants inherited from ActionItem

ActionItem::ACTION_LEGAL_KEYS

Instance Attribute Summary

Attributes inherited from StateItem

#engine, #name

Instance Method Summary collapse

Methods inherited from Container

#can_accomodate_agent?, #contents_names, #ensure_contains, #ensure_does_not_contain, #finished_init, #initialize, #item_change_location, #item_change_position, #move_item_inside, #receive_offer

Methods inherited from ActionItem

#__state_internal, #finished_init, #get_action, #get_actions_with_tags, #initialize, #register_actions, #run_action

Methods inherited from StateItem

#agent?, from_name_type, #get_structure, #initialize, #state, #state_type

Constructor Details

This class inherits a constructor from Demiurge::Container

Instance Method Details

#adjacent_positions(pos, options = {}) ⇒ Array<String>

Returns an array of position strings for positions adjacent to the one given. In some Zones this won't be meaningful. But for most "plain" zones, this gives possibilities of where is moveable for simple AIs.

Returns:

  • (Array<String>)

    Array of position strings

Since:

  • 0.0.1



85
86
87
# File 'lib/demiurge/zone.rb', line 85

def adjacent_positions(pos, options = {})
  []
end

#intentions_for_next_stepArray<Demiurge::Intention>

By default, a zone just passes control to all its non-agent items, gathering up their intentions into a list. It doesn't ask agents since agents located directly in zones are usually only for instantiation.

Returns:

Since:

  • 0.0.1



70
71
72
73
74
75
76
# File 'lib/demiurge/zone.rb', line 70

def intentions_for_next_step
  intentions = @state["contents"].flat_map do |item_name|
    item = @engine.item_by_name(item_name)
    item.agent? ? [] : item.intentions_for_next_step
  end
  intentions
end

#locationDemiurge::StateItem

A Zone isn't located "inside" somewhere else. It is located in/at itself.

Returns:

Since:

  • 0.0.1



19
20
21
# File 'lib/demiurge/zone.rb', line 19

def location
  self
end

#location_nameString

A Zone isn't located "inside" somewhere else. It is located in/at itself.

Returns:

  • (String)

    The zone's name

Since:

  • 0.0.1



27
28
29
# File 'lib/demiurge/zone.rb', line 27

def location_name
  @name
end

#positionString

Similarly, a Zone has no position beyond itself.

Returns:

  • (String)

    The zone's name, which is also its position string

Since:

  • 0.0.1



35
36
37
# File 'lib/demiurge/zone.rb', line 35

def position
  @name
end

#zoneDemiurge::StateItem

A Zone's zone is itself.

Returns:

Since:

  • 0.0.1



43
44
45
# File 'lib/demiurge/zone.rb', line 43

def zone
  self
end

#zone?Boolean

A Zone is, indeed, a Zone.

Returns:

  • (Boolean)

    Return true for Zone and its subclasses.

Since:

  • 0.0.1



59
60
61
# File 'lib/demiurge/zone.rb', line 59

def zone?
  true
end

#zone_nameString

A Zone's zone is itself.

Returns:

  • (String)

    The Zone's item name

Since:

  • 0.0.1



51
52
53
# File 'lib/demiurge/zone.rb', line 51

def zone_name
  @name
end