# pieces.py - Classes for simulating "The Settlers of Catan"
#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
# 97-02-27 ct7 Original version.
# 97-03-06 ct7 Seperate display methods into layout manager calls
#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Land:

	def __init__( self, type, char ):

		self.type  = type
		self.repr  = char

	def __mul__( self, other ):

		if type(other) == type(0):
			a = []
			for i in range(other):
				a.append( self )
			return a
		else:
			raise TypeError, "Can't multiply Land by %s" % other

	def __repr__( self ):

		return self.repr

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Port:

	def __init__( self, type, count ):

		self.type  = type
		self.count = count

	def __mul__( self, other ):

		if type(other) == type(0):
			a = []
			for i in range(other):
				a.append( self )
			return a
		else:
			raise TypeError, "Can't multiply Port by %s" % other

	def __repr__( self ):

		return "%d%s:1?" % ( self.count, self.type )

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Piece:

	def __init__( self, layout, x, y ):

		self.layout = layout
		self.x = x
		self.y = y

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Hex( Piece ):

	def __init__( self, layout, x, y, land=None, roll=None ):

		Piece.__init__( self, layout, x, y )

		self.land  = land
		self.roll  = roll
		self.spots = []

	def __repr__( self ):

		return "H(%d,%d)" % (self.x, self.y)

	def draw( self ):

		self.layout.draw_hex( self )

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Spot( Piece ):

	def __init__( self, layout, x, y ):

		Piece.__init__( self, layout, x, y )

		self.port = None

		self.settler = 0
		self.city    = 0
		self.lands   = []
		self.roads   = []
		self.spots   = []

	def __repr__( self ):

		return "S(%d,%d)" % (self.x, self.y)

	def draw( self ):

		self.layout.draw_spot( self )

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

class Road:

	def __init__( self, layout, fm, to ):

		self.layout = layout

		self.fm = fm
		self.to = to
		self.settler = 0

	def __repr__( self ):

		return "R(%d,%d-%d,%d)" % \
			(self.fm.x, self.fm.y, self.to.x, self.to.y )

	def draw( self ):

		self.layout.draw_road( self )

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Any    = Land( "any",   "?" )
Sheep  = Land( "sheep", "S" )
Trees  = Land( "trees", "T" )
Brick  = Land( "brick", "B" )
Rocks  = Land( "rocks", "R" )
Wheat  = Land( "wheat", "W" )
Desert = Land( "desert","D" )
Water  = Land( "water", " " )

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

p4any   = Port( Any,   4 )
p3any   = Port( Any,   3 )
p2sheep = Port( Sheep, 2 )
p2trees = Port( Trees, 2 )
p2brick = Port( Brick, 2 )
p2rocks = Port( Rocks, 2 )
p2wheat = Port( Wheat, 2 )

#---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

