git.fiddlerwoaroof.com
Ed L authored on 30/07/2012 21:10:55
Showing 8 changed files
... ...
@@ -3,7 +3,7 @@ import os
3 3
 def take(num, iter_):
4 4
    for _ in range(num): yield iter_.next()
5 5
 
6
-def _get_last_module(num=1, exclude_modules={'debug'}):
6
+def get_last_module(num=1, exclude_modules={'debug'}):
7 7
 	modname = '%s.py' % __name__.split('.')[-1]
8 8
 	try:
9 9
 		result = take(
... ...
@@ -35,3 +35,4 @@ def debug(func):
35 35
 		return result
36 36
 	return _inner
37 37
 
38
+_get_last_module = get_last_module
... ...
@@ -91,12 +91,12 @@ class ItemLoader(object):
91 91
 			distance = doc.get('distance')
92 92
 
93 93
 
94
-@Game.register_item_type(5)
94
+@Game.register_item_type(10)
95 95
 class HealingPotion(Item):
96 96
 	name = 'Healing potion'
97 97
 	char = '\x03'
98 98
 	color = libtcod.violet
99
-	potency = 10
99
+	potency = 15
100 100
 	item_class = 'healing'
101 101
 	def use(self):
102 102
 		fighter = self.user.fighter
... ...
@@ -111,7 +111,7 @@ class HealingPotion(Item):
111 111
 
112 112
 		return result
113 113
 
114
-@Game.register_item_type(2)
114
+@Game.register_item_type(7)
115 115
 class SuperHealingPotion(Item):
116 116
 	name = 'Super healing potion'
117 117
 	char = '\x03'
... ...
@@ -22,10 +22,11 @@ class Level(object):
22 22
 			dj = self.djikstra_cache[x,y] = djikstra.DjikstraMap(self.map.map.data)
23 23
 			dj.set_goals( (x,y), weight=0)
24 24
 		dj = self.djikstra_cache[x,y]
25
-		dj.cycle()
25
+		dj.iter(3)
26 26
 		return dj
27 27
 
28 28
 	def __init__(self, width, height, con, item_types=None, monster_types=None):
29
+		self.clear_cells = set()
29 30
 		self.djikstra_cache = {}
30 31
 		self.objects = []
31 32
 		self.map = maps.Map(width, height, con, self)
... ...
@@ -101,11 +102,19 @@ class Level(object):
101 102
 				wall = cell.block_sight
102 103
 				walkable = not cell.blocked
103 104
 
105
+				if (x,y) in self.clear_cells and not self.is_blocked(x,y):
106
+					libtcod.console_set_char(self.con, x,y, ord(' '))
104 107
 				if wall or walkable:
105 108
 					color = {
106 109
 						True: {True: self.color_light_wall, False: self.color_light_ground},
107 110
 						False: {True: self.color_dark_wall, False: self.color_dark_ground}
108 111
 					}[visible][wall]
112
+					if not self.is_blocked(x,y):
113
+						dj=self.get_djikstra(*self.player.pos)
114
+						dist = dj.get_cell( (x,y) )
115
+						if 0 < dist < 10:
116
+							libtcod.console_put_char(self.con, x,y, ord(str(dist)))
117
+							self.clear_cells.add((x,y))
109 118
 				elif not walkable:
110 119
 					color = libtcod.Color(100,100,200)
111 120
 
... ...
@@ -655,7 +655,7 @@ RIGHT=1
655 655
 CENTER=2
656 656
 # initializing the console
657 657
 def console_init_root(w, h, title, fullscreen=False, renderer=RENDERER_SDL):
658
-    _lib.TCOD_console_init_root(w, h, title, c_uint(fullscreen), c_uint(renderer))
658
+    _lib.TCOD_console_init_root(w, h, title, c_bool(fullscreen), c_uint(renderer))
659 659
 
660 660
 def console_get_width(con):
661 661
     return _lib.TCOD_console_get_width(con)
... ...
@@ -772,7 +772,7 @@ def console_get_height_rect(con, x, y, w, h, fmt):
772 772
     return _lib.TCOD_console_get_height_rect(c_void_p(con), x, y, w, h, c_char_p(fmt))
773 773
 
774 774
 def console_rect(con, x, y, w, h, clr, flag=BKGND_DEFAULT):
775
-    _lib.TCOD_console_rect(con, x, y, w, h, c_int(clr), flag)
775
+    _lib.TCOD_console_rect(con, x, y, w, h, c_bool(clr), flag)
776 776
 
777 777
 def console_hline(con, x, y, l, flag=BKGND_DEFAULT):
778 778
     _lib.TCOD_console_hline( con, x, y, l, flag)
... ...
@@ -1462,10 +1462,10 @@ def map_copy(source, dest):
1462 1462
     return _lib.TCOD_map_copy(source, dest)
1463 1463
 
1464 1464
 def map_set_properties(m, x, y, isTrans, isWalk):
1465
-    _lib.TCOD_map_set_properties(m, x, y, c_int(isTrans), c_int(isWalk))
1465
+    _lib.TCOD_map_set_properties(m, x, y, c_bool(isTrans), c_bool(isWalk))
1466 1466
 
1467 1467
 def map_clear(m,walkable=False,transparent=False):
1468
-    _lib.TCOD_map_clear(m,c_int(walkable),c_int(transparent))
1468
+    _lib.TCOD_map_clear(m,c_bool(walkable),c_bool(transparent))
1469 1469
 
1470 1470
 def map_compute_fov(m, x, y, radius=0, light_walls=True, algo=FOV_RESTRICTIVE ):
1471 1471
     _lib.TCOD_map_compute_fov(m, x, y, c_int(radius), c_bool(light_walls), c_int(algo))
... ...
@@ -103,8 +103,9 @@ if __name__ == 'main':
103 103
 			self.levels = [levels.Level(self.MAP_WIDTH, self.MAP_HEIGHT, self.con, self.item_types, self.monster_types)]
104 104
 
105 105
 			x,y = None,None
106
+
106 107
 			self.player = objects.Player(self.level.map, self.con, x,y, '@', libtcod.white,
107
-				fighter=objects.Fighter(hp=20, defense = 2, power = 10, death_function=self.player_death)
108
+				fighter=objects.Fighter(hp=40, defense = 2, power = 11, death_function=self.player_death)
108 109
 			)
109 110
 
110 111
 
... ...
@@ -345,6 +346,13 @@ if __name__ == 'main':
345 346
 			libtcod.console_print_ex(self.panel, self.BAR_WIDTH/2,3, libtcod.BKGND_NONE, libtcod.CENTER,
346 347
 				'%s p %s d' %(self.player.fighter.power, self.player.fighter.defense)
347 348
 			)
349
+			fps = libtcod.sys_get_fps()
350
+			if fps < 10:
351
+				import debug
352
+				print 'FPS drop!'
353
+			libtcod.console_print_ex(self.panel, self.BAR_WIDTH/2,4, libtcod.BKGND_NONE, libtcod.CENTER,
354
+				'%s FPS' %(libtcod.sys_get_fps())
355
+			)
348 356
 
349 357
 			libtcod.console_set_default_foreground(self.panel, libtcod.light_gray)
350 358
 			libtcod.console_print(self.panel, 1, 0, self.get_names_under_mouse())
... ...
@@ -395,6 +403,7 @@ if __name__ == '__main__':
395 403
 
396 404
 	game_instance.load_settings()
397 405
 	action = game_instance.main_menu()
406
+	libtcod.sys_set_fps(Game.LIMIT_FPS)
398 407
 	while action is None or action.lower() != 'exit':
399 408
 		if action is not None:
400 409
 			if action.lower() == 'play':
... ...
@@ -419,11 +419,13 @@ class Map(collections.MutableSequence):
419 419
 
420 420
 	def choose_empty_point(self, room):
421 421
 		empty_points = [p for p in room.iter_cells() if not self.is_blocked(*p)]
422
+
423
+		result = None,None
422 424
 		if empty_points:
423
-			for x in empty_points:
424
-				self.level.get_djikstra(*x)
425
-			return random.choice(empty_points)
426
-		return None,None
425
+			result = random.choice(empty_points)
426
+			self.level.get_djikstra(*result)
427
+
428
+		return result
427 429
 
428 430
 	def place_objects(self, room, monster_types, max_num_monsters, item_types, max_num_items):
429 431
 		self.place_monsters(room, monster_types, max_num_monsters)
... ...
@@ -44,15 +44,16 @@ class Thief(BasicMonster):
44 44
 			BasicMonster.take_turn(self)
45 45
 
46 46
 	def steal(self):
47
-		if self.player.inventory.keys() == 0:
47
+		if self.player.inventory.keys():
48
+			print self.player.inventory.keys()
48 49
 			game_instance.message( ('%s can\'t find anything to steal'%self.owner.name).capitalize(), libtcod.orange )
49
-		obj = random.choice(self.player.inventory.keys())
50
-		game_instance.message( ('%s tries to steal %s'%(self.owner.name,obj)).capitalize(), libtcod.red)
51
-		if random.random() < self.skill:
52
-			game_instance.message( ('%s successfully steals %s'%(self.owner.name,obj)).capitalize(), libtcod.orange)
53
-			obj = self.player.inventory[obj]
54
-			self.inventory.append(obj)
55
-			del self.player.inventory[obj]
50
+			obj = random.choice(self.player.inventory.keys())
51
+			game_instance.message( ('%s tries to steal %s'%(self.owner.name,obj)).capitalize(), libtcod.red)
52
+			if random.random() < self.skill:
53
+				game_instance.message( ('%s successfully steals %s'%(self.owner.name,obj)).capitalize(), libtcod.orange)
54
+				obj = self.player.inventory[obj]
55
+				self.inventory.append(obj)
56
+				del self.player.inventory[obj.name]
56 57
 
57 58
 	def death(self):
58 59
 		monster_death(self.owner)
... ...
@@ -77,20 +78,12 @@ class DjikstraMonster(Monster):
77 78
 
78 79
 	def init(self, level):
79 80
 		self.level = level
80
-		#print
81
-		#print 'now olog on level:', self.level, self.maps
81
+		self.owner.always_visible = True
82 82
 
83 83
 		self.opos = self.owner.x, self.owner.y
84 84
 		self.ppos = None
85 85
 
86 86
 		map = level.map
87
-		if self.dj.map is None:
88
-			self.dj.load_map(map.map.data)
89
-
90
-			self.dj.set_goals(*(room.center for room in map.gen.rooms), weight = 0)
91
-
92
-			while self.dj.cycle(): pass
93
-
94 87
 		#self.dj.visualize()
95 88
 
96 89
 	def take_turn(self):
... ...
@@ -103,8 +96,8 @@ class DjikstraMonster(Monster):
103 96
 			else:
104 97
 				dx, dy = self.owner.move_towards(*self.level.player.pos)
105 98
 
106
-		elif random.random() < .4:
107
-			dx,dy = self.dj.nav(*pos)
99
+		#elif random.random() < .4:
100
+		#	dx,dy = self.dj.nav(*pos)
108 101
 
109 102
 		else:
110 103
 			dj = self.level.get_djikstra(*self.level.player.pos)
... ...
@@ -12,6 +12,7 @@ class Object(object):
12 12
 		self.color = color
13 13
 		self.blocks = blocks
14 14
 		self.con = con
15
+		self.always_visible = False
15 16
 #		self.map = map
16 17
 
17 18
 		if level is not None:
... ...
@@ -80,7 +81,7 @@ class Object(object):
80 81
 		return self.move(dx, dy)
81 82
 
82 83
 	def draw(self, player=None):
83
-		if player is None or player.can_see(self.x, self.y):
84
+		if player is None or self.always_visible or player.can_see(self.x, self.y):
84 85
 			libtcod.console_set_default_foreground(self.con, self.color)
85 86
 			libtcod.console_put_char(self.con, self.x,self.y, self.char, libtcod.BKGND_NONE)
86 87
 		return self