示例#1
0
def place_equipment(map, x, y, itemToSpawn):
	""" Places a piece of equipment, that can be picked up, at the given position """
	from components import Object, Item, Equipment, Weapon, Armor, Ranged
	import mechanics

	compEquip = Equipment(
							slot=str(itemToSpawn["equipment"]["slot"])
	 					)

	if itemToSpawn["equipment"].has_key("armor"):
		armor= itemToSpawn["equipment"]["armor"]
		compEquip.armor = Armor(bashing_soak=armor["bashing_soak"],
								lethal_soak=armor["lethal_soak"],
								fatigue=armor["fatigue"],
								penalty=armor["penalty"],
								hardness=armor["hardness"])

	if itemToSpawn["equipment"].has_key("weapon"):
		weapon= itemToSpawn["equipment"]["weapon"]
		compEquip.weapon = Weapon(accuracy=weapon["accuracy"],
								damage=weapon["damage"],
								skill=weapon["skill"],
								speed=weapon["speed"])
		if "ranged" in weapon and weapon["ranged"] == True:
			compEquip.ranged = Ranged(accuracy=weapon["ranged_accuracy"],
								damage=weapon["ranged_damage"],
								skill=weapon["ranged_skill"],
								speed=weapon["ranged_speed"])

	item = Object(map.owner, map.owner.maps.index(map), x, y, str(itemToSpawn["character"]), color=libtcod.Color(itemToSpawn["color"][0], itemToSpawn["color"][1], itemToSpawn["color"][2]), name=itemToSpawn["name"], equipment=compEquip)
	map.objects.append(item)
	item.send_to_back()
示例#2
0
def place_item(map, x, y, itemToSpawn):
	""" Places a usable item at the given position """
	from components import Object, Item, Equipment
	import mechanics

	compItem = Item(use_function=getattr(mechanics, itemToSpawn["use_function"]), args=itemToSpawn["args"], count=libtcod.random_get_int(0, itemToSpawn["amount"][0], itemToSpawn["amount"][1]))
	item = Object(map.owner, map.owner.maps.index(map), x, y, str(itemToSpawn["character"]), color=libtcod.Color(itemToSpawn["color"][0], itemToSpawn["color"][1], itemToSpawn["color"][2]), name=itemToSpawn["name"], item=compItem)

	map.objects.append(item)
	item.send_to_back()
 def get_detections(self,
                    frame: np.ndarray,
                    threshold: float = 0.7) -> FrameAnnotations:
     if frame is None:
         return FrameAnnotations(frame=frame,
                                 objects=list(),
                                 image_width=None,
                                 image_height=None)
     new_frame, frame, dimensions = self.prep_frame(frame)
     new_frame = new_frame.cuda()
     frame_dimensions = torch.FloatTensor(dimensions).repeat(1, 2).cuda()
     with torch.no_grad():
         output = self.net(Variable(new_frame), True)
     output = self.format_output(output, threshold, frame_dimensions)
     objects = list()
     if output is not None:
         for obj in output:
             if self.class_filters is not None:
                 if self.class_names[int(obj[-1])] not in \
                         self.class_filters:
                     continue
             objects.append(
                 Object(class_name=self.class_names[int(obj[-1])],
                        bbox=BBox(left=int(obj[1]),
                                  top=int(obj[2]),
                                  right=int(obj[3]),
                                  bottom=int(obj[4]))))
     return FrameAnnotations(frame=frame,
                             objects=objects,
                             image_width=frame.shape[1],
                             image_height=frame.shape[0])
示例#4
0
def spawn_entrance(map, x=None, y=None, dungeon=None):
	""" Spawns the entrance to a dungeon. If dungeon is not set, a randomly generated will be used. """
	from components import Object
	if dungeon is None:
		gvar.game.world.random_dungeon()
		dungeon = gvar.game.world.dungeons[len(gvar.game.world.dungeons)-1]
		dungeon.addRandomMap()

	name = 'Entrance to ' + str(dungeon.id)
	if map in dungeon.maps:
		level = dungeon.maps.index(map)
	else:
		level = 0
	map.objects.append(Object(currentDungeon=dungeon, currentLevel=level, x=2 , y=2 , char=chr(31), name=name, color=libtcod.light_turquoise, always_visible=True, use_function=spawn_player, args=[dungeon, 0]))
示例#5
0
def place_mob_pack(map, x, y, mobToSpawn, packsize):
	""" Places a pack of mobs at the given position. """
	from components import Object,Fighter,MobAI
	from mechanics import mob_death

	for mob in range(1, packsize+1):
		if map.is_blocked(x, y, ai=True):
			(x, y) = map.unblocked_spot_in(4, x, y)
		compAI = MobAI()
		mob = Object(map.owner, map.owner.maps.index(map), x, y, str(mobToSpawn["character"]), color=libtcod.Color(mobToSpawn["color"][0],mobToSpawn["color"][1],mobToSpawn["color"][2]), name=mobToSpawn["name"], blocks=True, exp=mobToSpawn["exp"], ai=compAI)
		compFighter = Fighter(
								hl=mobToSpawn["hl"],
								essence=mobToSpawn["essence"],
								strength=mobToSpawn["strength"],
								dexterity=mobToSpawn["dexterity"],
								skills=mobToSpawn["skills"],
								death_function=mob_death
							)
		mob.fighter = compFighter
		mob.fighter.owner = mob

		map.objects.append(mob)
		mob.send_to_front()
示例#6
0
def spawn_downstairs(map):
	""" |  Spawns the stairs to the next level
		|  Guarantees that it is rechable from the upstairs position
	"""
	from components import Object

	#choose random room
	room = map.random_room()
	(x, y) = room.random_spot()
	#guarantee that player can reach the goal
	while map.is_blocked(x, y, ai=True) or not map.is_reachable((x, y), (map.upstairs.x, map.upstairs.y)):
		room = map.random_room()
		(x, y) = room.random_spot()
	map.downstairs = Object(currentDungeon=map.owner, currentLevel=map.level, x=x, y=y, char=chr(31), name='stairs', color=libtcod.light_turquoise, always_visible=True, use_function=spawn_player, args=[map.owner, map.level+1])
	map.objects.append(map.downstairs)
	map.downstairs.send_to_back()
示例#7
0
	def __init__(self):
		global playermaxhl
		from mechanics import player_death
		from components import Object,Fighter
		from utils import PriorityQueue

		self.player = Object(currentDungeon=None, currentLevel=0, x=0, y=0, char=chr(2), color=libtcod.white, name='player', blocks=True, inventory=[])
		compFighter = Fighter(hl=[1,2,2,1], essence=2, strength=1, dexterity=1, stamina=1, death_function=player_death)
		playermaxhl = compFighter.hl
		self.player.fighter = compFighter
		self.player.fighter.owner = self.player

		self.ticks = PriorityQueue()

		self.game_msgs = []
		self.last_die_rolls = []
		self.game_state = 'playing'
示例#8
0
def spawn_upstairs(map):
	""" Spawns the stairs to the previous level, or to the worldspace, if it's the first level	"""
	from components import Object
	if map.level > 0:
		dest_dungeon = map.owner
		dest_level = map.level - 1
	else:
		dest_dungeon = gvar.game.world.worldspace
		dest_level = 0
	#choose random room
	room = map.random_room()
	(x, y) = room.random_spot()
	#guarantee that player can reach the goal
	while map.is_blocked(x, y, ai=True):
		room = map.random_room()
		(x, y) = room.random_spot()
	map.upstairs = Object(currentDungeon=map.owner, currentLevel=map.level, x=x, y=y, char=chr(30), name='stairs', color=libtcod.light_turquoise, always_visible=True, use_function=spawn_player, args=[dest_dungeon, dest_level])
	map.objects.append(map.upstairs)
	map.upstairs.send_to_back()
    def confirm_box(self, frame, annotations, new_annotations,
                    annotation_file_name) -> None:
        for annotation in annotations:
            annotation = annotation.strip()
            annotation_str = annotation
            frame_copy = frame.copy()
            annotation = annotation.split(',')
            if len(annotation) != 7:
                print(f"Annotation {annotation} is of bad format")
                continue
            class_name, left, top, right, \
                bottom, width, height = annotation
            single_box = FrameAnnotations(
                frame=frame,
                objects=[
                    Object(class_name=class_name,
                           bbox=BBox(
                               left=int(left),
                               top=int(top),
                               right=int(right),
                               bottom=int(bottom),
                           ))
                ],
                image_width=int(width),
                image_height=int(height),
            )
            frame_copy = self.draw_boxes(frame_copy, single_box)
            while True:
                cv2.imshow("image", frame_copy)
                cv2.moveWindow("image", 20, 20)
                print("Press [y] to confirm this box or [n] to delete it")
                print("Pres [q] to fully quit the program.")
                key = cv2.waitKey(0)
                if key & 0xFF == ord('y'):
                    print("Confirmed")
                    new_annotations.append(annotation_str)
                    frame = self.draw_boxes(frame, single_box)
                    break
                elif key & 0xFF == ord('n'):
                    print("Deleted")
                    break
                elif key & 0xFF == ord('q'):
                    print("Are you sure you want to quit [y]/[n]")
                    while True:
                        q = cv2.waitKey(0)
                        if q & 0xFF == ord('y'):
                            sys.exit(0)
                        elif q & 0xFF == ord('n'):
                            break
        print(
            "Done with generated annotations, now for custom if things were missed."
        )
        while True:
            cv2.imshow("image", frame)
            cv2.moveWindow("image", 20, 20)
            print("Press [a] to add a new annotation or [n] to move to " +
                  "next frame")
            key = cv2.waitKey(0)
            if key & 0xFF == ord('n'):
                print("Moving to next frame")
                break
            if key & 0xFF == ord('a'):
                results = self.draw_new_box(frame)
                if results is not None:
                    frame, new_box = results
                    new_annotations.append(new_box)

        self.write_new_results(annotation_file_name, new_annotations)
        cv2.destroyAllWindows()
示例#10
0
def target_tile(max_range=None, radius=0):
	"""	|  Target a distant tile
		|  For Ranged Attacks, like Archery, Thrown
		|  Also Fireballs or similar projectiles with Radius
	"""
	from components import Object
	from mapcreation import Circle
	from render import render_all

	# Spawn a Target Object that can be moved with arrow Keys
	(x, y) = (gvar.game.player.x, gvar.game.player.y)
	target = Object(x, y, 'X', color=libtcod.red, name='target', blocks=False)
	gvar.game.objects.append(target)

	while True:
		target.send_to_front()
		render_all()

		#Render Splash
		libtcod.console_clear(gvar.overlay)
		if radius > 0:
			target.splash = Circle(target.x, target.y, radius)
			for point in target.splash.circle:
				libtcod.console_set_char_background(gvar.overlay, point[0], point[1], libtcod.yellow)
		libtcod.console_blit(gvar.overlay, 0, 0, gvar.SCREEN_WIDTH, gvar.SCREEN_HEIGHT, 0, 0, 0, 1.0, 0.5)
		libtcod.console_flush()

		#Move the Target around
		key = libtcod.Key()
		mouse = libtcod.Mouse()
		key_pressed = libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS,key,mouse,True)
		if not key_pressed:
			return 'cancelled'

		if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x, target.y-1):
				target.y -= 1
		elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x, target.y+1):
				target.y += 1
		elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x-1, target.y):
				target.x -= 1
		elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x+1, target.y):
				target.x += 1
		elif key.vk == libtcod.KEY_KP7:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x-1, target.y-1):
				target.x -= 1
				target.y -= 1
		elif key.vk == libtcod.KEY_KP9:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x+1, target.y-1):
				target.x += 1
				target.y -= 1
		elif key.vk == libtcod.KEY_KP3:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x+1, target.y+1):
				target.x += 1
				target.y += 1
		elif key.vk == libtcod.KEY_KP1:
			if libtcod.map_is_in_fov(gvar.fov_map, target.x-1, target.y+1):
				target.x -= 1
				target.y += 1
		elif key.vk == libtcod.KEY_ENTER:
			gvar.game.objects.remove(target)
			return target
			break
		elif key.vk == libtcod.KEY_ESCAPE:
			gvar.game.objects.remove(target)
			return 'cancelled'
			break
		elif chr(key.c) == 's':
			# Returns String 'closest' for further evaluation by the calling function, e.g. for targeting the closest mob
			gvar.game.objects.remove(target)
			return 'closest'
			break
def target_tile(max_range=None, radius=0):
    """	|  Target a distant tile
		|  For Ranged Attacks, like Archery, Thrown
		|  Also Fireballs or similar projectiles with Radius
	"""
    from components import Object
    from mapcreation import Circle
    from render import render_all

    # Spawn a Target Object that can be moved with arrow Keys
    (x, y) = (gvar.game.player.x, gvar.game.player.y)
    target = Object(x, y, 'X', color=libtcod.red, name='target', blocks=False)
    gvar.game.objects.append(target)

    while True:
        target.send_to_front()
        render_all()

        #Render Splash
        libtcod.console_clear(gvar.overlay)
        if radius > 0:
            target.splash = Circle(target.x, target.y, radius)
            for point in target.splash.circle:
                libtcod.console_set_char_background(gvar.overlay, point[0],
                                                    point[1], libtcod.yellow)
        libtcod.console_blit(gvar.overlay, 0, 0, gvar.SCREEN_WIDTH,
                             gvar.SCREEN_HEIGHT, 0, 0, 0, 1.0, 0.5)
        libtcod.console_flush()

        #Move the Target around
        key = libtcod.Key()
        mouse = libtcod.Mouse()
        key_pressed = libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key,
                                                 mouse, True)
        if not key_pressed:
            return 'cancelled'

        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x, target.y - 1):
                target.y -= 1
        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x, target.y + 1):
                target.y += 1
        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x - 1, target.y):
                target.x -= 1
        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x + 1, target.y):
                target.x += 1
        elif key.vk == libtcod.KEY_KP7:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x - 1, target.y - 1):
                target.x -= 1
                target.y -= 1
        elif key.vk == libtcod.KEY_KP9:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x + 1, target.y - 1):
                target.x += 1
                target.y -= 1
        elif key.vk == libtcod.KEY_KP3:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x + 1, target.y + 1):
                target.x += 1
                target.y += 1
        elif key.vk == libtcod.KEY_KP1:
            if libtcod.map_is_in_fov(gvar.fov_map, target.x - 1, target.y + 1):
                target.x -= 1
                target.y += 1
        elif key.vk == libtcod.KEY_ENTER:
            gvar.game.objects.remove(target)
            return target
            break
        elif key.vk == libtcod.KEY_ESCAPE:
            gvar.game.objects.remove(target)
            return 'cancelled'
            break
        elif chr(key.c) == 's':
            # Returns String 'closest' for further evaluation by the calling function, e.g. for targeting the closest mob
            gvar.game.objects.remove(target)
            return 'closest'
            break