Example #1
0
def make_mob_opts(mobname):
    opts = Opt()
    opts.mobname = mobname
    opts.direction_change_prob = MOB_DIRECTION_CHANGE_PROB[mobname]
    opts.color = MOB_COLORS[mobname]
    opts.speed = MOB_SPEED[mobname]
    opts.loiter_prob = MOB_LOITER_PROB[mobname]
    opts.loiter_time = MOB_LOITER_TIME[mobname]
    opts.step_height = MOB_STEP_HEIGHT[mobname]
    opts.mobType = list(MOBS_BY_ID.keys())[list(
        MOBS_BY_ID.values()).index(mobname)]
    return opts
Example #2
0
    def test_add_mob(self):
        # add mob
        chicken = {v: k for k, v in MOBS_BY_ID.items()}["chicken"]
        mob_id, mob_type, pos = 42, chicken, Pos(3, 4, 5)
        self.memory.set_mob_position(Mob(mob_id, mob_type, pos))

        # get mob
        self.assertIsNotNone(self.memory.get_mob_by_eid(mob_id))

        # update mob
        pos = Pos(6, 7, 8)
        self.memory.set_mob_position(Mob(mob_id, mob_type, pos))

        # get mob
        mob_node = self.memory.get_mob_by_eid(mob_id)
        self.assertIsNotNone(mob_node)
        self.assertEqual(mob_node.pos, (6, 7, 8))
Example #3
0
def find_nearby_mobs(agent, radius, p=None, names=None):
    """Find mobs near the agent.
    NOTE: If names is a list will only return mobs in the list"""
    if p is None:
        p = agent.pos
    L = agent.get_mobs()
    M = {}
    for l in L:
        ep = (l.pos.x, l.pos.y, l.pos.z)
        if (ep[0] - p[0]) ** 2 + (ep[1] - p[1]) ** 2 + (ep[2] - p[2]) ** 2 < radius ** 2:
            name = MOBS_BY_ID.get(l.mobType)
            if names is None or name in names:
                if M.get(name) is None:
                    M[name] = [{"pos": ep, "id": l.entityId}]
                else:
                    M[name].append({"pos": ep, "id": l.entityId})
    return M
Example #4
0
 def test_add_guardian_mob(self):
     guardian = {v: k for k, v in MOBS_BY_ID.items()}["guardian"]
     mob_id, mob_type, pos, look = 42, guardian, Pos(3, 4, 5), Look(0.0, 0.0)
     self.memory.set_mob_position(Mob(mob_id, mob_type, pos, look))