Skip to content

Commit

Permalink
Merge branch 'other-vectors'
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed May 14, 2020
2 parents efc5c26 + a2e3a62 commit cbeed8b
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 10 deletions.
8 changes: 8 additions & 0 deletions SYNTAX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ These are defined in df-code.lisp:

with some extra code to make it easier to interact with.

``<df-other-vectors-type type-name='foo_other' index-enum='foo_other_id' item-type='foo'/>``

Defines a tuple of vectors with the same base type. Individual vectors act as if they were defined as::

<stl-vector name='FOO_KEY' pointer-type='foo'/>

where ``FOO_KEY`` is a key in the ``foo_other_id`` enum.

Class type definition
=====================

Expand Down
9 changes: 8 additions & 1 deletion StructFields.pm
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,17 @@ sub emit_struct_fields($$;%) {
&render_struct_field($_) for @fields;

my $identity_type = 'struct_identity';
my $maybe_index_enum = '';
if ($flags{-class}) {
$identity_type = 'virtual_identity';
} elsif (is_attr_true($tag, 'is-union')) {
$identity_type = 'union_identity';
} elsif (($tag->getAttribute('ld:subtype') or '') eq 'df-other-vectors-type') {
$identity_type = 'other_vectors_identity';
my $xe = $tag->getAttribute('index-enum');
#static_include_type $xe;
my $enum = type_identity_reference($types{$xe});
$maybe_index_enum = ', '.$enum;
}

my $full_name = fully_qualified_name($tag, $name, 1);
Expand Down Expand Up @@ -657,7 +664,7 @@ sub emit_struct_fields($$;%) {
type_identity_reference($tag,-parent => 1), ', ',
"\"$name\", ",
($inherits ? "&${inherits}::_identity" : 'NULL'), ', ',
"$ftable);";
"${ftable}${maybe_index_enum});";
}
} 'fields-' . $fields_group;
}
Expand Down
6 changes: 6 additions & 0 deletions StructType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ sub render_struct_type {
my $item_type = $tag->getAttribute('item-type');
my $list_link_type = $tag->getAttribute('df-list-link-type');
my $list_link_field = $tag->getAttribute('df-list-link-field');
my $is_other_vectors = (($tag->getAttribute('ld:subtype') or '') eq 'df-other-vectors-type');
my $index_enum = $tag->getAttribute('index-enum');
my $custom_methods = is_attr_true($tag, 'custom-methods') || $tag->findnodes('custom-methods/cmethod');
my $has_methods = $is_class || is_attr_true($tag, 'has-methods');
my $inherits = $tag->getAttribute('inherits-from');
Expand All @@ -218,6 +220,10 @@ sub render_struct_type {
} elsif ($is_linked_list) {
register_ref $item_type, 1;
$ispec = ' : DfLinkedList<'.$typename.', '.$item_type.'>';
} elsif ($is_other_vectors) {
register_ref $item_type, 0;
register_ref $index_enum, 1;
$ispec = ' : DfOtherVectors<'.$typename.', '.$index_enum.', '.$item_type.'>';
}

if ($list_link_type) {
Expand Down
15 changes: 15 additions & 0 deletions data-definition.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<xs:element name="struct-type" type="StructTypeDef" />
<xs:element name="class-type" type="ClassTypeDef" />
<xs:element name="df-linked-list-type" type="DFLinkedListTypeDef" />
<xs:element name="df-other-vectors-type" type="DFOtherVectorsTypeDef" />
<xs:element name="global-object" type="GlobalObjectDef" />
</xs:choice>
</xs:group>
Expand Down Expand Up @@ -155,6 +156,20 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="DFOtherVectorsTypeDef" mixed="true">
<xs:complexContent>
<xs:extension base="TypeDef">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="SharedElements"/>
<xs:element name="stl-vector" type="StlVectorField" />
</xs:choice>
<xs:attribute name="index-enum" use="required">
</xs:attribute>
<xs:attribute name="item-type" use="required">
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="GlobalObjectDef" mixed="true">
<xs:complexContent>
<xs:extension base="CompoundFieldType">
Expand Down
84 changes: 84 additions & 0 deletions df.building-vectors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,90 @@
<item-attr name='building' value='Instrument'/>
</enum-item>
</enum-type>

<df-other-vectors-type type-name='buildings_other' index-enum='buildings_other_id' item-type='building'>
<stl-vector name='STOCKPILE' pointer-type='building_stockpilest'/>
<stl-vector name='ANY_ZONE' pointer-type='building_civzonest'/>
<stl-vector name='ACTIVITY_ZONE' pointer-type='building_civzonest'/>
<stl-vector name='ANY_ACTUAL' pointer-type='building_actual'/>
<stl-vector name='BOX' pointer-type='building_boxst'/>
<stl-vector name='CABINET' pointer-type='building_cabinetst'/>
<stl-vector name='TRAP' pointer-type='building_trapst'/>
<stl-vector name='DOOR' pointer-type='building_doorst'/>
<stl-vector name='FLOODGATE' pointer-type='building_floodgatest'/>
<stl-vector name='HATCH' pointer-type='building_hatchst'/>
<stl-vector name='GRATE_WALL' pointer-type='building_grate_wallst'/>
<stl-vector name='GRATE_FLOOR' pointer-type='building_grate_floorst'/>
<stl-vector name='BARS_VERTICAL' pointer-type='building_bars_verticalst'/>
<stl-vector name='BARS_FLOOR' pointer-type='building_bars_floorst'/>
<stl-vector name='WELL' pointer-type='building_wellst'/>
<stl-vector name='TABLE' pointer-type='building_tablest'/>
<stl-vector name='BRIDGE' pointer-type='building_bridgest'/>
<stl-vector name='CHAIR' pointer-type='building_chairst'/>
<stl-vector name='TRADE_DEPOT' pointer-type='building_tradedepotst'/>
<stl-vector name='NEST' pointer-type='building_nestst'/>
<stl-vector name='NEST_BOX' pointer-type='building_nest_boxst'/>
<stl-vector name='BOOKCASE' pointer-type='building_bookcasest'/>
<stl-vector name='DISPLAY_CASE' pointer-type='building_display_furniturest' since='v0.44.01'/>
<stl-vector name='HIVE' pointer-type='building_hivest'/>
<stl-vector name='WAGON' pointer-type='building_wagonst'/>
<stl-vector name='SHOP' pointer-type='building_shopst'/>
<stl-vector name='BED' pointer-type='building_bedst'/>
<stl-vector name='TRACTION_BENCH' pointer-type='building_traction_benchst'/>
<stl-vector name='FARM_PLOT' pointer-type='building_farmplotst'/>
<stl-vector name='GEAR_ASSEMBLY' pointer-type='building_gear_assemblyst'/>
<stl-vector name='ROLLERS' pointer-type='building_rollersst'/>
<stl-vector name='AXLE_HORIZONTAL' pointer-type='building_axle_horizontalst'/>
<stl-vector name='AXLE_VERTICAL' pointer-type='building_axle_verticalst'/>
<stl-vector name='SUPPORT' pointer-type='building_supportst'/>
<stl-vector name='ARCHERY_TARGET' pointer-type='building_archerytargetst'/>
<stl-vector name='SCREW_PUMP' pointer-type='building_screw_pumpst'/>
<stl-vector name='WATER_WHEEL' pointer-type='building_water_wheelst'/>
<stl-vector name='WINDMILL' pointer-type='building_windmillst'/>
<stl-vector name='CHAIN' pointer-type='building_chainst'/>
<stl-vector name='CAGE' pointer-type='building_cagest'/>
<stl-vector name='STATUE' pointer-type='building_statuest'/>
<stl-vector name='SLAB' pointer-type='building_slabst'/>
<stl-vector name='COFFIN' pointer-type='building_coffinst'/>
<stl-vector name='WEAPON_RACK' pointer-type='building_weaponrackst'/>
<stl-vector name='ARMOR_STAND' pointer-type='building_armorstandst'/>
<stl-vector name='FURNACE_ANY' pointer-type='building_furnacest'/>
<stl-vector name='FURNACE_WOOD' pointer-type='building_furnacest'/>
<stl-vector name='FURNACE_SMELTER_ANY' pointer-type='building_furnacest'/>
<stl-vector name='FURNACE_SMELTER_MAGMA' pointer-type='building_furnacest'/>
<stl-vector name='FURNACE_KILN_ANY' pointer-type='building_furnacest'/>
<stl-vector name='FURNACE_GLASS_ANY' pointer-type='building_furnacest'/>
<stl-vector name='FURNACE_CUSTOM' pointer-type='building_furnacest'/>
<stl-vector name='WORKSHOP_ANY' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_BUTCHER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_MASON' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_KENNEL' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_FISHERY' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_JEWELER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_LOOM' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_TANNER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_DYER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_MILL_ANY' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_QUERN' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_TOOL' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_MILLSTONE' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_KITCHEN' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_STILL' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_FARMER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_ASHERY' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_CARPENTER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_CRAFTSDWARF' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_MECHANIC' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_SIEGE' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_CLOTHIER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_LEATHER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_BOWYER' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_MAGMA_FORGE' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_FORGE_ANY' pointer-type='building_workshopst'/>
<stl-vector name='WORKSHOP_CUSTOM' pointer-type='building_workshopst'/>
<stl-vector name='WEAPON_UPRIGHT' pointer-type='building_weaponst'/>
<stl-vector name='INSTRUMENT_STATIONARY' pointer-type='building_instrumentst'/>
</df-other-vectors-type>
</data-definition>

<!--
Expand Down
103 changes: 103 additions & 0 deletions df.item-vectors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,109 @@

</enum-type>

<df-other-vectors-type type-name='items_other' index-enum='items_other_id' item-type='item'>
<stl-vector name='WEAPON' pointer-type='item_weaponst'/>
<stl-vector name='ANY_TRUE_ARMOR' pointer-type='item_armorst'/>
<stl-vector name='ANY_ARMOR_HELM' pointer-type='item_helmst'/>
<stl-vector name='ANY_ARMOR_SHOES' pointer-type='item_shoesst'/>
<stl-vector name='SHIELD' pointer-type='item_shieldst'/>
<stl-vector name='ANY_ARMOR_GLOVES' pointer-type='item_glovesst'/>
<stl-vector name='ANY_ARMOR_PANTS' pointer-type='item_pantsst'/>
<stl-vector name='QUIVER' pointer-type='item_quiverst'/>
<stl-vector name='SPLINT' pointer-type='item_splintst'/>
<stl-vector name='ORTHOPEDIC_CAST' pointer-type='item_orthopedic_castst'/>
<stl-vector name='CRUTCH' pointer-type='item_crutchst'/>
<stl-vector name='BACKPACK' pointer-type='item_backpackst'/>
<stl-vector name='AMMO' pointer-type='item_ammost'/>
<stl-vector name='WOOD' pointer-type='item_woodst'/>
<stl-vector name='BRANCH' pointer-type='item_branchst'/>
<stl-vector name='BOULDER' pointer-type='item_boulderst'/>
<stl-vector name='ROCK' pointer-type='item_rockst'/>
<stl-vector name='DOOR' pointer-type='item_doorst'/>
<stl-vector name='FLOODGATE' pointer-type='item_floodgatest'/>
<stl-vector name='HATCH_COVER' pointer-type='item_hatch_coverst'/>
<stl-vector name='GRATE' pointer-type='item_gratest'/>
<stl-vector name='CAGE' pointer-type='item_cagest'/>
<stl-vector name='FLASK' pointer-type='item_flaskst'/>
<stl-vector name='WINDOW' pointer-type='item_windowst'/>
<stl-vector name='GOBLET' pointer-type='item_gobletst'/>
<stl-vector name='INSTRUMENT' pointer-type='item_instrumentst'/>
<stl-vector name='INSTRUMENT_STATIONARY' pointer-type='item_instrumentst'/>
<stl-vector name='TOY' pointer-type='item_toyst'/>
<stl-vector name='TOOL' pointer-type='item_toolst'/>
<stl-vector name='BUCKET' pointer-type='item_bucketst'/>
<stl-vector name='BARREL' pointer-type='item_barrelst'/>
<stl-vector name='CHAIN' pointer-type='item_chainst'/>
<stl-vector name='ANIMALTRAP' pointer-type='item_animaltrapst'/>
<stl-vector name='BED' pointer-type='item_bedst'/>
<stl-vector name='TRACTION_BENCH' pointer-type='item_traction_benchst'/>
<stl-vector name='CHAIR' pointer-type='item_chairst'/>
<stl-vector name='COFFIN' pointer-type='item_coffinst'/>
<stl-vector name='TABLE' pointer-type='item_tablest'/>
<stl-vector name='STATUE' pointer-type='item_statuest'/>
<stl-vector name='SLAB' pointer-type='item_slabst'/>
<stl-vector name='QUERN' pointer-type='item_quernst'/>
<stl-vector name='MILLSTONE' pointer-type='item_millstonest'/>
<stl-vector name='BOX' pointer-type='item_boxst'/>
<stl-vector name='BIN' pointer-type='item_binst'/>
<stl-vector name='ARMORSTAND' pointer-type='item_armorstandst'/>
<stl-vector name='WEAPONRACK' pointer-type='item_weaponrackst'/>
<stl-vector name='CABINET' pointer-type='item_cabinetst'/>
<stl-vector name='ANVIL' pointer-type='item_anvilst'/>
<stl-vector name='CATAPULTPARTS' pointer-type='item_catapultpartsst'/>
<stl-vector name='BALLISTAPARTS' pointer-type='item_ballistapartsst'/>
<stl-vector name='SIEGEAMMO' pointer-type='item_siegeammost'/>
<stl-vector name='TRAPPARTS' pointer-type='item_trappartsst'/>
<stl-vector name='ANY_WEBS' pointer-type='item_threadst'/>
<stl-vector name='PIPE_SECTION' pointer-type='item_pipe_sectionst'/>
<stl-vector name='DRINK' pointer-type='item_drinkst'/>
<stl-vector name='ANY_DRINK' pointer-type='item_drinkst'/>
<stl-vector name='LIQUID_MISC' pointer-type='item_liquid_miscst'/>
<stl-vector name='POWDER_MISC' pointer-type='item_powder_miscst'/>
<stl-vector name='VERMIN' pointer-type='item_verminst'/>
<stl-vector name='PET' pointer-type='item_petst'/>
<stl-vector name='COIN' pointer-type='item_coinst'/>
<stl-vector name='GLOB' pointer-type='item_globst'/>
<stl-vector name='TRAPCOMP' pointer-type='item_trapcompst'/>
<stl-vector name='BAR' pointer-type='item_barst'/>
<stl-vector name='SMALLGEM' pointer-type='item_smallgemst'/>
<stl-vector name='BLOCKS' pointer-type='item_blocksst'/>
<stl-vector name='ROUGH' pointer-type='item_roughst'/>
<stl-vector name='ANY_CORPSE' pointer-type='item_body_component'/>
<stl-vector name='CORPSE' pointer-type='item_corpsest'/>
<stl-vector name='BOOK' pointer-type='item_bookst'/>
<stl-vector name='FIGURINE' pointer-type='item_figurinest'/>
<stl-vector name='AMULET' pointer-type='item_amuletst'/>
<stl-vector name='SCEPTER' pointer-type='item_scepterst'/>
<stl-vector name='CROWN' pointer-type='item_crownst'/>
<stl-vector name='RING' pointer-type='item_ringst'/>
<stl-vector name='EARRING' pointer-type='item_earringst'/>
<stl-vector name='BRACELET' pointer-type='item_braceletst'/>
<stl-vector name='GEM' pointer-type='item_gemst'/>
<stl-vector name='CORPSEPIECE' pointer-type='item_corpsepiecest'/>
<stl-vector name='REMAINS' pointer-type='item_remainsst'/>
<stl-vector name='MEAT' pointer-type='item_meatst'/>
<stl-vector name='FISH' pointer-type='item_fishst'/>
<stl-vector name='FISH_RAW' pointer-type='item_fish_rawst'/>
<stl-vector name='EGG' pointer-type='item_eggst'/>
<stl-vector name='SEEDS' pointer-type='item_seedsst'/>
<stl-vector name='PLANT' pointer-type='item_plantst'/>
<stl-vector name='SKIN_TANNED' pointer-type='item_skin_tannedst'/>
<stl-vector name='PLANT_GROWTH' pointer-type='item_plant_growthst'/>
<stl-vector name='THREAD' pointer-type='item_threadst'/>
<stl-vector name='CLOTH' pointer-type='item_clothst'/>
<stl-vector name='SHEET' pointer-type='item_sheetst'/>
<stl-vector name='TOTEM' pointer-type='item_totemst'/>
<stl-vector name='PANTS' pointer-type='item_pantsst'/>
<stl-vector name='CHEESE' pointer-type='item_cheesest'/>
<stl-vector name='FOOD' pointer-type='item_foodst'/>
<stl-vector name='BALLISTAARROWHEAD' pointer-type='item_ballistaarrowheadst'/>
<stl-vector name='ARMOR' pointer-type='item_armorst'/>
<stl-vector name='SHOES' pointer-type='item_shoesst'/>
<stl-vector name='HELM' pointer-type='item_helmst'/>
<stl-vector name='GLOVES' pointer-type='item_glovesst'/>
</df-other-vectors-type>

</data-definition>

<!--
Expand Down
15 changes: 6 additions & 9 deletions df.world.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<enum-item name='ANY_BABY2'/>
</enum-type>

<df-other-vectors-type type-name='units_other' index-enum='units_other_id' item-type='unit'>
</df-other-vectors-type>

<enum-type type-name='conflict_level'>
<enum-item name='None' value='-1'/>
<enum-item name='Encounter'/>
Expand Down Expand Up @@ -637,9 +640,7 @@

<stl-vector name='all' pointer-type='building'/>

<static-array name='other' count='92' index-enum='buildings_other_id'>
<stl-vector pointer-type='building'/>
</static-array>
<compound name='other' type-name='buildings_other'/>

<stl-vector name='bad' has-bad-pointers='true' pointer-type='building'/>

Expand Down Expand Up @@ -860,9 +861,7 @@

<stl-vector name='active' pointer-type='unit' comment='not sorted, entry 0 is adventurer'/>

<static-array name='other' count='2' index-enum='units_other_id'>
<stl-vector pointer-type='unit'/>
</static-array>
<compound name='other' type-name='units_other'/>

<stl-vector name='bad' has-bad-pointers='true' pointer-type='unit'/>
<stl-vector name='unknown' since='v0.44.06'/>
Expand Down Expand Up @@ -891,9 +890,7 @@

<stl-vector name='all' pointer-type='item'/>

<static-array name='other' count='132' index-enum='items_other_id'>
<stl-vector pointer-type='item'/>
</static-array>
<compound name='other' type-name='items_other'/>

<stl-vector name='bad' has-bad-pointers='true' pointer-type='item'/>

Expand Down
Loading

0 comments on commit cbeed8b

Please sign in to comment.