Пример #1
0
def fixupSubsts(item, suffix):
    name = item['cname']+suffix
    dlist = item['cdecls']
    mkConnectionMethodRules = []
    outputPipes = []
    for m in dlist:
        if verbose:
            print 'fixupSubsts', m
        paramsForCall = ['request.%s' % p['pname'] for p in m['dparams']]
        msubs = {'methodName': m['dname'],
                 'paramsForCall': ', '.join(paramsForCall)}
        mkConnectionMethodRules.append(mkConnectionMethodTemplate % msubs)
        outputPipes.append('        interface %(methodName)s_PipeOut = %(methodName)s_requestAdapter.out;' % msubs)
    substs = {
        'Package': '',
        'channelCount': len(dlist),
        'Ifc': item['cname'],
        'dut': util.decapitalize(name),
        'Dut': util.capitalize(name),
    }
    if not generateInterfaceDefs:
        substs['Package'] = item['Package'] + '::'
    substs['requestOutputPipeInterfaces'] = ''.join(
        [requestOutputPipeInterfaceTemplate % {'methodName': m['dname'],
                                               'MethodName': util.capitalize(m['dname'])} for m in dlist])
    substs['outputPipes'] = '\n'.join(outputPipes)
    substs['mkConnectionMethodRules'] = ''.join(mkConnectionMethodRules)
    substs['indicationMethodRules'] = collectElements(dlist, indicationRuleTemplate, name)
    substs['indicationMethods'] = collectElements(dlist, indicationMethodTemplate, name)
    substs['requestElements'] = collectElements(dlist, requestStructTemplate, name)
    substs['methodRules'] = collectElements(dlist, requestRuleTemplate, name)
    substs['methodDef'] = collectElements(dlist, methodDefTemplate, name)
    substs['messageSizes'] = collectElements(dlist, messageSizeTemplate, name)
    return substs
Пример #2
0
    def attack(self, target):
        if not self.is_hostile(target):
            print('warning, %s trying to attack friend %s' %
                  (self.owner.name, target.name))
            return
        # a simple formula for attack damage
        damage = rl.random_int(0, self.power) - rl.random_int(
            0, target.defense)
        print('attack:', self, target, self.power, target.defense, damage)

        if damage > 0:
            #damage = rl.random_int(1, damage)
            # make the target take some damage
            if player in [self, target] or player.can_see(self):
                ui.message(
                    util.capitalize(self.get_name('attack{s}')) + ' ' +
                    target.get_name() + ' for ' + str(damage) + ' hit points.')
            else:
                ui.message('You hear combat in the distance', rl.LIGHTGRAY)
            target.take_damage(damage, self)
        else:
            if player in [self, target] or player.can_see(self):
                ui.message(
                    util.capitalize(self.get_name('attack{s}')) + ' ' +
                    target.get_name() + ' but it has no effect!')
Пример #3
0
def fixupSubsts(item, suffix):
    name = item['name']+suffix
    dlist = item['decls']
    mkConnectionMethodRules = []
    outputPipes = []
    for m in dlist:
        paramsForCall = ['request.%s' % p['name'] for p in m['params']]
        msubs = {'methodName': m['name'],
                 'paramsForCall': ', '.join(paramsForCall)}
        mkConnectionMethodRules.append(mkConnectionMethodTemplate % msubs)
        outputPipes.append('    interface %(methodName)s_PipeOut = toPipeOut(%(methodName)s_requestFifo);' % msubs)
    substs = {
        'Package': item['Package'],
        'channelCount': len(dlist),
        'moduleContext': item['moduleContext'],
        'Ifc': item['name'],
        'dut': util.decapitalize(name),
        'Dut': util.capitalize(name),
        'portalIfc': portalIfcTemplate,
    }
    substs['requestOutputPipeInterfaces'] = ''.join(
        [requestOutputPipeInterfaceTemplate % {'methodName': p['name'],
                                               'MethodName': util.capitalize(p['name'])} for p in dlist])
    substs['outputPipes'] = '\n'.join(outputPipes)
    substs['mkConnectionMethodRules'] = ''.join(mkConnectionMethodRules)
    substs['responseElements'] = collectElements(dlist, responseStructTemplate, name)
    substs['indicationMethodRules'] = collectElements(dlist, indicationRuleTemplate, name)
    substs['indicationMethods'] = collectElements(dlist, indicationMethodTemplate, name)
    substs['requestElements'] = collectElements(dlist, requestStructTemplate, name)
    substs['methodRules'] = collectElements(dlist, requestRuleTemplate, name)
    return substs
Пример #4
0
def collectElements(mlist, workerfn, name):
    methods = []
    mindex = 0
    for item in mlist:
        if verbose:
            print 'collectEl', item
            for p in item['dparams']:
                print 'collectEl/param', p
                break
        sub = { 'dut': util.decapitalize(name),
          'Dut': util.capitalize(name),
          'methodName': item['dname'],
          'MethodName': util.capitalize(item['dname']),
          'channelNumber': mindex}
        paramStructDeclarations = ['    %s %s;' % (toBsvType(p['ptype'], p.get('oldtype')), p['pname']) for p in item['dparams']]
        sub['paramType'] = ', '.join(['%s' % toBsvType(p['ptype'], p.get('oldtype')) for p in item['dparams']])
        sub['formals'] = ', '.join(['%s %s' % (toBsvType(p['ptype'], p.get('oldtype')), p['pname']) for p in item['dparams']])
        structElements = ['%s: %s' % (p['pname'], p['pname']) for p in item['dparams']]
        if not item['dparams']:
            paramStructDeclarations = ['    %s %s;' % ('Bit#(32)', 'padding')]
            structElements = ['padding: 0']
        sub['paramStructDeclarations'] = '\n'.join(paramStructDeclarations)
        sub['structElements'] = ', '.join(structElements)
        methods.append(workerfn % sub)
        mindex = mindex + 1
    return ''.join(methods)
Пример #5
0
 def apply_effect_to_monster(target):
     if target is None:
         return
     if player is caster or player.can_see(caster):
         ui.message(util.capitalize(caster.get_name('cast{s}')) + ' a {spell}'.format(**text))
  
     if len(set(immune) & set(target.skills)) == 0:
         effect(caster, target)
     else:
         if player.can_see(caster) or caster is player:
             ui.message(util.capitalize(target.get_name('resist{s}')) + '.')
Пример #6
0
    def substs(self,suffix,proxy):
        name = "%s%s"%(self.name,suffix)
        dutName = util.decapitalize(name)

        # specific to wrappers
        requestElements = self.collectRequestElements(name)
        methodNames = self.collectMethodNames(name)
        methodRules = self.collectMethodRules(name,False)
        
        # specific to proxies
        responseElements = self.collectResponseElements(name)
        indicationMethodRules = self.collectIndicationMethodRules(name)
        indicationMethods = self.collectIndicationMethods(name)

        m = md5.new()
        m.update(self.name)

        substs = {
            'Ifc': self.name,
            'dut': dutName,
            'Dut': util.capitalize(name),
            'requestElements': ''.join(requestElements),
            'methodNames': methodNames,
            'methodRules': ''.join(methodRules),
            'channelCount': self.channelCount,
            'moduleContext': '',

            'requestChannelCount': len(methodRules) if not proxy else 0,
            'responseElements': ''.join(responseElements),
            'indicationMethodRules': ''.join(indicationMethodRules),
            'indicationMethods': ''.join(indicationMethods),
            'indicationChannelCount': self.channelCount if proxy else 0,
            'indicationInterfaces': ''.join(indicationTemplate % { 'Indication': name }) if not self.hasSource else '',
            }

        substs['ifcType'] = 'truncate(128\'h%s)' % m.hexdigest()
        substs['portalIfc'] = portalIfcTemplate % substs
        substs['requestOutputPipeInterfaces'] = ''.join([requestOutputPipeInterfaceTemplate % {'methodName': methodName,
                                                       'MethodName': util.capitalize(methodName)}
                                                       for methodName in methodNames])
        mkConnectionMethodRules = []
        outputPipes = []
        for m in self.decls:
            if m.type == 'Method' and m.return_type.name == 'Action':
                paramsForCall = ['request.%s' % p.name for p in m.params]
                msubs = {'methodName': m.name,
                         'paramsForCall': ', '.join(paramsForCall)}
                mkConnectionMethodRules.append(mkConnectionMethodTemplate % msubs)
                outputPipes.append('    interface %(methodName)s_PipeOut = toPipeOut(%(methodName)s_requestFifo);' % msubs)
        substs['mkConnectionMethodRules'] = ''.join(mkConnectionMethodRules)
        substs['outputPipes'] = '\n'.join(outputPipes)
        return substs
Пример #7
0
 def substs(self, outerTypeName):
     if self.return_type.name == 'ActionValue':
         rt = self.return_type.params[0].toBsvType()
     else:
         rt = self.return_type.name
     d = { 'dut': util.decapitalize(outerTypeName),
           'Dut': util.capitalize(outerTypeName),
           'methodName': self.name,
           'MethodName': util.capitalize(self.name),
           'channelNumber': self.channelNumber,
           'ord': self.channelNumber,
           'methodReturnType': rt}
     return d
Пример #8
0
 def substs(self, outerTypeName):
     if self.return_type.name == 'ActionValue':
         rt = self.return_type.params[0].toBsvType()
     else:
         rt = self.return_type.name
     d = {
         'dut': util.decapitalize(outerTypeName),
         'Dut': util.capitalize(outerTypeName),
         'methodName': self.name,
         'MethodName': util.capitalize(self.name),
         'channelNumber': self.channelNumber,
         'ord': self.channelNumber,
         'methodReturnType': rt
     }
     return d
Пример #9
0
    def emitBsvWrapper(self,f):
        subs = self.substs('Wrapper',True,False)
        name = "%s%s"%(self.name,'Wrapper')
        methodNames = self.collectMethodNames(name)
        subs['requestOutputPipeInterfaces'] = ''.join([requestOutputPipeInterfaceTemplate % {'methodName': methodName,
                                                                                             'MethodName': util.capitalize(methodName)}
                                                       for methodName in methodNames])

        hidden = False
        mkConnectionMethodRules = []
        outputPipes = []
        for m in self.decls:
            if m.type == 'Method' and m.return_type.name == 'Action':
                paramsForCall = ['request.%s' % p.name for p in m.params]
                msubs = {'methodName': m.name,
                         'MethodName': util.capitalize(m.name),
                         'paramsForCall': ', '.join(paramsForCall)}
                msubs['invokeMethod'] = '' if hidden else 'ifc.%(methodName)s(%(paramsForCall)s);' % msubs
                mkConnectionMethodRules.append(mkConnectionMethodTemplate % msubs)
                outputPipes.append('    interface %(methodName)s_PipeOut = toPipeOut(%(methodName)s_requestFifo);' % msubs)

        subs['mkConnectionMethodRules'] = ''.join(mkConnectionMethodRules)
        subs['outputPipes'] = '\n'.join(outputPipes)
        f.write(exposedWrapperInterfaceTemplate % subs)
        f.write(mkExposedWrapperInterfaceTemplate % subs)
Пример #10
0
def cast_possess(caster):
    if caster.current_possession_cooldown > 0:
        if caster is player:
            ui.message('You need to wait for your possess spell to cool down', rl.BLUE)
        return 'cancelled'
    # ask the player for a target to confuse
    in_fov = util.visible_monsters(caster)

    if len(in_fov) == 0:
        #if caster is player:
        ui.message('No monster in sight to possess.', rl.BLUE)
        return 'cancelled'
    elif len(in_fov) == 1:
        monster = in_fov[0]
        if monster.name == 'nuphrindas':
            if caster is player:
                ui.message('Nuphrindas is too powerfull to be possessed.', rl.YELLOW)
            return 'cancelled'
        monster.push_controller(caster.pop_controller())
        monster.target = None
        monster.flee = None
        monster.master = None
        caster.push_controller(controllers.ParalyzedMonster(3))
        if caster is player:
            if monster.name == 'original body':
                ui.message('You possess your original body. It feels like home.', rl.GREEN)
            else:
                ui.message('You possess ' + monster.get_name(), rl.GREEN)
            builtins.player, old_monster = monster, player
            value = rl.random()
            if value < .2:
                old_monster.hp = 0
                old_monster.die()
            elif value < .4:
                old_monster.take_damage(old_monster.hp // 3)
                if caster is old_monster or player.can_see(old_monster):
                    ui.message(util.capitalize(old_monster.get_name('get{s} hurt and turn{s}')) + ' against ' + monster.get_name() + '.', rl.ORANGE)
            else:
                old_monster.master = player
                if caster is old_monster or player.can_see(old_monster):
                    ui.message(util.capitalize(old_monster.get_name('{is} subdued and start{s} helping')) + ' ' + monster.get_name() + '.', rl.ORANGE)

            level.compute_fov()
        monster.current_possession_cooldown = monster.possession_cooldown
    elif caster is player:
        ui.message('You need to be alone with a monster to possess it.', rl.BLUE)
    return 'cancelled'
Пример #11
0
def fireball_effect(monster):
    if monster.alive and 'immune_fire' not in monster.skills:
        if monster is player or player.can_see(monster):
            ui.message(
                util.capitalize(monster.get_name('{is}')) + ' burning.',
                rl.RED)
        monster.take_damage(const.FIREBALL_DAMAGE)
        return False
    return True
Пример #12
0
def water_effect(monster):
    if monster.alive and len(
            set(['can_fly', 'can_swim']) & set(monster.skills)) == 0:
        if monster is player or player.can_see(monster):
            ui.message(
                util.capitalize(monster.get_name('{is}')) + ' drowning.',
                rl.RED)
        monster.take_damage(max(1, monster.max_hp // 3))
        return False
    return True
Пример #13
0
def cast_fireball(caster, x=None, y=None):
    def effect(caster, x, y):
        for i in range(x - const.FIREBALL_RADIUS, x + const.FIREBALL_RADIUS + 1):
            for j in range(y - const.FIREBALL_RADIUS, y + const.FIREBALL_RADIUS + 1):
                distance = math.sqrt((x - i) ** 2 + (y - j) ** 2)
                if distance < const.FIREBALL_RADIUS and level.blocked[i, j] == 0:
                    level.objects.append(actors.Monster(i, j, graphics.FIREBALL, 'fireball', rl.RED, z=3, blocks=False, max_hp=5, controllers=[controllers.SpellEffect(3, environments.fireball_effect)]))
    return cast_at_location({
        'name': 'fireball',
        'result': util.capitalize(caster.get_name('cast{s}')) + 'a fireball spell. The fireball explodes, burning everything within ' + str(const.FIREBALL_RADIUS) + ' tiles!',
        }, caster, const.FIREBALL_RANGE, effect, x, y)
Пример #14
0
 def control(self, monster):
     if self.num_turns > 0:
         self.num_turns -= 1
         monster.move_away_from(self.flee.x, self.flee.y)
     else:
         monster.pop_controller()
         if player.can_see(monster) or player is monster:
             ui.message(
                 util.capitalize(monster.get_name('{is}')) +
                 ' not frightened anymore.', rl.ORANGE)
         monster.controller.control(monster)
Пример #15
0
 def control(self, monster):
     if self.num_turns > 0:
         self.num_turns -= 1
         monster.wait()
     else:
         monster.pop_controller()
         if player.can_see(monster) or player is monster:
             ui.message(
                 util.capitalize(monster.get_name('start{s}')) +
                 ' moving again', rl.ORANGE)
         monster.controller.control(monster)
Пример #16
0
    def substs(self,suffix,expose,proxy):
        name = "%s%s"%(self.name,suffix)
        dutName = util.decapitalize(name)
        methods = [d for d in self.decls if d.type == 'Method' and d.return_type.name == 'Action']

        # specific to wrappers
        requestElements = self.collectRequestElements(name)
        methodNames = self.collectMethodNames(name)
        methodRuleNames = self.collectMethodRuleNames(name)
        methodRules = self.collectMethodRules(name,not expose)
        
        # specific to proxies
        responseElements = self.collectResponseElements(name)
        indicationMethodRuleNames = self.collectIndicationMethodRuleNames(name)
        indicationMethodRules = self.collectIndicationMethodRules(name)
        indicationMethods = self.collectIndicationMethods(name)
        indicationMethodDecls = self.collectIndicationMethodDecls(name)

        m = md5.new()
        m.update(self.name)

        substs = {
            'Ifc': self.name,
            'dut': dutName,
            'Dut': util.capitalize(name),
            'requestElements': ''.join(requestElements),
            'methodNames': methodNames,
            'methodRules': ''.join(methodRules),
            'requestFailureRuleNames': "" if len(methodNames) == 0 else '(* descending_urgency = "'+', '.join(['handle_%s_requestFailure' % n for n in methodNames])+'"*)',
            'channelCount': self.channelCount,
            'writeChannelCount': self.channelCount,
            'hiddenProxy' : "%sStatus" % name,
            'moduleContext': '',

            'requestChannelCount': len(methodRules) if not proxy else 0,
            'responseElements': ''.join(responseElements),
            'indicationMethodRules': ''.join(indicationMethodRules),
            'indicationMethods': ''.join(indicationMethods),
            'indicationMethodDecls' :''.join(indicationMethodDecls),
            'indicationChannelCount': self.channelCount if proxy else 0,
            'indicationInterfaces': ''.join(indicationTemplate % { 'Indication': name }) if not self.hasSource else '',
            'hiddenWrapper' : "%sStatus" % name,
            'startIndicationMethods' : '' if not expose else '    interface %s ifc;' % self.name,
            'endIndicationMethods' : '' if not expose else '    endinterface',
            'slaveFifoSelExposed' : '1' if proxy else '0',
            'slaveFifoSelHidden'  : '0' if proxy else '1',
            }

        substs['portalIfcInterrupt'] = 'interface ReadOnly interrupt = p.interrupt;' if not proxy else proxyInterruptImplTemplate
        substs['ifcType'] = 'truncate(128\'h%s)' % m.hexdigest()
        substs['portalIfc'] = portalIfcTemplate % substs
        substs['wrapperCtrl'] = wrapperCtrlTemplate % substs
        substs['proxyCtrl'] = proxyCtrlTemplate % substs
        return substs
Пример #17
0
    def OnSuggest(self, event):
        if not self.sc.word:
            return

        isAllCaps = self.sc.word == util.upper(self.sc.word)
        isCapitalized = self.sc.word[:1] == util.upper(self.sc.word[:1])

        word = util.lower(self.sc.word)

        wl = len(word)
        wstart = word[:2]
        d = 500
        fifo = util.FIFO(5)
        wx.BeginBusyCursor()

        for w in spellcheck.prefixDict[util.getWordPrefix(word)]:
            if w.startswith(wstart):
                d = self.tryWord(word, wl, w, d, fifo)

        for w in self.gScDict.words.iterkeys():
            if w.startswith(wstart):
                d = self.tryWord(word, wl, w, d, fifo)

        for w in self.ctrl.sp.scDict.words.iterkeys():
            if w.startswith(wstart):
                d = self.tryWord(word, wl, w, d, fifo)

        items = fifo.get()

        wx.EndBusyCursor()

        if len(items) == 0:
            wx.MessageBox("No similar words found.", "Results",
                          wx.OK, self)

            return

        dlg = wx.SingleChoiceDialog(
            self, "Most similar words:", "Suggestions", items)

        if dlg.ShowModal() == wx.ID_OK:
            sel = dlg.GetSelection()

            newWord = items[sel]

            if isAllCaps:
                newWord = util.upper(newWord)
            elif isCapitalized:
                newWord = util.capitalize(newWord)

            self.replaceEntry.SetValue(newWord)

        dlg.Destroy()
Пример #18
0
    def control(self, monster):
        if self.num_turns > 0:  # still confused...
            # move in a random direction, and decrease the number of turns confused
            self.num_turns -= 1
            monster.move(rl.random_int(-1, 1), rl.random_int(-1, 1))

        else:  # restore the previous AI (this one will be deleted because it's not referenced anymore)
            monster.pop_controller()
            ui.message(
                util.capitalize(monster.get_name('{is}')) +
                ' no longer confused!', rl.RED)
            monster.controller.control(monster)
Пример #19
0
def cast_fear(caster):
    # find closest enemy (inside a maximum range) and damage it
    monster = util.closest_hostile(caster, const.FEAR_RANGE)
    if monster is None:  # no enemy found within maximum range
        if caster is player:
            ui.message('No enemy is close enough to strike.', rl.RED)
        return 'cancelled'
 
    # zap it!
    if caster is player or monster is player:
        ui.message(util.capitalize(caster.get_name('frighten{s}')) + ' ' + monster.get_name() + '. ' + util.capitalize(monster.get_name('flee{s}')) + '.', rl.BLUE)
    if type(monster.controller) is controllers.FrightenedMonster:
            monster.pop_controller()
    monster.push_controller(controllers.FrightenedMonster(caster, const.FEAR_DURATION))
Пример #20
0
 def summon_monster(name):
     print(name)
     x, y = 0, 0
     i = 0
     while i < 100:
         angle = rl.random_int(0, 359)
         distance = rl.random_int(2, 4)
         x = int(caster.x + .5 + math.cos(math.pi * angle / 180) * distance)
         y = int(caster.y + .5 + math.sin(math.pi * angle / 180) * distance)
         print(x, y)
         if not level.is_blocked(x, y) and caster.can_see_tile(x, y):
             break
         i += 1
     if i == 100:
         if caster is player:
             ui.message('You fail to cast the summon spell.', rl.BLUE)
     monster = monsters.make_monster(name, x, y)
     if not hostile:
         monster.master = caster
     level.objects.append(monster)
     if caster is player or player.can_see(caster) or player.can_see(monster):
         ui.message(util.capitalize(caster.get_name('summon{s}')) + ' ' + monster.get_name(determiner='a') + '.', rl.BLUE)
Пример #21
0
    def die(self):
        if self is player:
            ui.message('You died! Press ESCAPE to continue.', rl.RED)
            game.state = 'dead'
            self.tile = graphics.TOMB2
            #save_game()
        else:
            if player.can_see(self):
                ui.message(
                    util.capitalize(self.get_name('{is}')) + ' dead!',
                    rl.ORANGE)
            self.tile = graphics.CORPSE
        self.color = rl.RED
        self.blocks = False
        self.controllers = []
        self.name = 'remains of ' + self.name
        self.skills = [x for x in self.skills if x != 'invisible']
        self.master = self.target = self.flee = None
        self.z = -1

        if 'boss' in self.skills:
            # show dead boss and trigger ending
            game.push_scene(scenes.Ending())
Пример #22
0
    def substs(self, suffix, proxy):
        name = "%s%s" % (self.name, suffix)
        dutName = util.decapitalize(name)

        # specific to wrappers
        requestElements = self.collectRequestElements(name)
        methodNames = self.collectMethodNames(name)
        methodRules = self.collectMethodRules(name, False)

        # specific to proxies
        responseElements = self.collectResponseElements(name)
        indicationMethodRules = self.collectIndicationMethodRules(name)
        indicationMethods = self.collectIndicationMethods(name)

        m = md5.new()
        m.update(self.name)

        substs = {
            'Ifc':
            self.name,
            'dut':
            dutName,
            'Dut':
            util.capitalize(name),
            'requestElements':
            ''.join(requestElements),
            'methodNames':
            methodNames,
            'methodRules':
            ''.join(methodRules),
            'channelCount':
            self.channelCount,
            'moduleContext':
            '',
            'requestChannelCount':
            len(methodRules) if not proxy else 0,
            'responseElements':
            ''.join(responseElements),
            'indicationMethodRules':
            ''.join(indicationMethodRules),
            'indicationMethods':
            ''.join(indicationMethods),
            'indicationChannelCount':
            self.channelCount if proxy else 0,
            'indicationInterfaces':
            ''.join(indicationTemplate %
                    {'Indication': name}) if not self.hasSource else '',
        }

        substs['ifcType'] = 'truncate(128\'h%s)' % m.hexdigest()
        substs['portalIfc'] = portalIfcTemplate % substs
        substs['requestOutputPipeInterfaces'] = ''.join([
            requestOutputPipeInterfaceTemplate % {
                'methodName': methodName,
                'MethodName': util.capitalize(methodName)
            } for methodName in methodNames
        ])
        mkConnectionMethodRules = []
        outputPipes = []
        for m in self.decls:
            if m.type == 'Method' and m.return_type.name == 'Action':
                paramsForCall = ['request.%s' % p.name for p in m.params]
                msubs = {
                    'methodName': m.name,
                    'paramsForCall': ', '.join(paramsForCall)
                }
                mkConnectionMethodRules.append(mkConnectionMethodTemplate %
                                               msubs)
                outputPipes.append(
                    '    interface %(methodName)s_PipeOut = toPipeOut(%(methodName)s_requestFifo);'
                    % msubs)
        substs['mkConnectionMethodRules'] = ''.join(mkConnectionMethodRules)
        substs['outputPipes'] = '\n'.join(outputPipes)
        return substs
Пример #23
0
 def effect(caster, target):
     if type(target.controller) is controllers.ConfusedMonster:
         target.pop_controller()
     target.push_controller(controllers.ConfusedMonster())
     if target is player or player.can_see(target): 
         ui.message(util.capitalize(target.get_name()) + ' is confused. ' + util.capitalize(target.get_pronoun('start{s}')) + ' to stumble around!', rl.BLUE)