def select(self): self.set_result(rog.monat(rog.mapx(self.x), rog.mapy(self.y)))
def stateless(bot): ''' Dumb temporary NPC controller function implementing a simple 8-directional desire system ''' world = rog.world() desires = Desires(wander=7) sight = rog.getms(bot, "sight") pos = world.component_for_entity(bot, cmp.Position) botCreature = world.component_for_entity(bot, cmp.Creature) ## botType=world.component_for_entity(bot, cmp.Draw).char #should not depend on draw component # Where should this go???? ## rog.run_fov_manager(bot) # moved to can_see # TODO: write this function def isFoe(myFaction, theirFaction): return True # TODO: re-implement listening # listen to events '''lis=rog.listen(bot) if lis: for ev in lis: if rog.can_see(bot,ev.x,ev.y): continue # hearing if not ev.volume: continue if rog.can_hear(bot, ev.x,ev.y, ev.volume): interest=5 _add_desire_direction( desires, bot.x,bot.y, ev.x,ev.y, interest) rog.clear_listen_events(bot)''' # iterate through each tile in sight and see what is there... # is there a better way to do this? # This code is a little slow. for x in range(pos.x - sight, pos.x + sight + 1): for y in range(pos.y - sight, pos.y + sight + 1): if (not rog.is_in_grid(x, y) # out of bounds or (x == pos.x and y == pos.y)): # ignore self continue if not rog.can_see(bot, x, y, sight): continue # can't see it here = rog.thingat(x, y) if here: isCreature = world.has_component(here, cmp.Creature) # decide what it is and what to do about it if isCreature: creature = world.component_for_entity(here, cmp.Creature) if rog.on(here, DEAD): continue # no interest in dead things interest = 0 #desire to fight if creature.faction == FACT_ROGUE: interest = 1000 #grouping behavior elif creature.faction == botCreature.faction: interest = 5 if (interest > 0): _add_desire_direction(desires, pos.x, pos.y, x, y, interest) elif (interest < 0): _add_fear_direction(desires, pos.x, pos.y, x, y, interest) #if thing is inanimate else: #food desire if hungry #treasure desire pass # pick the direction it wants to move in the most highest = -999 for i in range(3): for j in range(3): new = desires.get(j - 1, i - 1) if new > highest: highest = new coords = ( j - 1, i - 1, ) dx, dy = coords xto = pos.x + dx yto = pos.y + dy # out of bounds if not rog.is_in_grid(xto, yto): return # fight if there is a foe present mon = rog.monat(xto, yto) if (mon and mon is not bot): monFaction = world.component_for_entity(mon, cmp.Creature).faction if isFoe(botCreature.faction, monFaction): action.fight(bot, mon) return # or move elif not rog.solidat(xto, yto): if action.move(bot, dx, dy): return # if no action was done, just wait action.wait(bot)
def commands(pc, pcAct): world = rog.world() for act, arg in pcAct: rog.update_base() # actions that take multiple turns busyTask = rog.occupations(pc) if busyTask: if not rog.occupation_elapse_turn(pc): # interrupted ## rog.Input("") pass #----------------# # convert action # #----------------# if act == 'target': act = directional_command #----------------# # perform action # #----------------# #-----------MOUSE ACTION----------------------------# if act == 'lclick': mousex, mousey, z = arg if rog.wallat(mousex, mousey): return pos = world.component_for_entity(pc, cmp.Position) rog.path_compute(pc.path, pos.x, pos.y, rog.mapx(mousex), rog.mapy(mousey)) #rog.occupation_set(pc,'path') if act == 'rclick': pass #------------OTHER ACTION--------------------------# if act == 'move': dx, dy, dz = arg pos = world.component_for_entity(pc, cmp.Position) actor = world.component_for_entity(pc, cmp.Actor) xto = pos.x + dx yto = pos.y + dy # wait if (xto == pos.x and yto == pos.y): actor.ap = 0 return # out of bounds if (not rog.is_in_grid_x(xto) or not rog.is_in_grid_y(yto)): return # fight if there is a monster present mon = rog.monat(xto, yto) if (mon and mon is not pc): action.fight(pc, mon) # or move elif not rog.solidat(xto, yto): # space is free, so we can move if action.move(pc, dx, dy): rog.view_center_player() if act == "get": action.pickup_pc(pc) return if act == "open": #open or close action.open_pc(pc) return if act == "sprint": #begin sprinting action.sprint_pc(pc) return if act == "throw": #throw an object action.throw_pc(pc) return #unused actions '''if act == "bomb": action.bomb_pc(pc) return''' # # # special actions # # if act == 'find player': #useful to immediately show where the player is pos = world.component_for_entity(pc, cmp.Position) rog.view_center_player() rog.update_game() rog.update_final() rog.update_base() rog.game_update() #call all the updates rog.alert('press any key to continue...') rog.Input(rog.getx(pos.x), rog.gety(pos.y), mode='wait') rog.update_base() rog.alert('') return if act == "look": pos = world.component_for_entity(pc, cmp.Position) rog.routine_look(pos.x, pos.y) return if act == "move view": rog.routine_move_view() return if act == "fixed view": rog.fixedViewMode_toggle() return if act == 'select': # TESTING print(rog.Input(0, 0, 20)) return if act == 'exit': return
def stateless(bot): # desire to move in a particular coordinate desires = Desires(wander=7) # listen to events '''lis=rog.listen(bot) if lis: for ev in lis: if rog.can_see(bot,ev.x,ev.y): continue # hearing if not ev.volume: continue if rog.can_hear(bot, ev.x,ev.y, ev.volume): interest=5 _add_desire_direction( desires, bot.x,bot.y, ev.x,ev.y, interest) rog.clear_listen_events(bot)''' # iterate through each tile in sight and see what is there... # is there a better way to do this? # This code is a little slow. sight = bot.stats.sight for x in range(bot.x - sight, bot.x + sight + 1): for y in range(bot.y - sight, bot.y + sight + 1): if (not rog.is_in_grid(x, y) #out of bounds or (x == bot.x and y == bot.y)): #ignore self continue if not rog.can_see(bot, x, y): continue #bot can't see it here = rog.thingat(x, y) if here: # decide what it is and what to do about it if rog.is_creature(here): if rog.on(here, DEAD): continue #no interest in dead things interest = 0 #desire to fight if here.faction == FACT_ROGUE: interest = 1000 #desire to run away #elif here.type == '@': # interest=-1000 #grouping behavior elif here.type == bot.type: interest = 5 if (interest > 0): _add_desire_direction(desires, bot.x, bot.y, x, y, interest) elif (interest < 0): _add_fear_direction(desires, bot.x, bot.y, x, y, interest) #if thing is inanimate else: #food desire if hungry #treasure desire pass # pick the direction it wants to move in the most highest = -999 for i in range(3): for j in range(3): new = desires.get(j - 1, i - 1) if new > highest: highest = new coords = ( j - 1, i - 1, ) dx, dy = coords xto = bot.x + dx yto = bot.y + dy # out of bounds if not rog.is_in_grid(xto, yto): return # fight if there is a monster present mon = rog.monat(xto, yto) if (mon and mon is not bot): if not mon.type == bot.type: ##TEMPORARY action.fight(bot, mon) return # or move elif not rog.solidat(xto, yto): if action.move(bot, dx, dy): return # if no action was done, just wait action.wait(bot)
def commands(pc, pcAct): world = rog.world() directional_command = 'move' for act,arg in pcAct: ## print(act) ## print(arg) rog.update_base() #----------------# # convert action # #----------------# if act =='context-dir': act=directional_command ## if act =='context': ## pass # moving using the menu move keys if (act =='menu-nav' and rog.game_state()=="normal"): act=directional_command #----------------# # perform action # #----------------# #-----------MOUSE ACTION----------------------------# if act == 'lclick': mousex,mousey,z=arg if rog.wallat(mousex,mousey): return pos = world.component_for_entity(pc, cmp.Position) print("Left click unimplemented") ## rog.path_compute(pc.path, pos.x,pos.y, rog.mapx(mousex), rog.mapy(mousey)) #rog.occupation_set(pc,'path') if act == 'rclick': pass #------------OTHER ACTION--------------------------# if act == 'help': rog.help() # "move-prompt" : True # prompt for a direction # and then perform the move action in that direction if act == 'move-prompt': pass # "attack-prompt" : True # prompt for a direction # and then perform the attack action in that direction if act == 'attack-prompt': pass # "move" : (x_change, y_change, z_change,) if act == 'move': _Update() dx,dy,dz=arg pos = world.component_for_entity(pc, cmp.Position) actor = world.component_for_entity(pc, cmp.Actor) xto=pos.x + dx yto=pos.y + dy # wait if (xto==pos.x and yto==pos.y): actor.ap = 0 return # out of bounds if ( not rog.is_in_grid_x(xto) or not rog.is_in_grid_y(yto) ): return # warning for slow move speed if rog.allow_warning_msp(): msp=rog.getms(pc, 'msp') if msp <= 10: inp=rog.prompt( 0,0,rog.window_w(), 6, mode='wait', q='''Warning: your movement speed is critically slow (MSP: {}). Are you sure you want to move? y/n'''.format(msp) ) if inp!='y': return else: rog.expire_warning_msp() #TODO: when is best time to reset this warning? # end if # choose context-sensitive action # # fight if there is a monster present mon = rog.monat(xto,yto) if mon: # and mon != pc): action.fight(pc,mon) # or move elif not rog.solidat(xto,yto): # space is free, so we can move if action.move(pc, dx,dy): rog.view_center_player() else: rog.alert("That space is occupied.") # end conditional # "attack" : (x, y, z,) if act == 'attack': _Update() xto,yto,zto=arg pos = world.component_for_entity(pc, cmp.Position) actor = world.component_for_entity(pc, cmp.Actor) # out of bounds if ( not rog.is_in_grid_x(xto) or not rog.is_in_grid_y(yto) ): return # fight if there is a monster present mon = rog.monat(xto,yto) # ... but don't attack yourself! if mon == pc: rog.alert("You can't fight yourself!") return if mon: action.fight(pc,mon) else: ent = rog.thingat(xto,yto) if ent: action.fight(pc,ent) else: rog.msg("You strike out at thin air, losing your balance.") actor.ap = 0 rog.set_status( pc, cmp.StatusOffBalance, t=2, q=-MISS_BAL_PENALTY ) # end conditional # chat with closest speaking entity; # if multiple good options, prompt for which one. if act == "chat-context": action.chat_context(pc) _Update() return if act == "change-pos": # change body position action.change_bodypos_pc(pc) _Update() return if act == "change-msp": # change speed of movement (walking, running, jogging, etc.) action.change_speed_pc(pc) _Update() return if act == "msp-up": # change from walk to powerwalk, to trot, jog, etc. action.speed_up_pc(pc) _Update() return if act == "msp-down": # change from sprint to run, to jog, to trot, etc. action.slow_down_pc(pc) _Update() return if act == "target-prompt": #target entity + fire / throw / attack action.target_pc_generic(pc) _Update() return if act == "get-prompt": action.pickup_pc(pc) _Update() return if act == "openclose-prompt": #open or close action.open_pc(pc) _Update() return if act == "open-prompt": #open or close action.open_pc(pc) _Update() return if act == "close-prompt": #open or close action.open_pc(pc) _Update() return if act == "jog": #begin jogging action.jog_pc(pc) _Update() return if act == "run": #begin running action.run_pc(pc) _Update() return if act == "sprint": #begin sprinting action.sprint_pc(pc) _Update() return #unused actions '''if act == "bomb": action.bomb_pc(pc) return''' # # # special actions # # if act == 'find player': #useful to immediately show where the player is pos = world.component_for_entity(pc, cmp.Position) rog.view_center_player() rog.update_game() rog.update_final() rog.game_update() #call all the updates rog.alert('press any key to continue...') rog.Input(rog.getx(pos.x), rog.gety(pos.y), mode='wait') rog.update_base() rog.alert('') return if act == "look": pos = world.component_for_entity(pc, cmp.Position) rog.routine_look(pos.x,pos.y) return if act == "move view": rog.routine_move_view() return if act == "fixed view": rog.fixedViewMode_toggle() return if act == 'select': # TESTING print(rog.Input(0,0,20)) return if act == 'exit': return