Beispiel #1
0
def init_suspect_positions (game):
    sl    = game.suspect_list
    manor = game.base_manor
    for sid in xrange(len(sl.suspects)):
        if sid == sl.victim:
            continue

        s = sl.get_suspect(sid)
        s.path = []
        if sid == sl.murderer:
            candidates = []
            for c in AdjacencyIterator(sl.get_victim().pos):
                if manor.get_feature(c).traversable():
                    candidates.append(c)
            if len(candidates) > 0:
                s.pos = random.choice(candidates)
                murderer_flees(game, sid)
                continue

        alibi = s.alibi
        if alibi == None:
            rid = random.choice(manor.rooms)
        else:
            rid = s.alibi.rid

        room  = manor.get_room(rid)
        start = room.pos() + 1
        stop  = room.pos() + room.size() - 2

        while True:
            s.pos = Coord(random.randint(start.x, stop.x), random.randint(start.y, stop.y))
            if manor.get_feature(s.pos).traversable():
                break

        # The murderer is trying to leave as quickly as possible.
        if sid == sl.murderer:
            murderer_flees(game, sid)
            continue

        if s.alibi == None:
            rid = None
        else:
            rid = s.alibi.rid
        rp  = game.base_manor.room_props[rid]
        if sid in rp.owners:
            if s.gender == 'f':
                pronoun = "her"
            else:
                pronoun = "his"
            print "%s is already in %s bedroom." % (s.get_name(), pronoun)
            # Suspect in their own bedroom -> they won't be leaving for a while.
            s.duration = 100
Beispiel #2
0
    def move_suspect (self, i):
        sl = self.suspect_list
        s  = sl.get_suspect(i)
        if len(s.path) == 0:
            if s.duration > 0:
                s.duration -= 1
            elif one_chance_in(30):
                self.set_suspect_path(i)

        manor = self.base_manor
        if len(s.path) > 0:
            if self.player_pos == s.path[-1]:
                return

            new_pos = s.path.pop()
            if len(s.path) == 0:
                rp = manor.room_props[manor.get_room_index(new_pos)]
                if i in rp.owners:
                    if s.gender == 'f':
                        pronoun = "her"
                    else:
                        pronoun = "his"
                    room_name = "%s bedroom" % pronoun

                    if self.turns > 780:
                       s.duration = 500
                else:
                    room_name = rp.room_name(True)
                print "%s has reached %s." % (s.get_name(), room_name)
        else:
            valid_moves = []
            for pos in AdjacencyIterator(s.pos):
                if pos == self.player_pos:
                    continue
                if not manor.get_feature(pos).traversable():
                    continue
                # Don't leave the room yet.
                if s.duration > 0 and manor.get_room_index(pos) != manor.get_room_index(s.pos):
                    continue

                valid_moves.append(pos)

            if len(valid_moves) == 0:
                return

            new_pos = random.choice(valid_moves)

        # If we walk into another suspect, swap positions.
        for s2 in sl.suspects:
            if s != s2 and new_pos == s2.pos:
                s2.pos = s.pos
                break

        # Set the new position.
        s.pos = new_pos