Module: Api::TechTree
- Defined in:
- lib/sc2ai/api/tech_tree.rb,
lib/sc2ai/api/tech_tree_data.rb
Overview
Provides helper functions which work with and rely on auto generated data in tech_tree_data.rb To lighten code generation, these methods live in a file of their own and may be modified.
Class Method Summary collapse
-
.creates_unit_types(unit_type_id:) ⇒ Array<Integer>
Returns what unit types a specific unit type can produce.
-
.unit_abilities(unit_type_id) ⇒ Array<Integer>
Returns known abilities fo unit type.
-
.unit_created_from(unit_type_id:) ⇒ Array<Integer>
Returns what the unit type another is created from.
-
.unit_special_abilities(unit_type_id) ⇒ Array<Integer>
Returns special abilities, excluding basic start/stop/attack commands.
-
.unit_type_creation_abilities(source:, target: nil) ⇒ Hash
Get units can be created at source + the ability to trigger it.
-
.unit_type_creation_ability_id(source:, target:) ⇒ Integer?
Which ability id creates the target, given the source unit/building.
-
.upgrade_ability_data(source_unit_type_id) ⇒ Hash<Integer, Hash>
Returns hash of upgrade info for a specific structure where the upgrade id is the key.
-
.upgrade_research_ability_id(upgrade_id:) ⇒ Integer
Returns the ability which researches this upgrade.
-
.upgrade_researched_from(upgrade_id:) ⇒ Integer
Returns what the unit type an upgrade is researched from.
-
.upgrade_structure_unit_type_ids ⇒ Array<Integer>
Returns a full list of structure unit id’s which perform upgrades This is a useful list when checking if any updates are in progress, because we scan these structure types for orders.
Class Method Details
.creates_unit_types(unit_type_id:) ⇒ Array<Integer>
Returns what unit types a specific unit type can produce
63 64 65 |
# File 'lib/sc2ai/api/tech_tree.rb', line 63 def creates_unit_types(unit_type_id:) unit_type_creation_abilities_data[unit_type_id].keys end |
.unit_abilities(unit_type_id) ⇒ Array<Integer>
Returns known abilities fo unit type
105 106 107 |
# File 'lib/sc2ai/api/tech_tree.rb', line 105 def unit_abilities(unit_type_id) unit_abilities_data[unit_type_id] end |
.unit_created_from(unit_type_id:) ⇒ Array<Integer>
Returns what the unit type another is created from
70 71 72 |
# File 'lib/sc2ai/api/tech_tree.rb', line 70 def unit_created_from(unit_type_id:) unit_created_from_data[unit_type_id] || [] end |
.unit_special_abilities(unit_type_id) ⇒ Array<Integer>
Returns special abilities, excluding basic start/stop/attack commands
128 129 130 131 132 133 134 135 136 |
# File 'lib/sc2ai/api/tech_tree.rb', line 128 def unit_special_abilities(unit_type_id) @_unit_special_abilities ||= {} if !@_unit_special_abilities[unit_type_id] @_unit_special_abilities[unit_type_id] = unit_abilities(unit_type_id).reject do |ability_id| standard_abilities.include?(Api::AbilityId.generic_id(ability_id)) || standard_abilities.include?(ability_id) end end @_unit_special_abilities[unit_type_id] end |
.unit_type_creation_abilities(source:, target: nil) ⇒ Hash
Get units can be created at source + the ability to trigger it. Optionally target a specific unit from source
41 42 43 44 45 46 47 |
# File 'lib/sc2ai/api/tech_tree.rb', line 41 def unit_type_creation_abilities(source:, target: nil) creates_unit_types = unit_type_creation_abilities_data[source] unless target.nil? return creates_unit_types[target] end creates_unit_types end |
.unit_type_creation_ability_id(source:, target:) ⇒ Integer?
Which ability id creates the target, given the source unit/building
54 55 56 57 58 |
# File 'lib/sc2ai/api/tech_tree.rb', line 54 def unit_type_creation_ability_id(source:, target:) ability_hash = unit_type_creation_abilities(source: source, target: target) return ability_hash[:ability] if ability_hash && ability_hash[:ability] nil end |
.upgrade_ability_data(source_unit_type_id) ⇒ Hash<Integer, Hash>
Returns hash of upgrade info for a specific structure where the upgrade id is the key
99 100 101 |
# File 'lib/sc2ai/api/tech_tree.rb', line 99 def upgrade_ability_data(source_unit_type_id) upgrade_research_abilities_data[source_unit_type_id] end |
.upgrade_research_ability_id(upgrade_id:) ⇒ Integer
Returns the ability which researches this upgrade
83 84 85 86 |
# File 'lib/sc2ai/api/tech_tree.rb', line 83 def upgrade_research_ability_id(upgrade_id:) source_unit_type_id = upgrade_researched_from(upgrade_id:) upgrade_research_abilities_data[source_unit_type_id][upgrade_id][:ability] end |
.upgrade_researched_from(upgrade_id:) ⇒ Integer
Returns what the unit type an upgrade is researched from
77 78 79 |
# File 'lib/sc2ai/api/tech_tree.rb', line 77 def upgrade_researched_from(upgrade_id:) upgrade_researched_from_data[upgrade_id] end |
.upgrade_structure_unit_type_ids ⇒ Array<Integer>
Returns a full list of structure unit id’s which perform upgrades This is a useful list when checking if any updates are in progress, because we scan these structure types for orders
92 93 94 |
# File 'lib/sc2ai/api/tech_tree.rb', line 92 def upgrade_structure_unit_type_ids @upgrade_structure_unit_type_ids ||= upgrade_research_abilities_data.keys end |