<data>
	<tiles>	
		<!-- GENERIC TEMPLATE -->
		<tileTemplate r_name="'mainTemplate'"
									r_graphic="tileGraphic+additionalGraphic"
									additionalGraphic="{}"
									r_isSimpleGround="0"
									r_isSimpleWall="isWall"
									rw_isKnown="0"
									w_isSeenByHeroes="0"
									tileName="r_name"
									isWater="0"
									isWall="0"
									r_moveMask="((actors.count==0)?0:1)+(isWall?2:0)+(isWater?4:0)"
									r_losMask="((actors.count==0)?0:1)+(isWall?2:0)+(isWater?8:0)"
									moveCost="100"
									movePlannerCost="100"
									dangerousTile="0" />
		<!-- STANDARD TILE TEMPLATES -->
		<tileTemplate r_name="'groundTemplate'" r_template="'mainTemplate'"
									r_moveMask="actors.count>0"
									r_losMask="actors.count>0"
									r_isSimpleGround="1"/>
		<tileTemplate r_name="'waterTemplate'" r_template="'mainTemplate'"
									isWater="1"
									r_moveMask="(actors.count>0)+4"
									r_losMask="((actors.count==0)?0:1)+8"/>
		<tileTemplate r_name="'wallTemplate'" r_template="'mainTemplate'"
									isWall="1"
									r_moveMask="2"
									r_losMask="2"/>

		<tileTemplate r_name="'downstairAdditionalTemplate'" r_isSimpleGounrd="0">
			<activable r_name="'downstair'" r_template="'downstairTemplate'" r_category="downstairVisible?'stair':'none'">
				<modifier r_name="'downstairXCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'downstairXCoord'" r_modifiedValue="w_xCoord"/>
				<modifier r_name="'downstairYCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'downstairYCoord'" r_modifiedValue="w_yCoord"/>
			</activable>
		</tileTemplate>
		<tileTemplate r_name="'upstairAdditionalTemplate'" r_isSimpleGounrd="0">
			<activable r_name="'upstair'" r_template="'upstairTemplate'">
				<modifier r_name="'upstairXCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'upstairXCoord'" r_modifiedValue="w_xCoord"/>
				<modifier r_name="'upstairYCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'upstairYCoord'" r_modifiedValue="w_yCoord"/>
			</activable>
		</tileTemplate>
		<tileTemplate r_name="'exitPortalAdditionalTemplate'" r_isSimpleGounrd="0">
			<activable r_name="'portal'" r_template="'portalTemplate'">
				<modifier r_name="'downstairXCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'downstairXCoord'" r_modifiedValue="w_xCoord"/>
				<modifier r_name="'downstairYCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'downstairYCoord'" r_modifiedValue="w_yCoord"/>
			</activable>
		</tileTemplate>
		<tileTemplate r_name="'entryPortalAdditionalTemplate'" r_isSimpleGounrd="0">
			<activable r_name="'portal'" r_template="'mainActivableTemplate'"> <!-- dummy activable -->
				<modifier r_name="'upstairXCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'upstairXCoord'" r_modifiedValue="w_xCoord"/>
				<modifier r_name="'upstairYCoord'" r_template="'mainModifierTemplate'" r_modifierTarget="'upstairYCoord'" r_modifiedValue="w_yCoord"/>
			</activable>
		</tileTemplate>

		<!-- COMMON TILE -->
		<tileTemplate r_name="'commonGround'" r_template="'groundTemplate'" tileGraphic="tileGraphic={designNameGround+'_field_'+(1DgroundGraphicCount-1)+'.png'}"/>
		<tileTemplate r_name="'commonWater'" r_template="'waterTemplate'" tileGraphic="tileGraphic={designNameWater+'_water'}"/>
		<tileTemplate r_name="'commonWall'" r_template="'wallTemplate'" tileGraphic="tileGraphic={designNameGround+'_field_'+(1DgroundGraphicCount-1)+'.png',designNameWall+'_wall_'+(1DwallGraphicCount-1)+'.png'}"/>

		<!-- COMPLEX TILE (graphic influenced by neighbors)-->
		<tileTemplate r_name="'complexShadeTemplate'"
									shadeGraphic="shadeGraphic=simplifyArray(((shadeOrientation!='000')?{'common_shade_'+shadeOrientation+'.png'}:{})+((!shadeMask[0]&&shadeMask[1]&&!shadeMask[2])?{'common_shade_corner_UR.png'}:{}))"
									shadeMask="shadeMask=level.neighborMask(w_xCoord,w_yCoord,'isWall')"
									shadeOrientation="''+shadeMask[0]+shadeMask[2]+shadeMask[4]+(shadeMask[3]?'_UL':'')"/>
		<tileTemplate r_name="'complexWithShadeTemplate'" r_template="'complexShadeTemplate'"
									tileGraphic="baseTileGraphic+shadeGraphic"/>
									
		<tileTemplate r_name="'complexGround'" r_template="{'groundTemplate','complexWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray({relocate(baseGroundGraphic)})"/>
		<tileTemplate r_name="'complexWater'" r_template="{'waterTemplate','complexWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray(	{designNameWater+'_water'}+
																																	{designNameWaterBorder+'_water_'+orientation+'.png'}+
																																	((neighborMask[0]&&!neighborMask[1]&&neighborMask[2])?{designNameWall+'_water_corner_UR.png'}:{})+
																																	((neighborMask[2]&&!neighborMask[3]&&neighborMask[4])?{designNameWall+'_water_corner_UL.png'}:{})+
																																	((neighborMask[4]&&!neighborMask[5]&&neighborMask[6])?{designNameWall+'_water_corner_BL.png'}:{})+
																																	((neighborMask[6]&&!neighborMask[7]&&neighborMask[0])?{designNameWall+'_water_corner_BR.png'}:{}))"
									neighborMask="neighborMask=level.neighborMask(w_xCoord,w_yCoord,'isWater')"
									orientation="''+neighborMask[0]+neighborMask[2]+neighborMask[4]+neighborMask[6]"/>
		<tileTemplate r_name="'complexWall'" r_template="'wallTemplate'"
									tileGraphic="tileGraphic=({designNameWall+'_wall_'+orientation+'.png'}+cornerGraphic+additionalGraphic)"
									cornerGraphic="((neighborMask[0]&&!neighborMask[1]&&neighborMask[2])?{designNameWall+'_wall_corner_UR.png'}:{})+((neighborMask[2]&&!neighborMask[3]&&neighborMask[4])?{designNameWall+'_wall_corner_UL.png'}:{})+((neighborMask[4]&&!neighborMask[5]&&neighborMask[6])?{designNameWall+'_wall_corner_BL.png'}:{})+((neighborMask[6]&&!neighborMask[7]&&neighborMask[0])?{designNameWall+'_wall_corner_BR.png'}:{})"
									additionalGraphic="additionalGraphic=((!neighborMask[6])?additionalWallGraphics:{})"
									neighborMask="neighborMask=level.neighborMask(w_xCoord,w_yCoord,'isWall')"
									orientation="''+neighborMask[0]+neighborMask[2]+neighborMask[4]+neighborMask[6]"/>
		<tileTemplate r_name="'complex8Wall'" r_template="'wallTemplate'"
									tileGraphic="tileGraphic=({designNameWall+'_wall_'+orientation+'.png'}+additionalGraphic)"
									additionalGraphic="additionalGraphic=((!neighborMask[6])?additionalWallGraphics:{})"
									neighborMask="neighborMask=level.neighborMask(w_xCoord,w_yCoord,'isWall')"
									orientation="''+neighborMask[0]+((!neighborMask[0]||!neighborMask[2])?'x':neighborMask[1])+neighborMask[2]+((!neighborMask[2]||!neighborMask[4])?'x':neighborMask[3])+neighborMask[4]+((!neighborMask[4]||!neighborMask[6])?'x':neighborMask[5])+neighborMask[6]+((!neighborMask[6]||!neighborMask[0])?'x':neighborMask[7])"/>
		<tileTemplate r_name="'complexDownstair'" r_template="{'groundTemplate','downstairAdditionalTemplate','complexWithShadeTemplate'}"
									baseTileGraphic="{relocate(baseGroundGraphic),stairGraphic}"
									stairGraphic="designNameStair+'_down.png'"/>
		<tileTemplate r_name="'complexUpstair'" r_template="{'groundTemplate','upstairAdditionalTemplate','complexWithShadeTemplate'}"
									baseTileGraphic="{relocate(baseGroundGraphic),stairGraphic}"
									stairGraphic="designNameStair+'_up.png'"/>

		<!-- ADVANCED GRAPHICS -->
		<tileTemplate r_name="'advancedShadeTemplate'"
									shadeGraphic="shadeGraphic=simplifyArray(shadeMask[4]?(shadeMask[3]?{'ombre1.png'}:{'ombre2.png'}):{})"
									shadeMask="shadeMask=level.neighborMask(w_xCoord,w_yCoord,'isWall')"/>
		<tileTemplate r_name="'advancedWithShadeTemplate'" r_template="'advancedShadeTemplate'"
									tileGraphic="baseTileGraphic+shadeGraphic"/>
		<tileTemplate r_name="'advancedGround'" r_template="{'groundTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray({relocate(baseGroundGraphic)})"/>
		<tileTemplate r_name="'advancedWall'" r_template="{'wallTemplate','advancedShadeTemplate'}"
									wallGraphic="'walls_'+designNameWall+'_'+orientation+'.png'"
									tileGraphic="tileGraphic=({relocate(baseGroundGraphic)}+shadeGraphic+{wallGraphic})"
									neighborMask="neighborMask=level.neighborMask(w_xCoord,w_yCoord,'isWall')"
									orientation="{randomElement({'0000_0','0000_1','0000_2'}),'0001','0010','0011','0100',randomElement({'0101_0','0101_1'}),'0110',randomElement({'0111_0','0111_1'}),'1000','1001',randomElement({'1010_0','1010_1'}),randomElement({'1011_0','1011_1'}),'1100',randomElement({'1101_0','1101_1'}),randomElement({'1110_0','1110_1','1110_2'}),'1111'}[8*neighborMask[0]+4*neighborMask[2]+2*neighborMask[4]+neighborMask[6]]"/>
		<tileTemplate r_name="'advancedWater'" r_template="{'waterTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray(((orientation!='1111')?{relocate(baseGroundGraphic)}:{})+{'eau_'+orientation})"
									neighborMask="neighborMask=level.neighborMask(w_xCoord,w_yCoord,'isWater')"
									orientation="''+neighborMask[0]+neighborMask[2]+neighborMask[4]+neighborMask[6]"/>
		<tileTemplate r_name="'advancedDownstair'" r_template="{'groundTemplate','downstairAdditionalTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="{relocate(baseGroundGraphic)}+(downstairVisible?{stairGraphic}:{})"
									stairGraphic="downstairVisible?(designNameStair+'_down.png'):''">
			<event r_name="'downstairVisible'" r_template="'mainEventTemplate'" r_eventTarget="'downstairVisible'" r_targetType="'attribute'">
				<effect r_name="'graphicRefresh'" r_template="'mainGraphicEffectTemplate'" r_type="'LocalRefresh'"/>
			</event>
		</tileTemplate>
		<tileTemplate r_name="'advancedUpstair'" r_template="{'groundTemplate','upstairAdditionalTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray({relocate(baseGroundGraphic),stairGraphic})"
									stairGraphic="designNameStair+'_up.png'"/>

		<tileTemplate r_name="'advancedUpstair1x2N_0'" r_template="'advancedWall'"
									tileGraphic="{designNameStair+'_up_1x2N0.png'}"
									r_isSimpleWall="0"/>
		<tileTemplate r_name="'advancedUpstair1x2N_1'" r_template="'advancedUpstair'"
									stairGraphic="designNameStair+'_up_1x2N1.png'"/>
		<tileTemplate r_name="'advancedDownstair1x2N_0'" r_template="'advancedWall'"
									tileGraphic="downstairVisible?{designNameStair+'_down_1x2N0.png'}:hiddenGraphic"
									hiddenGraphic="{relocate(baseGroundGraphic)}+shadeGraphic+{'walls_'+designNameWall+'_1110_0.png'}"
									r_isSimpleWall="0">
			<event r_name="'downstairVisible'" r_template="'mainEventTemplate'" r_eventTarget="'downstairVisible'" r_targetType="'attribute'">
				<effect r_name="'graphicRefresh'" r_template="'mainGraphicEffectTemplate'" r_type="'LocalRefresh'"/>
			</event>
		</tileTemplate>
		<tileTemplate r_name="'advancedDownstair1x2N_1'" r_template="'advancedDownstair'"
									stairGraphic="designNameStair+'_down_1x2N1.png'"/>
		<tileTemplate r_name="'advancedUpstair1x2S_0'" r_template="'advancedUpstair'"
									stairGraphic="designNameStair+'_up_1x2S0.png'"/>
		<tileTemplate r_name="'advancedUpstair1x2S_1'" r_template="'advancedWall'"
									tileGraphic="{designNameStair+'_up_1x2S1.png'}"
									r_isSimpleWall="0"/>
		<tileTemplate r_name="'advancedDownstair1x2S_0'" r_template="'advancedDownstair'"
									stairGraphic="designNameStair+'_down_1x2S0.png'"/>
		<tileTemplate r_name="'advancedDownstair1x2S_1'" r_template="'advancedWall'"
									tileGraphic="downstairVisible?{designNameStair+'_down_1x2S1.png'}:hiddenGraphic"
									hiddenGraphic="{relocate(baseGroundGraphic)}+shadeGraphic+{'walls_'+designNameWall+'_1011_0.png'}"
									r_isSimpleWall="0">
			<event r_name="'downstairVisible'" r_template="'mainEventTemplate'" r_eventTarget="'downstairVisible'" r_targetType="'attribute'">
				<effect r_name="'graphicRefresh'" r_template="'mainGraphicEffectTemplate'" r_type="'LocalRefresh'"/>
			</event>
		</tileTemplate>

		<tileTemplate r_name="'exitPortalTile'" r_template="{'groundTemplate','exitPortalAdditionalTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray({relocate(baseGroundGraphic),stairGraphic})"
									stairGraphic="'portal_on.png'"/>
		<tileTemplate r_name="'entryPortalTile'" r_template="{'groundTemplate','entryPortalAdditionalTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray({relocate(baseGroundGraphic),stairGraphic})"
									stairGraphic="'portal_off.png'"/>

		<tileTemplate r_name="'downstairPortal'" r_template="{'groundTemplate','downstairAdditionalTemplate','advancedWithShadeTemplate'}"
									baseTileGraphic="baseTileGraphic=simplifyArray({relocate(baseGroundGraphic),stairGraphic})"
									stairGraphic="'portal_on.png'"/>

		<tileTemplate r_name="'advancedGroundNonBasic'" r_template="'advancedGround'"
									r_isSimpleGround="0"/>
		<tileTemplate r_name="'advancedGroundWithGraphicTile'" r_template="'advancedGroundNonBasic'">
			<activable r_name="'graphicActivable'" r_template="'mainActivableTemplate'" r_graphic="featureAdditionalGraphic"/>
		</tileTemplate>

		<!-- ADVANCED DECORATIVE TILE FACTORIES -->
		<tileTemplate r_name="'multiWallFeatureTileInterface'" r_isSimpleWall="0">
			<event r_name="'featureIsKnown'" r_template="'mainEventTemplate'" r_eventTarget="'featureIsKnown'" r_targetType="'attribute'">
				<effect r_name="'tileBecomesKnown'" r_template="{'mainSelfEffectTemplate','evaluationEffect'}" r_enabled="!rw_isKnown&&featureIsKnown" r_effect="rw_isKnown=1"/>
			</event>
			<event r_name="'tileIsKnown'" r_template="'mainEventTemplate'" r_eventTarget="'rw_isKnown'" r_targetType="'attribute'">
				<effect r_name="'featureBecomesKnown'" r_template="{'mainSelfEffectTemplate','evaluationEffect'}" r_enabled="rw_isKnown&&!featureIsKnown" r_effect="featureIsKnown=1"/>
				<effect r_name="'graphicRefresh'" r_template="'mainGraphicEffectTemplate'" r_type="'LocalRefresh'"/>
			</event>
		</tileTemplate>
		<tile r_name="'standardWallInFeature'" r_template="{'advancedWall','multiWallFeatureTileInterface'}"/>
		
		<!-- design, setIndex, tileIndex -->
		<factory r_name="'wall2x1'" r_params="{{'cave','forest','dungeon','swamp','lavacave','desert'},{0,1,2,3,4,5,6,7,8,9},{0,1}}">
			<tile r_template="{'advancedWall','multiWallFeatureTileInterface'}" wallGraphic="'walls_2x1_'+w_FP0+'_'+w_FP1+'_'+w_FP2+'.png'"/>
		</factory>
		<factory r_name="'wall1x2'" r_params="{{'cave','forest','dungeon','swamp','lavacave','desert'},{0,1,2,3,4,5,6,7,8,9},{0,1}}">
			<tile r_template="{'advancedWall','multiWallFeatureTileInterface'}" wallGraphic="'walls_1x2_'+w_FP0+'_'+w_FP1+'_'+w_FP2+'.png'"/>
		</factory>
		<factory r_name="'wall2x2'" r_params="{{'cave','forest','dungeon','swamp','lavacave','desert'},{0,1,2,3,4,5,6,7,8,9},{0,1,2,3}}">
			<tile r_template="{'advancedWall','multiWallFeatureTileInterface'}" wallGraphic="'walls_2x2_'+w_FP0+'_'+w_FP1+'_'+w_FP2+'.png'"/>
		</factory>
		<factory r_name="'wallInner1x1'" r_params="{{'cave','forest','dungeon','swamp','lavacave','desert'},{0,1,2,3,4,5,6,7,8,9}}">
			<tile r_template="{'advancedWall','multiWallFeatureTileInterface'}" wallGraphic="'walls_inner_1x1_'+w_FP0+'_'+w_FP1+'.png'"/>
		</factory>
		<factory r_name="'wallInner2x2'" r_params="{{'cave','forest','dungeon','swamp','lavacave','desert'},{0,1,2,3,4,5,6,7,8,9},{0,1,2,3}}">
			<tile r_template="{'advancedWall','multiWallFeatureTileInterface'}" wallGraphic="'walls_inner_2x2_'+w_FP0+'_'+w_FP1+'_'+w_FP2+'.png'"/>
		</factory>
		
		<!-- FEATURES TILES -->
		<tileTemplate r_name="'commonDoor'" r_template="groundTile" doorDesignGraphic="doorDesignGraphic=designNameDoor+'_door.png'">
			<activable r_template="'door'" doorGraphic="doorGraphic=doorDesignGraphic"/>
		</tileTemplate>
		<tileTemplate r_name="'specificLoot'" r_template="groundTile">
			<activable r_template="'specificLoot'" specificLoot="lootName"/>
		</tileTemplate>
		<tileTemplate r_name="'commonLoot'" r_template="groundTile">
			<activable r_template="'standardLoot'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonChest'" r_template="groundTile">
			<activable r_template="'standardChest'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonPotion'" r_template="groundTile">
			<activable r_template="'standardPotion'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonBookshelf'" r_template="groundTile">
			<activable r_template="'standardBookshelf'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonArmorRack'" r_template="groundTile">
			<activable r_template="'standardArmorRack'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonJewelleryDisplay'" r_template="groundTile">
			<activable r_template="'standardJewelleryDisplay'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonTrap'" r_template="groundTile">
			<activable r_template="'monsterTrap'"/>
		</tileTemplate>
		<tileTemplate r_name="'commonAltar'" r_template="groundTile" affinityName="''">
			<activable r_template="affinityName+'Altar'"/>
		</tileTemplate>
		<tileTemplate r_name="'AirAltarTile'" r_template="'commonAltar'" affinityName="'Air'"/>
		<tileTemplate r_name="'DeathAltarTile'" r_template="'commonAltar'" affinityName="'Death'"/>
		<tileTemplate r_name="'EarthAltarTile'" r_template="'commonAltar'" affinityName="'Earth'"/>
		<tileTemplate r_name="'FireAltarTile'" r_template="'commonAltar'" affinityName="'Fire'"/>
		<tileTemplate r_name="'HolyAltarTile'" r_template="'commonAltar'" affinityName="'Holy'"/>
		<tileTemplate r_name="'WaterAltarTile'" r_template="'commonAltar'" affinityName="'Water'"/>
		<tileTemplate r_name="'statueAir'" r_template="groundTile">
			<activable r_template="'statueAir'"/>
		</tileTemplate>
		<tileTemplate r_name="'statueEarth'" r_template="groundTile">
			<activable r_template="'statueEarth'"/>
		</tileTemplate>
		<tileTemplate r_name="'statueFire'" r_template="groundTile">
			<activable r_template="'statueFire'"/>
		</tileTemplate>
		<tileTemplate r_name="'statueWater'" r_template="groundTile">
			<activable r_template="'statueWater'"/>
		</tileTemplate>
		<tileTemplate r_name="'DemonInvocator'" r_template="groundTile">
			<activable r_template="'DemonInvocator'"/>
		</tileTemplate>

		<!-- MONSTER TILE -->
		<tileTemplate r_name="'monsterTile'" r_template="groundTile">
			<actor r_name="'monster'" r_template="monsterName"/>
		</tileTemplate>
		<tileTemplate r_name="'bossTile'" r_template="groundTile">
			<actor r_name="'boss'" r_template="{monsterName,'dungeonBossInterface'}"/>
		</tileTemplate>
		<tileTemplate r_name="'finalBossTile'" r_template="groundTile">
			<actor r_name="'finalBoss'" r_template="{monsterName,'campaignBossInterface'}"/>
		</tileTemplate>

		<tileTemplate r_name="'bloodCultLeaderTile'" r_template="'bossTile'" monsterName="'BloodCultLeader'"/>
		<tileTemplate r_name="'bloodCultMemberTile'" r_template="'monsterTile'" monsterName="'BloodCultMember'"/>
		<tileTemplate r_name="'princessTile'" r_template="'monsterTile'" monsterName="'Princess'"/>
		<tileTemplate r_name="'kidTile'" r_template="'monsterTile'" monsterName="'Kid'"/>
		<tileTemplate r_name="'monsterTileManticore'" r_template="'monsterTile'" monsterName="'Manticore'"/>
		<tileTemplate r_name="'monsterTileGorgon'" r_template="'monsterTile'" monsterName="'Gorgon'"/>
		<tileTemplate r_name="'monsterTileLich'" r_template="'monsterTile'" monsterName="'Lich'"/>
		<tileTemplate r_name="'monsterTileMinotaur'" r_template="'monsterTile'" monsterName="'Minotaur'"/>
	</tiles>
</data>