Package horizons :: Package util :: Module tile_orientation
[hide private]
[frames] | no frames]

Source Code for Module horizons.util.tile_orientation

 1  # ################################################### 
 2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
 3  # team@unknown-horizons.org 
 4  # This file is part of Unknown Horizons. 
 5  # 
 6  # Unknown Horizons is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the 
18  # Free Software Foundation, Inc., 
19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
20  # ################################################### 
21   
22  from horizons.constants import BUILDINGS 
23   
24   
25 -def get_tile_alignment_action(origin, is_similar_tile):
26 """ 27 ROAD/WALL ORIENTATION CHEATSHEET 28 ================================ 29 a b 30 \ e / a,b,c,d are connections to nearby roads 31 \ / 32 \ / e,f,g,h indicate whether this area occupies more space than 33 h X f a single road would (i.e. whether we should fill this three- 34 / \ cornered space with graphics that will make it look like a 35 / \ coherent square instead of many short-circuit road circles). 36 / g \ Note that 'e' can only be placed if both 'a' and 'b' exist. 37 d c 38 39 SAMPLE ROADS 40 ============ 41 \ \ \..../ \ / \ / 42 \ .\ \../ \ /. \ /. 43 \ ..\ \/ \/.. \/.. 44 / ../ / .. /\.. 45 / ./ / . /..\. 46 / / / /....\ 47 48 ad adh abde abf (im- abcdfg 49 possible) 50 """ 51 action = '' 52 53 # Order is important here. 54 ordered_actions = sorted(BUILDINGS.ACTION.action_offset_dict.items()) 55 for action_part, (xoff, yoff) in ordered_actions: 56 if not is_similar_tile(origin.offset(xoff, yoff)): 57 continue 58 59 if action_part in 'abcd': 60 action += action_part 61 if action_part in 'efgh': 62 # Now check whether we can place valid road-filled areas. 63 # Only adds 'g' to action if both 'c' and 'd' are in already 64 # (that's why order matters - we need to know at this point) 65 # and the condition for 'g' is met: road tiles exist in that 66 # direction. 67 fill_left = chr(ord(action_part) - 4) in action 68 # 'h' has the parents 'd' and 'a' (not 'e'), so we need a slight hack here. 69 fill_right = chr(ord(action_part) - 3 - 4 * (action_part == 'h')) in action 70 if fill_left and fill_right: 71 action += action_part 72 if action == '': 73 # Single trail piece with no neighbor road tiles. 74 action = 'single' 75 76 return action
77