Esempio n. 1
0
def burn(obj, dmg, maxTemp):
    #get obj resistance
    res = obj.stats.resfire
    if rog.on(obj, WET):
        rog.clear_status(obj, WET)  #wet things get dried
        #steam=stuff.create("steam", obj.x, obj.y)
    #increase temperature
    dmg = int(dmg * (1 - (res / 100)))
    obj.stats.temp += max(0, dmg)
    obj.stats.temp = min(maxTemp, obj.stats.temp)
    #set burning status
    if (not rog.on(obj, FIRE)
            and obj.stats.temp >= FIRE_TEMP):  #should depend on material?
        rog.set_status(obj, FIRE)
Esempio n. 2
0
 def _draw_what_player_sees(self, pc):
     world=rog.world()
     seer=world.component_for_entity(pc, cmp.SenseSight)
     rang=seer.sight
     pos=world.component_for_entity(pc, cmp.Position)
     rend=world.component_for_entity(ent, cmp.Draw)
     for     x in range( max(0, pc.x-rang), min(self.w, pc.x+rang+1) ):
         for y in range( max(0, pc.y-rang), min(self.h, pc.y+rang+1) ):
             canSee=False
             
             if not rog.in_range(pos.x,pos.y, x,y, rang):
                 continue
             if not libtcod.map_is_in_fov(seer.fov_map, x,y):
                 continue
             ent=self.thingat(x, y)
             if (self.get_light_value(x,y) == 0 and not rog.on(pc,NVISION) ):
                 self._draw_silhouettes(pc, x,y, ent)
                 continue
             
             if ent:
                 libtcod.console_put_char(
                     self.con_map_state, x,y,
                     rend.char)
                 libtcod.console_set_char_foreground(
                     self.con_map_state, x,y, rend.color)
                 self._apply_rendered_bgcol(x,y, ent)
             else:
                 libtcod.console_put_char_ex(self.con_map_state, x,y,
                     self.get_char(x, y),
                     self.get_color(x, y), self.get_bgcolor(x, y))
Esempio n. 3
0
    def process(self):
        world = self.world

        # give AP to all actors
        for ent, actor in world.get_component(cmp.Actor):
            if rog.on(ent, DEAD):
                actor.ap = 0
                continue
            spd = max(MIN_SPD, rog.getms(ent, 'spd'))
            actor.ap = min(actor.ap + spd, spd)

        # Action Queues
        for ent, (qa,
                  actor) in self.world.get_components(cmp.DelayedAction,
                                                      cmp.Actor):

            # process interruptions and cancelled / paused jobs
            if qa.interrupted:
                ActionQueue._interrupt(ent, qa)
                continue
            if actor.ap <= 0:
                continue

            # proceed with the job
            # spend as much AP as we can / as we need
            # automatically finishes the job if applicable
            points = min(actor.ap, qa.ap)
            ActionQueue._pay(ent, qa, actor, points)

        # If no Action Queued, then continue with turn as normal #

        # NPC / AI / computer turn
        for ent, (actor, _ai) in world.get_components(cmp.Actor, cmp.AI):
            while actor.ap > 0:
                _ai.func(ent)
Esempio n. 4
0
def inventory_pc(pc,pcInv):
    if not pc.inv:
        rog.alert(ALERT_EMPTYCONTAINER)
        return
    x=0
    y=rog.view_port_y()
#   items menu
    item=rog.menu("{}'s Inventory".format(pc.name), x,y, pcInv.items)
    
#   viewing an item
    if not item == -1:
        keysItems={}
        
    #   get available actions for this item...
        if rog.on(item,CANEAT):
            keysItems.update({"E":"Eat"})
        if rog.on(item,CANQUAFF):
            keysItems.update({"q":"quaff"})
        if rog.on(item,CANEQUIP):
            keysItems.update({"e":"equip"})
        if rog.on(item,CANUSE):
            keysItems.update({"u":"use"})
        if rog.on(item,CANOPEN):
            keysItems.update({"o":"open"})
        keysItems.update({"x":"examine"})
        keysItems.update({"d":"drop"})
        keysItems.update({"t":"throw"})
        #
        
        opt=rog.menu(
            "{}".format(item.name), x,y,
            keysItems, autoItemize=False
        )
        #print(opt)
        if opt == -1: return
        opt=opt.lower()
        
        rmg=False
        if   opt == "drop":     rmg=True; drop_pc(pc,item)
        elif opt == "equip":    rmg=True; equip_pc(pc,item)
        elif opt == "eat":      rmg=True; eat_pc(pc, item)
        elif opt == "quaff":    rmg=True; quaff_pc(pc, item)
        elif opt == "use":      rmg=True; use_pc(pc, item)
        elif opt == "examine":  rmg=True; examine_pc(pc, item)
        
        if rmg: rog.drain(pc, 'nrg', NRG_RUMMAGE)
Esempio n. 5
0
def fight(attkr,dfndr,adv=0):
##    TODO: when you attack, look at your weapon entity to get:
        #-material of weapon
        #-element of weapon
        #-flags of weapon
    world = rog.world()
    cstats = world.component_for_entity(attkr, cmp.CombatStats)
    dpos = world.component_for_entity(dfndr, cmp.Position)
    element = ELEM_PHYS #****TEMPORARY!!!! has_component...
    nrg_cost = round( NRG_ATTACK*AVG_SPD/max(1, cstats.asp) )
    cstats.ap -= nrg_cost

    die=COMBATROLL
    acc=cstats.atk
    dv=cstats.dfn
    hit = False
    rol = dice.roll(die + acc + adv - dv) - dice.roll(die)
    if (rol >= 0): # HIT!!!
        hit = True
        
        #type of damage dealt depends on the element attacker is using
        if element == ELEM_PHYS:
            #high attack values can pierce armor
##            if rol > ATK_BONUS_DMG_CUTOFF:
##                pierce = int( (rol - ATK_BONUS_DMG_CUTOFF)/2 )
##            else:
##                pierce = 0
            armor = dfndr.stats.get('arm') #max(0, dfndr.stats.get('arm') - pierce)
            dmg = max(0, attkr.stats.get('dmg') - armor)
            rog.hurt(dfndr, dmg)
        elif element == ELEM_FIRE:
            rog.burn(dfndr, dmg)
        elif element == ELEM_BIO:
            rog.disease(dfndr, dmg)
        elif element == ELEM_ELEC:
            rog.electrify(dfndr, dmg)
        elif element == ELEM_CHEM:
            rog.exposure(dfndr, dmg)
        elif element == ELEM_RADS:
            rog.irradiate(dfndr, dmg)
        
        killed = rog.on(dfndr,DEAD) #...did we kill it?
    #
    
    message = True
    a=attkr.name; n=dfndr.name; t1=attkr.title; t2=dfndr.title; x='.';
    
    # make a message describing the fight
    if message:
        if hit==False: v="misses"
        elif dmg==0: v="cannot penetrate"; x="'s armor!"
        elif killed: v="defeats"
        else: v="hits"
        rog.event_sight(
            dfndr.x,dfndr.y,
            "{t1}{a} {v} {t2}{n}{x}".format(a=a,v=v,n=n,t1=t1,t2=t2,x=x)
        )
        rog.event_sound(dpos.x,dpos.y, SND_FIGHT)
Esempio n. 6
0
def pickup_pc(pc):
    rog.alert("Pick up what?{d}".format(d=dirStr))
    args=rog.get_direction()
    if not args:
        rog.alert()
        return
    dx,dy,dz=args
    xx,yy=pc.x + dx, pc.y + dy
    
    things=rog.thingsat(xx,yy)
    if pc in things:
        things.remove(pc)

    choice=None
    if len(things) > 1:
        rog.alert("There are multiple things here. Pick up which item?")
        choices = [] #["all",] #should player be able to pickup multiple things at once? Maybe could be a delayed action?
        for thing in things:
            choices.append(thing)
        choice=rog.menu(
            "pick up", rog.view_port_x()+2, rog.view_port_y()+2, choices
            )
    else:
        if things:
            choice=things[0]

    if (choice and not choice == "all"):

        if choice == K_ESCAPE:
            return
        
        #thing is creature! You can't pick up creatures :(
        if choice.isCreature:
            rog.alert("You can't pick that up!")
            return
        #thing is on fire! What are you doing trying to pick it up??
        if rog.on(choice,FIRE):
            answer=""
            while True:
                answer=rog.prompt(0,0,rog.window_w(),1,maxw=1,
                    q="That thing is on fire! Are you sure? y/n",
                    mode='wait',border=None)
                answer=answer.lower()
                if answer == "y" or answer == " " or answer == K_ENTER:
                    rog.alert("You burn your hands!")
                    rog.burn(pc, FIRE_BURN)
                    rog.hurt(pc, FIRE_HURT)
                    break
                elif answer == "n" or answer == K_ESCAPE:
                    return
        # put in inventory
        pocketThing(pc, choice)
    #elif choice == "all":
    #    
    else:
        rog.alert("There is nothing there to pick up.")
Esempio n. 7
0
def fight(attkr,dfndr,adv=0):
    nrg_cost = round( NRG_ATTACK*AVG_SPD/max(1, attkr.stats.get('asp')) )
    attkr.stats.nrg -= nrg_cost

    die=COMBATROLL
    acc=attkr.stats.get('atk')
    dv=dfndr.stats.get('dfn')
    hit = False
    rol = dice.roll(die + acc + adv - dv) - dice.roll(die)
    if (rol >= 0): # HIT!!!
        hit = True
        
        #type of damage dealt depends on the element attacker is using
        if attkr.stats.element == ELEM_PHYS:
            #high attack values can pierce armor
##            if rol > ATK_BONUS_DMG_CUTOFF:
##                pierce = int( (rol - ATK_BONUS_DMG_CUTOFF)/2 )
##            else:
##                pierce = 0
            armor = dfndr.stats.get('arm') #max(0, dfndr.stats.get('arm') - pierce)
            dmg = max(0, attkr.stats.get('dmg') - armor)
            rog.hurt(dfndr, dmg)
        elif attkr.stats.element == ELEM_FIRE:
            rog.burn(dfndr, dmg)
        elif attkr.stats.element == ELEM_BIO:
            rog.disease(dfndr, dmg)
        elif attkr.stats.element == ELEM_ELEC:
            rog.electrify(dfndr, dmg)
        elif attkr.stats.element == ELEM_CHEM:
            rog.exposure(dfndr, dmg)
        elif attkr.stats.element == ELEM_RADS:
            rog.irradiate(dfndr, dmg)
        
        killed = rog.on(dfndr,DEAD) #...did we kill it?
    #
    
    message = True
    a=attkr.name; n=dfndr.name; t1=attkr.title; t2=dfndr.title; x='.';
    
    # make a message describing the fight
    if message:
        if hit==False: v="misses"
        elif dmg==0: v="cannot penetrate"; x="'s armor!"
        elif killed: v="defeats"
        else: v="hits"
        rog.event_sight(
            dfndr.x,dfndr.y,
            "{t1}{a} {v} {t2}{n}{x}".format(a=a,v=v,n=n,t1=t1,t2=t2,x=x)
        )
        rog.event_sound(dfndr.x,dfndr.y, SND_FIGHT)
Esempio n. 8
0
def explosion(bomb):
    con=libtcod.console_new(ROOMW, ROOMH)
    rog.msg("{t}{n} explodes!".format(t=bomb.title, n=bomb.name))
    fov=rog.fov_init()
    libtcod.map_compute_fov(
        fov, bomb.x,bomb.y, bomb.r,
        light_walls = True, algo=libtcod.FOV_RESTRICTIVE)
    
    for x in range(bomb.r*2 + 1):
        for y in range(bomb.r*2 + 1):
            xx=x + bomb.x - bomb.r
            yy=y + bomb.y - bomb.r
            if not libtcod.map_is_in_fov(fov, xx,yy):
                continue
            if not rog.is_in_grid(xx,yy): continue
            dist=maths.dist(bomb.x,bomb.y, xx,yy)
            if dist > bomb.r: continue
            
            thing=rog.thingat(xx, yy)
            if thing:
                if rog.on(thing,DEAD): continue
                
                if thing.isCreature:
                    decay=bomb.dmg/bomb.r
                    dmg= bomb.dmg - round(dist*decay) - thing.stats.get('arm')
                    rog.hurt(thing, dmg)
                    if dmg==0: hitName="not damaged"
                    elif rog.on(thing,DEAD): hitName="killed"
                    else: hitName="hit"
                    rog.msg("{t}{n} is {h} by the blast.".format(
                        t=thing.title,n=thing.name,h=hitName) )
                else:
                    # explode any bombs caught in the blast
                    if (thing is not bomb
                            and hasattr(thing,'explode')
                            and dist <= bomb.r/2 ):
                        thing.timer=0
Esempio n. 9
0
def towel_pc(pc, item):
    options={}
    options.update({"W" : "wrap around"})
    options.update({"l" : "lie"})
    options.update({"s" : "sail"})
    options.update({"w" : "wield"})
    options.update({"h" : "wear on head"})
    options.update({"x" : "wave"})
    options.update({"d" : "dry"})
    choice=rog.menu("use towel",0,0,options,autoItemize=False)
    if choice == "wear on head":
        pass
    elif choice == "wrap around":
        dirTo=rog.get_direction()
        if not args: return
        dx,dy,dz=args
        xto = pc.x + dx; yto = pc.y + dy;

        if (dx==0 and dy==0 and dz==0):
            pass #wrap around self
        
    elif choice == "wield":
        if rog.on(item, WET):
            pass #equip it
        else:
            rog.alert("You can't wield a towel that isn't wet!")
            
    elif choice == "dry":
        #itSeemsCleanEnough=...
        if ( itSeemsCleanEnough and not rog.on(item, WET) ):
            pass #dry self
        else:
            if not itSeemsCleanEnough:
                rog.alert("It doesn't seem clean enough.")
            elif rog.on(item, WET):
                rog.alert("It's too wet.")
    def _tick(self, obj, status, time):
        if status == SICK:
            pass
        
        elif status == SPRINT:
            pass #chance to trip while sprinting
##            if dice.roll(100) < SPRINT_TRIP_CHANCE:
##                rog.knockdown(obj)
        
        elif status == FIRE:
            if obj.stats.get('temp') < FIRE_TEMP: #cooled down too much to keep burning
                self.remove(obj, status)
                print("removing fire due to low temp for {} at {},{}".format(obj.name,obj.x,obj.y))
                return
            #damage is based on temperature of the object
            dmg = max( 1, int(obj.stats.get('temp') / 100) )
            rog.hurt(obj, dmg)
            #create a fire at the location of burning things
            if rog.on(obj,ONGRID):
                rog.set_fire(obj.x,obj.y)
            
        elif status == ACID:
            #damage is based on time remaining, more time = more dmg
            dmg = max( 1, dice.roll(2) - 2 + math.ceil(math.sqrt(time-1)) )
            rog.hurt(obj, dmg)
            
        elif status == IRRIT:
            pass
        
        elif status == PARAL:
            if dice.roll(20) <= PARAL_ROLLSAVE:
                self.remove(obj, status)
                
        elif status == COUGH:
            pass #chance to stop in a coughing fit (waste your turn)
##            if dice.roll(20) <= COUGH_CHANCE:
##                rog.queue_action(obj, action.cough)
        
        elif status == VOMIT:
            pass #chance to stop in a vomiting fit (waste your turn)
##            if dice.roll(20) <= VOMIT_CHANCE:
##                rog.queue_action(obj, action.cough)
        
        elif status == BLIND:
            pass
        
        elif status == DEAF:
            pass
    def run(self):
        super(Manager_Meters, self).run()

        for thing in rog.list_things():
            #print(thing.name," is getting cooled down") #TESTING
            # cool down temperature meter if not currently burning
            if (thing.stats.temp > 0 and not rog.on(thing,FIRE)):
                thing.stats.temp = max(0, thing.stats.temp - FIRE_METERLOSS)
            #warm up
            if (thing.stats.temp < 0):
                thing.stats.temp = min(0, thing.stats.temp + FIRE_METERGAIN)
            # sickness meter
            if (thing.stats.sick > 0):
                thing.stats.sick = max(0, thing.stats.sick - BIO_METERLOSS)
            # exposure meter
            if (thing.stats.expo > 0):
                thing.stats.expo = max(0, thing.stats.expo - CHEM_METERLOSS)
Esempio n. 12
0
def play(pc, pcAct):
    #timer.reset() #DEBUG TESTING. USED WITH timer.print()

    rog.release_souls()
    rog.compute_fovs()

    #-------------------#
    #   NPC turn        #
    #-------------------#

    if pc.stats.nrg <= 0:

        #beginning of turn is considered when the monsters begin their turns
        #   /right after player turn.
        rog.managers_beginturn_run()

        for mon in rog.list_creatures():
            if rog.on(mon, DEAD): continue

            ai.tick(mon)  # AI function
            monspd = mon.stats.get('spd')
            rog.gain(mon, 'nrg', monspd, Max=monspd)  # give action points

        rog.turn_pass()
        #end of turn is considered to be right before player does his turn
        rog.managers_endturn_run()
        return


#-------------------#
#   player turn     #
#-------------------#

    rog.pc_listen_sights()
    rog.pc_listen_sounds()
    rog.clear_listeners()

    rog.game_update()
    #timer.print() #DEBUG TESTING. SHOWS TIME ELAPSED SINCE RESET.

    player.commands(pc, pcAct)
    player.commands_pages(pc, pcAct)
Esempio n. 13
0
def main():
    
#------------------------------------------------#
    # INIT
#------------------------------------------------#

    # new way to init
    rog.Rogue.create_settings() # later controllers might depend on settings
    rog.Rogue.create_window()
    rog.Rogue.create_consoles()
    rog.Rogue.create_world()
    rog.Rogue.create_controller()
    rog.Rogue.create_data()
    rog.Rogue.create_map()
    rog.Rogue.create_clock()
    rog.Rogue.create_updater()
    rog.Rogue.create_view()
    rog.Rogue.create_log()
    rog.Rogue.create_savedGame()
    rog.Rogue.create_processors()
    rog.Rogue.create_perturn_managers()
    rog.Rogue.create_const_managers()
    rog.Rogue.create_player(0,0) # what position should be given?
    
    rog.init_keyBindings()
        
##    #map generation
##    rog.map_generate(rog.map(),rog.dlvl())
##
##    # init player object
##    pc=rog.create_player(15,15)
##    # TODO: observer for player
####    obs=observer.Observer_playerChange()
####    pc.observer_add(obs)
##    rog.view_center(pc)
##    
##    
##    ##TESTING
##    rog.gain(pc,"hpmax",100)
##    log=rog.create_stuff(THG.LOG, 18,18)
##    rog.burn(log,200)
##    box=rog.create_stuff(THG.BOX,20,18)
##    #fluids.smoke(16,16)
##    '''pc.stats.hpmax      = 20
##    pc.stats.mpmax      = 20
##    pc.stats.sight      = 20
##    pc.stats.spd        = 100
##    pc.stats.nvision    = False'''
##        #LIGHT
##    pc.light=rog.create_light(pc.x,pc.y, 5, owner=pc)
##        #HEAL
##    rog.givehp(pc)
##    rog.givemp(pc)
##        #EQUIP
##    #print(pc.stats.get('atk'))
##    item=gear.create_weapon("sword",pc.x,pc.y)
##    rog.equip(pc, item, EQ_MAINHAND)
##    #print(pc.stats.get('atk'))
##    #rog.deequip(pc,EQ_MAINHAND)
##    #print(pc.stats.get('atk'))
##        #BUFF
##    #rog.effect_add(pc,{'atk':5})
##    #rog.effect_add(pc,{'dmg':5})
##    #rog.effect_add(pc,{'arm':0})
##    #rog.effect_add(pc,{'msp':15})
##    #rog.effect_add(pc,{'msp':-50})'''
##    '''
##    z = rog.create_monster('Z',15,16)
##    rog.effect_add(z,{'arm':1})
##    rog.effect_add(z,{'dfn':4})
##    rog.effect_add(z,{'atk':3})
##    rog.effect_add(z,{'dmg':3})
##    rog.givehp(z)'''
##    z=rog.create_monster('z',13,19,COL['ltblue'])
##    a=rog.create_monster('a',12,13,COL['scarlet'])
##    o=rog.create_monster('U',19,18,COL['red'])
##    a=rog.create_monster('a',15,17,COL['scarlet'])
##    W=rog.create_monster('W',20,15,COL['purple'])
##    '''import dice
##    for x in range(ROOMW):
##        for y in range(ROOMH):
##            if dice.roll(100) > 98:
##                if not (rog.wallat(x,y)
##                        or rog.monat(x,y) ):
##                    r=rog.create_monster('r',x,y)
##                    r.color=COL['ltgray']
##    print("num monsters: ", len(rog.list_creatures()))
##    '''
    
        

    
#-----------------------------------------------#
#               # MAIN GAME LOOP #              #
#-----------------------------------------------#

    rog.game_set_state("normal")

##    # initialize fov for creatures with sight
##    # IS THIS NOT WORKING???? WHAT'S GOING ON?
##    for creat in rog.list_creatures():
##        if creat.stats.sight > 0:
##            rog.fov_compute(creat)
    
    while rog.game_is_running():

        # manually close game #
        if libtcod.console_is_window_closed():
            rog.end()
        
        # defeat conditions #
        if rog.on(pc, DEAD):
            rog.game_set_state("game over")
        
        # get input #
        pcInput=IO.get_raw_input()
        pcAct=IO.handle_mousekeys(pcInput).items()
        
        # commands that are available from anywhere #
        player.commands_const(pc, pcAct)
        
        # Finally record game state after any/all changes #
        gameState=rog.game_state()
        
        
                        #----------#
                        #   PLAY   #
                        #----------#
                
        #
        # normal game play
        #
        if gameState == "normal":
            game.play(pc, pcAct)
        #
        # other game states #
        #
        elif (gameState == "move view"
                or gameState == "look"
                or gameState == "busy"
                or gameState == "message history"
                ):
            manager=rog.get_active_manager()
            manager.run(pcAct)
            if manager.result:
                rog.close_active_manager()
        #
        
        elif gameState == "game over":
            rog.msg("You died...")
Esempio n. 14
0
 def solidat(self,x,y):    # get solid thing in tile i.e. things that cannot be moved through... only 1 allowed per tile
     ent = self.thingat(x,y)
     if not ent: return None
     return ent if rog.on(ent, ISSOLID) else None
Esempio n. 15
0
def main():

    #------------------------------------------------#
    # INIT
    #------------------------------------------------#

    rog.Rogue.create_settings()  # later controllers may depend on settings
    rog.Rogue.create_window()
    rog.Rogue.create_consoles()
    rog.Rogue.create_world()
    rog.Rogue.create_controller()
    rog.Rogue.create_data()
    rog.Rogue.create_map(ROOMW, ROOMH)
    ##    rog.Rogue.create_fov_maps()
    rog.Rogue.create_clock()
    rog.Rogue.create_updater()
    rog.Rogue.create_view()
    rog.Rogue.create_log()
    rog.Rogue.create_savedGame()  # TODO: learn/use Pickle.
    rog.Rogue.create_processors()
    rog.Rogue.create_perturn_managers()
    rog.Rogue.create_const_managers()
    rog.Rogue.create_const_entities()

    rog.init_keyBindings()

    #map generation
    rog.getmap(rog.dlvl()).init_specialGrids(
    )  # inits fov_map; do this before you init terrain
    rog.getmap(rog.dlvl()).init_terrain(WALL)  # clear the map to all walls
    rog.getmap(rog.dlvl()).generate_dlvl(rog.dlvl())

    # init player

    # TESTING THIS IS ALL TEMPORARY!!!
    # temporary: find a position to place the player
    xpos = 15
    ypos = 15
    _borders = 10
    while rog.getmap(rog.dlvl()).tileat(xpos, ypos) == WALL:
        xpos += 1
        if xpos >= ROOMW - _borders:
            xpos = _borders
            ypos += 1
        if ypos >= ROOMH:
            print("~~ ! FATAL ERROR ! Failed to place player in the map!")
            break

    rog.Rogue.create_player(xpos, ypos)  # create player
    pc = rog.pc()

    # TESTING
    # HELP THE PLAYER TO SEE
    rog.create_envlight(16)
    ##    rog.make(rog.pc(), NVISION)
    #

    w = rog.create_monster('W', xpos, ypos - 1)
    ##    rog.world().add_component(w, cmp.AttractedToMen())
    ##    rog.world().add_component(w, cmp.AttractedToWomen())
    ##
    ##     #testing speech
    ##    rog.init_person(w)
    #
    ##    w2=rog.create_monster('W',xpos,ypos+1)
    ##    w3=rog.create_monster('W',xpos,ypos+2)

    ##    rog.setskill(pc, SKL_BOXING, 100)
    ##    rog.setskill(pc, SKL_PERSUASION, 0)
    ##    rog.setskill(pc, SKL_ARMOR, 100)
    ##    rog.sets(pc, 'dex', 12*MULT_STATS)
    ##    rog.sets(pc, 'int', 4*MULT_STATS)
    ##    rog.setskill(pc, SKL_UNARMORED, 40)

    ##    for x in range(20):
    ##        rog.create_monster("L", 1+x*5,1)

    ##    rog.alts(pc, 'sight', 50)
    weap = rog.create_weapon("sword", xpos, ypos, mat=MAT_METAL)
    weap = rog.create_weapon("buckler", xpos, ypos, mat=MAT_METAL)
    ##
    ##    rog.wound(pc, WOUND_BURN, 2)

    ##    rog.damage(weap, 200)
    ##    rog.fitgear(weap, pc)
    ##    print(rog.equip(
    ##        pc,weap,EQ_MAINHANDW
    ##        ))
    ##    rog.create_weapon("wooden club", xpos,ypos)
    ##    rog.create_weapon("estoc", xpos-1,ypos)
    ##    shield=rog.create_weapon("metal shield", 0,0)
    ##    rog.equip(
    ##        pc,shield,EQ_OFFHAND
    ##        )
    ##    rog.fitgear(shield, pc)
    ##    armor=rog.create_armor("metal gear", 0,0)
    ##    rog.equip(
    ##        pc,armor,EQ_FRONT
    ##        )
    ##    rog.fitgear(armor, pc)
    ##    helm=rog.create_headwear("metal helm", 0,0)
    ##    rog.equip(
    ##        pc,helm,EQ_MAINHEAD
    ##        )
    ##    rog.fitgear(helm, pc)
    ##    leg1=rog.create_legwear("metal mail legging", 0,0)
    ##    rog.equip(
    ##        pc,leg1,EQ_MAINLEG
    ##        )
    ##    rog.fitgear(leg1, pc)
    ##    leg2=rog.create_legwear("metal mail legging", 0,0)
    ##    rog.equip(
    ##        pc,leg2,EQ_OFFLEG
    ##        )
    ##    rog.fitgear(leg2, pc)
    ##    arm1=rog.create_armwear("metal vambrace", 0,0)
    ##    rog.equip(
    ##        pc,arm1,EQ_MAINARM
    ##        )
    ##    rog.fitgear(arm1, pc)
    ##    arm2=rog.create_armwear("metal vambrace", 0,0)
    ##    rog.equip(
    ##        pc,arm2,EQ_OFFARM
    ##        )
    ##    rog.fitgear(arm2, pc)
    ##    foot1=rog.create_footwear("metal boot", 0,0)
    ##    rog.equip(
    ##        pc,foot1,EQ_MAINFOOT
    ##        )
    ##    rog.fitgear(foot1, pc)
    ##    foot2=rog.create_footwear("metal boot", 0,0)
    ##    rog.equip(
    ##        pc,foot2,EQ_OFFFOOT
    ##        )
    ##    rog.fitgear(foot2, pc)
    #

    # create light so player can see
    ##    log=rog.create_rawmat("log", 18,18)
    ##    rog.burn(log,500)
    #
    # /TESTING /TEMPORARY
    #

    # TODO?: observer for player
    ##    obs=observer.Observer_playerChange()
    ##    pc.observer_add(obs)

    #-----------------------------------------------#
    #               # MAIN GAME LOOP #              #
    #-----------------------------------------------#

    rog.game_set_state("normal")

    while rog.game_is_running():

        # manually close game #
        if libtcod.console_is_window_closed():
            rog.end()

        # defeat conditions #
        if rog.on(rog.pc(), DEAD):
            rog.game_set_state("game over")

        # get input #
        pcInput = IO.get_raw_input()
        pcAct = IO.handle_mousekeys(pcInput).items()

        # commands that are available from anywhere #
        player.commands_const(rog.pc(), pcAct)

        # Finally record game state after any/all changes #
        gameState = rog.game_state()

        #----------#
        #   PLAY   #
        #----------#

        #
        # normal game play
        #
        if gameState == "normal":
            game.play(pc, pcAct)
        #
        # manager game states #
        #
        elif gameState == "manager":
            manager = rog.get_active_manager()
            manager.run(pcAct)
            if manager.result:
                rog.close_active_manager()
        #

        elif gameState == "game over":
            rog.msg("You died...")
Esempio n. 16
0
def can_be_used(item):
    return rog.on(item, CANUSE)
Esempio n. 17
0
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)
Esempio n. 18
0
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)
Esempio n. 19
0
    def process(self):
        super(FiresProcessor, self).run()

        self.removeList = []
        self.soundsList = {}
        for fx, fy in self.fires:
            #print("running fire manager for fire at {},{}".format(x,y))
            _fluids = rog.fluidsat(fx, fy)
            _things = rog.thingsat(fx, fy)
            _exit = False

            #tiles that put out fires or feed fires
            '''
            wet floor flag


            '''

            #fluids that put out fires or feed fires
            '''for flud in _fluids:
                if flud.extinguish:
                    self.remove(fx,fy)
                    _exit=True
                    continue
                if flud.flammable:
                    self.fire_spread(fx,fy)
                    continue
                    '''

            if _exit: continue

            #check for no fuel condition
            if not _things:
                #print("no things to burn. Removing fire at {},{}".format(x,y))
                self.removeList.append((
                    fx,
                    fy,
                ))
                continue

            #BURN THINGS ALIVE (or dead)
            food = 0  #counter for amount of fuel gained by the fire
            for ent in _things:  #things that might fuel the fire (or put it out)
                textSee = ""
                rog.burn(ent, FIRE_BURN)
                if rog.on(ent, FIRE):
                    food += self._gobble(ent)

            _FOOD_THRESHOLD = 5
            '''if food < _FOOD_THRESHOLD:
                if dice.roll(food) == 1:
                    print("not enough food. Removing fire at {},{}".format(fx,fy))
                    self.removeList.append((fx,fy,))
            else:'''
            if food >= _FOOD_THRESHOLD:
                iterations = 1 + int((food - _FOOD_THRESHOLD) / 3)
                self._spread(fx, fy, iterations)
            elif food == 0:
                self.removeList.append((
                    fx,
                    fy,
                ))
                continue

        #end for (fires)

        #add new fires
        self._fuseGrids()

        #remove fires
        for xx, yy in self.removeList:
            #print("fire at {},{} is to be removed...".format(xx,yy))
            self.remove(xx, yy)
            '''doNotDie=False
            #don't let the fire die if something in this tile is still burning.
            for tt in _things:
                if rog.on(tt, FIRE):
                    doNotDie=True
            if doNotDie == False:'''

        #sounds
        for k, v in self.soundsList.items():
            xx, yy = k
            snd = v
            rog.event_sound(xx, yy, snd)
Esempio n. 20
0
def main():

    #------------------------------------------------#
    # INIT
    #------------------------------------------------#

    # init settings
    settings = rog.init_settings()
    rog.init_keyBindings()
    # init global controllers
    rog.create_window(settings.window_width, settings.window_height)
    rog.create_consoles()
    rog.create_map()
    rog.create_data()
    rog.create_view()
    rog.create_clock()
    rog.create_log()
    rog.create_update()
    rog.create_environment()
    rog.create_controller()
    rog.create_savedGame()
    # init managers
    rog.create_const_managers()
    rog.create_perturn_managers()

    #map generation
    rog.map_generate(rog.map(), rog.dlvl())

    # init player object
    pc = rog.create_player(15, 15)
    obs = observer.Observer_playerChange()
    pc.observer_add(obs)
    rog.view_center(pc)

    ##TESTING
    rog.gain(pc, "hpmax", 100)
    log = rog.create_stuff(THG.LOG, 18, 18)
    rog.burn(log, 200)
    box = rog.create_stuff(THG.BOX, 20, 18)
    #fluids.smoke(16,16)
    '''pc.stats.hpmax      = 20
    pc.stats.mpmax      = 20
    pc.stats.sight      = 20
    pc.stats.spd        = 100
    pc.stats.nvision    = False'''
    #LIGHT
    pc.light = rog.create_light(pc.x, pc.y, 5, owner=pc)
    #HEAL
    rog.givehp(pc)
    rog.givemp(pc)
    #EQUIP
    #print(pc.stats.get('atk'))
    #item=gear.create_weapon("sword",pc.x,pc.y)
    #rog.equip(pc, item, EQ_MAINHAND)
    #print(pc.stats.get('atk'))
    #rog.deequip(pc,EQ_MAINHAND)
    #print(pc.stats.get('atk'))
    #BUFF
    #rog.effect_add(pc,{'atk':5})
    #rog.effect_add(pc,{'dmg':5})
    #rog.effect_add(pc,{'arm':0})
    #rog.effect_add(pc,{'msp':15})
    #rog.effect_add(pc,{'msp':-50})'''
    '''
    z = rog.create_monster('Z',15,16)
    rog.effect_add(z,{'arm':1})
    rog.effect_add(z,{'dfn':4})
    rog.effect_add(z,{'atk':3})
    rog.effect_add(z,{'dmg':3})
    rog.givehp(z)'''
    z = rog.create_monster('z', 13, 19, COL['ltblue'])
    a = rog.create_monster('a', 12, 13, COL['scarlet'])
    o = rog.create_monster('U', 19, 18, COL['red'])
    a = rog.create_monster('a', 15, 17, COL['scarlet'])
    W = rog.create_monster('W', 20, 15, COL['purple'])
    '''import dice
    for x in range(ROOMW):
        for y in range(ROOMH):
            if dice.roll(100) > 98:
                if not (rog.wallat(x,y)
                        or rog.monat(x,y) ):
                    r=rog.create_monster('r',x,y)
                    r.color=COL['ltgray']
    print("num monsters: ", len(rog.list_creatures()))
    '''
    #create a create_thing function for specific items.
    #make list of items, etc.
    yyy = Thing()
    yyy.x = 16
    yyy.y = 13
    yyy.mask = '4'
    yyy.name = 'the four of destiny'
    yyy.color = COL['gold']
    rog.register_inanimate(yyy)
    ##
    yyy = Thing()
    yyy.x = 17
    yyy.y = 13
    yyy.mask = '*'
    yyy.name = 'blood clot'
    yyy.color = COL['dkmagenta']
    rog.register_inanimate(yyy)
    ##
    '''
    yyy=Thing()
    yyy.name="wood"
    yyy.mask=chr(15)
    yyy.material=MAT_WOOD
    yyy.x=20
    yyy.y=12
    yyy.mass=20
    yyy.stats.hp=1250
    yyy.color=COL['brown']
    rog.register_inanimate(yyy)
    rog.set_status(yyy, FIRE)
    
    yyy=Thing()
    yyy.name="wood"
    yyy.mask=chr(15)
    yyy.material=MAT_WOOD
    yyy.x=10
    yyy.y=19
    yyy.mass=12
    yyy.stats.hp=400
    yyy.color=COL['brown']
    rog.register_inanimate(yyy)
    rog.set_status(yyy, FIRE)'''
    '''
    yyy=rog.create_light(25,25, 15)
    yyy=rog.create_light(14,11, 7)'''

    #-----------------------------------------------#
    #               # MAIN GAME LOOP #              #
    #-----------------------------------------------#

    rog.game_set_state("normal")

    # initialize fov for creatures with sight
    for creat in rog.list_creatures():
        if creat.stats.sight > 0:
            rog.fov_compute(creat)

    while rog.game_is_running():

        # manually close game #
        if libtcod.console_is_window_closed():
            rog.end()

        # defeat conditions #
        if rog.on(pc, DEAD):
            rog.game_set_state("game over")
        # get input #
        pcInput = IO.get_raw_input()
        pcAct = IO.handle_mousekeys(pcInput).items()

        # commands that are available from anywhere #
        player.commands_const(pc, pcAct)

        # Finally record game state after any/all changes #
        gameState = rog.game_state()

        #----------#
        #   PLAY   #
        #----------#
        #
        # normal game play
        #
        if gameState == "normal":
            game.play(pc, pcAct)
        #
        # other game states #
        #
        elif (gameState == "move view" or gameState == "look"
              or gameState == "busy" or gameState == "message history"):
            manager = rog.get_active_manager()
            manager.run(pcAct)
            if manager.result:
                rog.close_active_manager()
        #

        elif gameState == "game over":
            rog.msg("You died...")
Esempio n. 21
0
def sprint_pc(pc):
    #if sprint cooldown elapsed
    if not rog.on(pc, TIRED):
        sprint(pc)
    else:
        rog.alert("You're too tired to sprint.")
Esempio n. 22
0
def pickup_pc(pc):
    world = rog.world()
    pos = world.component_for_entity(pc, cmp.Position)
    pcx = pos.x
    pcy = pos.y
    rog.alert("Pick up what?{d}".format(d=dirStr))
    args=rog.get_direction()
    if not args:
        rog.alert()
        return
    dx,dy,dz=args
    xx,yy = pcx + dx, pcy + dy
    
    things=rog.thingsat(xx,yy)
    if pc in things: #can't pick yourself up.
        things.remove(pc)

    choice=None
    if len(things) > 1:
        rog.alert("There are multiple things here. Pick up which item?")
        choices = [] #["all",] #should player be able to pickup multiple things at once? Maybe could be a delayed action?
        for thing in things:
            choices.append(thing)
        choice=rog.menu(
            "pick up", rog.view_port_x()+2, rog.view_port_y()+2, choices
            )
    else:
        if things:
            choice=things[0]

    if (choice and not choice == "all"):

        if choice == K_ESCAPE:
            return
        
        #thing is creature! You can't pick up creatures :( or can you...?
        if world.has_component(choice, cmp.Creature):
            rog.alert("You can't pick that up!")
            return
        #thing is on fire, prompt user & burn persistent rogues
        if rog.on(choice,FIRE):
            answer=""
            while True:
                answer=rog.prompt(0,0,rog.window_w(),1,maxw=1,
                    q="That thing is on fire! Are you sure? y/n",
                    mode='wait',border=None)
                answer=answer.lower()
                if answer == "y" or answer == " " or answer == K_ENTER:
                    rog.alert("You burn your hands!")
                    rog.burn(pc, FIRE_BURN)
                    rog.hurt(pc, FIRE_HURT)
                    break
                elif answer == "n" or answer == K_ESCAPE:
                    return
        # put in inventory
        pocketThing(pc, choice)
##    elif choice == "all":
##        for tt in things:
##            pocketThing(pc, tt)
    else:
        rog.alert("There is nothing there to pick up.")