def _spread(noise): for alife in LIFE.values(): if alife['dead']: continue _can_see = False if sight.can_see_position(alife, noise['pos']): _can_see = True _dist = bad_numbers.distance(noise['pos'], alife['pos']) if _dist>noise['volume']: continue update_targets_around_noise(alife, noise) _direction_to = bad_numbers.direction_to(alife['pos'], noise['pos']) _direction_string = language.get_real_direction(_direction_to) #TODO: Check walls between positions #TODO: Add memory if not _can_see or not noise['skip_on_visual']: if _dist >=noise['volume']/2: if 'player' in alife: gfx.message(random.choice(FAR_TEXT).replace('@t', noise['text'][1]).replace('@d', _direction_string), style='sound') else: if 'player' in alife: gfx.message(random.choice(FAR_TEXT).replace('@t', noise['text'][0]).replace('@d', _direction_string), style='sound')
def get_known_group(life, life_id): _target = brain.knows_alife_by_id(life, life_id) _dialog_id = lfe.has_dialog_with(life, life_id) if 'player' in life: _menu_items = [] for group_id in life['known_groups']: if _target['group'] == group_id: continue _menu_items.append(menus.create_item('single', group_id, None, group=group_id, dialog_id=_dialog_id)) if not _menu_items: gfx.message('You don\'t know of any other groups.') return False _menu = menus.create_menu(menu=_menu_items, title='Inform of Group', format_str='$k', on_select=confirm_inform_of_group, close_on_select=True) menus.activate_menu(_menu) else: raise Exception('Dead end.')
def create_cache_drop(pos, spawn_list): _player = LIFE[SETTINGS["controlling"]] _pos = spawns.get_spawn_point_around(pos, area=10) _direction = language.get_real_direction(numbers.direction_to(_player["pos"], _pos)) for container in spawn_list: if not container["rarity"] > random.uniform(0, 1.0): continue _c = items.create_item(container["item"], position=[_pos[0], _pos[1], 2]) for _inside_item in container["spawn_list"]: if _inside_item["rarity"] <= random.uniform(0, 1.0): continue _i = items.create_item(_inside_item["item"], position=[_pos[0], _pos[1], 2]) if not items.can_store_item_in(_i, _c): items.delete_item(_i) continue items.store_item_in(_i, _c) effects.create_smoker(_pos, 300, color=tcod.orange) gfx.message("You see something parachuting to the ground to the %s." % _direction, style="event")
def tick_fields(): for territory in get_active_fields(): _spawn_chunk_keys = [k for k in territory['chunk_keys'] if WORLD_INFO['chunk_map'][k]['type'] == 'other'] if not 'create' in territory['flags'] or not territory['flags']['create']: if 'first_run' in territory['flags']: territory['flags']['create'] = random.randint(50, 60) else: territory['flags']['create'] = random.randint(150, 180) territory['flags']['first_run'] = True if SETTINGS['controlling'] and life.get_current_chunk_id(LIFE[SETTINGS['controlling']]) in _spawn_chunk_keys: gfx.message('The ground begins to shake...', style='alert') continue else: territory['flags']['create'] -= 1 continue create_burner(_spawn_chunk_keys.pop(random.randint(0, len(_spawn_chunk_keys)-1))) territory['flags']['create_amount'] -= 1 if not territory['flags']['create_amount']: territory['danger'] = None territory['flags']['create_amount'] = 0 del territory['flags']['first_run']
def create_cache_drop(pos, spawn_list): _player = LIFE[SETTINGS['controlling']] _pos = spawns.get_spawn_point_around(pos, area=10) _direction = language.get_real_direction( numbers.direction_to(_player['pos'], _pos)) for container in spawn_list: if not container['rarity'] > random.uniform(0, 1.0): continue _c = items.create_item(container['item'], position=[_pos[0], _pos[1], 2]) for _inside_item in container['spawn_list']: if _inside_item['rarity'] <= random.uniform(0, 1.0): continue _i = items.create_item(_inside_item['item'], position=[_pos[0], _pos[1], 2]) if not items.can_store_item_in(_i, _c): items.delete_item(_i) continue items.store_item_in(_i, _c) effects.create_smoker(_pos, 300, color=tcod.orange) gfx.message('You see something parachuting to the ground to the %s.' % _direction, style='event')
def get_known_group(life, life_id): _target = brain.knows_alife_by_id(life, life_id) _dialog_id = lfe.has_dialog_with(life, life_id) if 'player' in life: _menu_items = [] for group_id in life['known_groups']: if _target['group'] == group_id: continue _menu_items.append( menus.create_item('single', group_id, None, group=group_id, dialog_id=_dialog_id)) if not _menu_items: gfx.message('You don\'t know of any other groups.') return False _menu = menus.create_menu(menu=_menu_items, title='Inform of Group', format_str='$k', on_select=confirm_inform_of_group, close_on_select=True) menus.activate_menu(_menu) else: raise Exception('Dead end.')
def execute_recipe(life, item, recipe): _difficulty = get_recipe_difficulty(life, item, recipe) _dice_percentage = bad_numbers.roll(2, 5) / (10.0 + _difficulty) if _dice_percentage >= .75: _recipe_quality = 'success' elif _dice_percentage >= .5: _recipe_quality = 'partial_success' else: _recipe_quality = 'failure' if recipe['type'] == 'create_item': for create_item in recipe['create_item']: if not _recipe_quality in recipe['create_item'][create_item]: continue for i in range(recipe['create_item'][create_item][_recipe_quality] ['amount']): _created_item = items.create_item(create_item) lfe.add_item_to_inventory(life, _created_item) if _recipe_quality in recipe['strings']: gfx.message(recipe['strings'][_recipe_quality]) else: gfx.message('You finish crafting.')
def join_group(life, group_id): life['group'] = group_id add_member(life, group_id, life['id']) if 'player' in life: gfx.message('You join group %s.' % group_id, style='good') else: logging.debug('%s joined group %s.' % (' '.join(life['name']), group_id))
def tick_world(): WORLD_INFO['ticks'] += 1 alfe.groups.get_group_relationships() if WORLD_INFO['real_time_of_day'] < WORLD_INFO['length_of_day']: WORLD_INFO['real_time_of_day'] += WORLD_INFO['time_scale'] else: WORLD_INFO['real_time_of_day'] = 0 WORLD_INFO['day'] += 1 weather.change_weather() if WORLD_INFO['real_time_of_day'] >= WORLD_INFO[ 'length_of_day'] - 22.00 or WORLD_INFO[ 'real_time_of_day'] <= WORLD_INFO['length_of_day'] * .15: if WORLD_INFO['time_of_day'] == 'day': gfx.message('Night falls.') WORLD_INFO['time_of_day'] = 'night' else: if WORLD_INFO['time_of_day'] == 'night': gfx.message('The sun rises.') WORLD_INFO['time_of_day'] = 'day' if WORLD_INFO['dynamic_spawn_interval'][0] > 0: WORLD_INFO['dynamic_spawn_interval'][0] -= 1 elif not WORLD_INFO['dynamic_spawn_interval'][0]: spawns.generate_life(random.choice(['loner', 'bandit'])) WORLD_INFO['dynamic_spawn_interval'][0] = random.randint( WORLD_INFO['dynamic_spawn_interval'][1][0], WORLD_INFO['dynamic_spawn_interval'][1][1]) logging.info('Reset life spawn clock: %s' % WORLD_INFO['dynamic_spawn_interval'][0]) if WORLD_INFO['wildlife_spawn_interval'][0] > 0: WORLD_INFO['wildlife_spawn_interval'][0] -= 1 elif not WORLD_INFO['wildlife_spawn_interval'][0]: worldgen.generate_wildlife() WORLD_INFO['wildlife_spawn_interval'][0] = random.randint( WORLD_INFO['wildlife_spawn_interval'][1][0], WORLD_INFO['wildlife_spawn_interval'][1][1]) logging.info('Reset wildlife spawn clock: %s' % WORLD_INFO['wildlife_spawn_interval'][0]) #situations.form_scheme() #situations.execute_scheme() alfe.factions.direct() core.evaluate_overwatch_mood() cache.scan_cache()
def burn(item, amount): if not 'CAN_BURN' in item['flags']: return False item['burning'] += amount*.1 if item['owner']: logging.debug('%s\'s %s catches fire!' % (' '.join(LIFE[item['owner']]['name']), item['name'])) if 'player' in LIFE[item['owner']]: gfx.message('Your %s catches fire!' % item['name'])
def add_member(life, group_id, life_id): if is_member(life, group_id, life_id): raise Exception( '%s failed to add new member: %s is already a member of group: %s' % (' '.join(life['name']), ' '.join( LIFE[life_id]['name']), group_id)) if not life['id'] == life_id: _target = brain.knows_alife_by_id(life, life_id) if _target: if _target['group'] == group_id: pass elif _target and _target['group']: lfe.memory(LIFE[life_id], 'left group for group', left_group=_target['group'], group=group_id) remove_member(life, _target['group'], life_id) _target['group'] = group_id else: _target = brain.meet_alife(life, LIFE[life_id]) stats.establish_trust(life, life_id) elif life['id'] == life_id and life[ 'group'] and not life['group'] == group_id: remove_member(life, life['group'], life_id) _group = get_group(life, group_id) for member in _group['members']: brain.meet_alife(LIFE[member], LIFE[life_id]) if _group['shelter']: LIFE[life_id]['shelter'] = _group['shelter'] lfe.memory(LIFE[life_id], 'shelter founder', shelter=_group['shelter'], founder=_group['leader']) _group['members'].append(life_id) if _group['leader'] and 'player' in LIFE[_group['leader']]: _text = '%s has joined your group.' % ' '.join(LIFE[life_id]['name']) gfx.message(_text, style='good') if sight.can_see_target(LIFE[_group['leader']], life_id): logic.show_event(_text, life=LIFE[life_id], delay=1) logging.debug( '%s added %s to group \'%s\'' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
def get_accuracy(life, weapon_uid, limb=None): weapon = ITEMS[weapon_uid] _accuracy = 3 * weapon['accuracy'] _accuracy *= alife.stats.get_firearm_accuracy(life) if limb: _stability = lfe.get_limb_stability(life, limb) _accuracy *= _stability if 'player' in life: if _stability <= 0: gfx.message('Your %s is useless.' % limb, style='damage') return 0 elif _stability <= .25: gfx.message('Your %s is nearly useless!' % limb, style='damage') lfe.add_wound(life, limb, pain=2) elif _stability <= .55: gfx.message('You feel a sharp pain in your %s!' % limb, style='damage') lfe.add_wound(life, limb, pain=1) elif _stability <= .75: gfx.message('Your %s stings from the recoil.' % limb, style='damage') if life['stance'] == 'standing': _accuracy *= 0.7 elif life['stance'] == 'crouching': _accuracy *= 0.9 elif life['stance'] == 'crawling': _accuracy *= 1 return _accuracy
def get_accuracy(life, weapon_uid, limb=None): weapon = ITEMS[weapon_uid] _accuracy = weapon['accuracy'] _accuracy *= alife.stats.get_firearm_accuracy(life) if limb: _stability = lfe.get_limb_stability(life, limb) _accuracy *= _stability if 'player' in life: if _stability <= 0: gfx.message('Your %s is useless.' % limb, style='damage') return 0 elif _stability <= .25: gfx.message('Your %s is nearly useless!' % limb, style='damage') lfe.add_wound(life, limb, pain=2) elif _stability <= .55: gfx.message('You feel a sharp pain in your %s!' % limb, style='damage') lfe.add_wound(life, limb, pain=1) elif _stability <= .75: gfx.message('Your %s stings from the recoil.' % limb, style='damage') if life['stance'] == 'standing': _accuracy *= 0.7 elif life['stance'] == 'crouching': _accuracy *= 0.9 elif life['stance'] == 'crawling': _accuracy *= 1 return _accuracy
def perform_moves(people): for life_id in people: _life = LIFE[life_id] if not _life['stance'] in _life['moves'] or not _life['next_stance']['towards']: continue if _life['next_stance']['towards']: _target = LIFE[_life['next_stance']['towards']] if _life['stance'] in _life['moves'] and _target['stance'] in _life['moves'][_life['stance']]['counters']: if 'player' in _target: gfx.message('You counter %s\'s %s.' % (' '.join(_life['name']), _target['stance']), style='player_combat_good') elif 'player' in _life: gfx.message('%s counters your %s.' % (' '.join(_target['name']), _life['stance']), style='player_combat_bad') print '%s counters %s\'s %s!' % (_target['name'], _life['name'], _life['stance']) #react_to_attack(_life, _target['id'], _target['stance']) else: lfe.memory(_life, 'shot', target=_target['id']) lfe.memory(_target, 'attacked', target=_life['id']) alife.judgement.judge_life(_target, _life['id']) if 'player' in _life: gfx.message('You %s %s.' % (_life['stance'], ' '.join(_target['name'])), style='player_combat_good') elif 'player' in _target: gfx.message('%s lands a %s.' % (' '.join(_life['name']), _life['stance']), style='player_combat_bad') print '%s\'s %s hits %s!' % (_life['name'], _life['stance'], _target['name']) react_to_attack(_target, _life['id'], _life['stance']) _life['next_stance']['towards'] = None
def force_stance(p, target_id, stance): if not p['stance'] == stance: if 'player' in p: gfx.message('You are thrown by %s.' % ' '.join(LIFE[target_id]['name']), style='player_combat_bad') elif 'player' in LIFE[target_id]: gfx.message('You throw %s into %s.' % (' '.join(p['name']), stance), style='player_combat_good') p['next_stance']['delay'] = get_stance_score(p, stance) p['stance'] = stance #TODO: Randomly regain balance or fall over p['next_stance']['stance'] = 'standing' p['next_stance']['forced'] = True print p['name'], 'forced into', p['stance'], '(%s' % p['next_stance']['delay']+')'
def tick_world(): WORLD_INFO['ticks'] += 1 alfe.groups.get_group_relationships() if WORLD_INFO['real_time_of_day'] < WORLD_INFO['length_of_day']: WORLD_INFO['real_time_of_day'] += WORLD_INFO['time_scale'] else: WORLD_INFO['real_time_of_day'] = 0 WORLD_INFO['day'] += 1 weather.change_weather() if WORLD_INFO['real_time_of_day']>=WORLD_INFO['length_of_day']-22.00 or WORLD_INFO['real_time_of_day']<=WORLD_INFO['length_of_day']*.15: if WORLD_INFO['time_of_day'] == 'day': gfx.message('Night falls.') WORLD_INFO['time_of_day'] = 'night' else: if WORLD_INFO['time_of_day'] == 'night': gfx.message('The sun rises.') WORLD_INFO['time_of_day'] = 'day' if WORLD_INFO['dynamic_spawn_interval'][0]>0: WORLD_INFO['dynamic_spawn_interval'][0] -= 1 elif not WORLD_INFO['dynamic_spawn_interval'][0]: spawns.generate_life(random.choice(['loner', 'bandit'])) WORLD_INFO['dynamic_spawn_interval'][0] = random.randint(WORLD_INFO['dynamic_spawn_interval'][1][0], WORLD_INFO['dynamic_spawn_interval'][1][1]) logging.info('Reset life spawn clock: %s' % WORLD_INFO['dynamic_spawn_interval'][0]) if WORLD_INFO['wildlife_spawn_interval'][0]>0: WORLD_INFO['wildlife_spawn_interval'][0] -= 1 elif not WORLD_INFO['wildlife_spawn_interval'][0]: worldgen.generate_wildlife() WORLD_INFO['wildlife_spawn_interval'][0] = random.randint(WORLD_INFO['wildlife_spawn_interval'][1][0], WORLD_INFO['wildlife_spawn_interval'][1][1]) logging.info('Reset wildlife spawn clock: %s' % WORLD_INFO['wildlife_spawn_interval'][0]) situations.form_scheme() situations.execute_scheme() artifacts.tick_fields() alfe.factions.direct() core.evaluate_overwatch_mood() cache.scan_cache()
def execute_scheme(): if not WORLD_INFO['scheme']: return False _event = None for event in WORLD_INFO['scheme']: if event['time'] <= WORLD_INFO['ticks']: _event = event break if not _event: return False _situation = core.get_player_situation() _player = LIFE[SETTINGS['controlling']] if 'sound' in _event: alife.noise.create(_event['pos'], _event['volume'], _event['sound'][0], _event['sound'][1]) if 'radio' in _event and _situation['has_radio']: gfx.message('%s: %s' % (_event['radio'][0], _event['radio'][1]), style='radio') if 'glitch' in _event: gfx.glitch_text(_event['glitch'], change_text_only=_event['change']) if 'life' in _event: _life = spawns.generate_life(_event['life']['type'], position=_event['life']['position'])[0] if 'injuries' in _event['life']: for limb in _event['life']['injuries']: lfe.add_wound(_life, limb, **_event['life']['injuries'][limb]) if 'group' in _event: if 'stage' in _event: alife.groups.set_stage(LIFE[_event['member']], _event['group'], _event['stage']) if _event['stage'] == STAGE_RAIDING: alife.groups.raid(LIFE[_event['member']], _event['group'], _event['flags']['chunk_key']) WORLD_INFO['scheme'].remove(_event)
def get_weapon_to_fire(life): if 'player' in life: return life['firing'] _item = lfe.get_held_items(life, matches=[{'type': 'gun'}]) if _item: _item = _item[0] else: return False if not _item: if 'player' in life: gfx.message('You aren\'t holding a weapon!') life['firing'] = None return False return lfe.get_inventory_item(life, _item)
def discover_group(life, group_id): if not group_id in life['known_groups']: life['known_groups'][group_id] = {'id': group_id, 'members': [], 'leader': None, 'shelter': None, 'stage': STAGE_FORMING, 'alignment': 'neutral', 'claimed_motive': 'nothing', 'flags': {}} if 'player' in life: gfx.message('You learn about group %s.' % group_id) logging.debug('%s discovered group %s.' % (' '.join(life['name']), group_id)) return True return False
def get_weapon_to_fire(life): if 'player' in life: return life['firing'] _item = lfe.get_held_items(life,matches=[{'type': 'gun'}]) if _item: _item = _item[0] else: return False if not _item: if 'player' in life: gfx.message('You aren\'t holding a weapon!') life['firing'] = None return False return lfe.get_inventory_item(life, _item)
def can_tick(ignore_tickrate=False, ignore_pause=False): if SETTINGS['controlling'] and not EVENTS and not sum( [abs(i) for i in LIFE[SETTINGS['controlling']]['velocity']]): if life.is_target_of(LIFE[SETTINGS['controlling']]): if not SETTINGS['paused']: gfx.message('An enemy appears.', style='important') SETTINGS['paused'] = True if not ignore_pause and SETTINGS['paused'] and not LIFE[ SETTINGS['controlling']]['actions'] and not LIFE[ SETTINGS['controlling']]['dead']: return False if not ignore_tickrate: if process_events(): return False elif EVENTS and not ignore_pause: return False if SETTINGS['controlling'] and not ignore_pause and not sum( [abs(i) for i in LIFE[SETTINGS['controlling']]['velocity']]): if MENUS: return False if LIFE[SETTINGS['controlling']]['targeting']: return False if life.has_dialog(LIFE[SETTINGS['controlling']]): return False if not ignore_tickrate: if time.time() - WORLD_INFO['last_update_time'] < 1: if WORLD_INFO['tps'] < 30: WORLD_INFO['tps'] += 1 else: return False else: WORLD_INFO['last_update_time'] = time.time() WORLD_INFO['tps'] = 0 return True
def force_stance(p, target_id, stance): if not p['stance'] == stance: if 'player' in p: gfx.message('You are thrown by %s.' % ' '.join(LIFE[target_id]['name']), style='player_combat_bad') elif 'player' in LIFE[target_id]: gfx.message('You throw %s into %s.' % (' '.join(p['name']), stance), style='player_combat_good') p['next_stance']['delay'] = get_stance_score(p, stance) p['stance'] = stance #TODO: Randomly regain balance or fall over p['next_stance']['stance'] = 'standing' p['next_stance']['forced'] = True print p['name'], 'forced into', p[ 'stance'], '(%s' % p['next_stance']['delay'] + ')'
def add_member(life, group_id, life_id): if not group_id in LIFE[life_id]['known_groups']: raise Exception('DOES NOT KNOW') if is_member(life, group_id, life_id): raise Exception('%s failed to add new member: %s is already a member of group: %s' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id)) if not life['id'] == life_id: _target = brain.knows_alife_by_id(life, life_id) if _target: if _target['group'] == group_id: pass elif _target and _target['group']: lfe.memory(LIFE[life_id], 'left group for group', left_group=_target['group'], group=group_id) remove_member(life, _target['group'], life_id) _target['group'] = group_id else: brain.meet_alife(life, LIFE[life_id]) elif life['id'] == life_id and life['group'] and not life['group'] == group_id: remove_member(life, life['group'], life_id) _group = get_group(life, group_id) for member in _group['members']: brain.meet_alife(LIFE[member], LIFE[life_id]) if _group['shelter']: LIFE[life_id]['shelter'] = _group['shelter'] lfe.memory(LIFE[life_id], 'shelter founder', shelter=_group['shelter'], founder=_group['leader']) _group['members'].append(life_id) if _group['leader'] and 'player' in LIFE[_group['leader']]: _text = '%s has joined your group.' % ' '.join(LIFE[life_id]['name']) gfx.message(_text, style='good') if sight.can_see_target(LIFE[_group['leader']], life_id): logic.show_event(_text, life=LIFE[life_id], delay=1) logging.debug('%s added %s to group \'%s\'' % (' '.join(life['name']), ' '.join(LIFE[life_id]['name']), group_id))
def assume_stance(p, stance, towards=None): if p['next_stance']['stance'] == stance and p['next_stance'][ 'towards'] == towards: if 'player' in p: gfx.message('You continue to %s.' % stance) return False if p['next_stance']['forced']: if not p['next_stance']['delay']: p['next_stance']['forced'] = False else: print p['name'], 'cannot move (forced)' return False p['next_stance']['delay'] = get_stance_score(p, stance) p['next_stance']['stance'] = stance p['next_stance']['towards'] = towards p['next_stance']['forced'] = False if 'player' in p: gfx.message('You start to %s.' % stance) elif 'player' in LIFE[towards]: gfx.message('%s begins to %s.' % (' '.join(p['name']), stance)) print p['name'], 'begins', p['next_stance'][ 'stance'], '(%s' % p['next_stance']['delay'] + ')' return True
def drop_cache(item_names): while 1: _chunk_key = random.choice(WORLD_INFO['chunk_map'].keys()) _chunk = alife.chunks.get_chunk(_chunk_key) if _chunk['type'] == 'other': break for item in item_names: _pos = random.choice(_chunk['ground']) _item = ITEMS[items.create_item(item, position=[_pos[0], _pos[1], 2])] for life in LIFE.values(): lfe.memory(life, 'cache_drop', chunk_key=_chunk_key) #alife.survival.add_needed_item(life, # {'pos': _item['pos'][:]}, # satisfy_if=alife.action.make_small_script(function='always'), # satisfy_callback=alife.action.make_small_script(function='consume')) #alife.brain.remember_item(life, _item) gfx.message('You see something parachuting to the ground.') print _chunk['pos']
def can_tick(ignore_tickrate=False, ignore_pause=False): if SETTINGS['controlling'] and not EVENTS and not sum([abs(i) for i in LIFE[SETTINGS['controlling']]['velocity']]): if life.is_target_of(LIFE[SETTINGS['controlling']]): if not SETTINGS['paused']: gfx.message('An enemy appears.', style='important') SETTINGS['paused'] = True if not ignore_pause and SETTINGS['paused'] and not LIFE[SETTINGS['controlling']]['actions'] and not LIFE[SETTINGS['controlling']]['dead']: return False if not ignore_tickrate: if process_events(): return False elif EVENTS and not ignore_pause: return False if SETTINGS['controlling'] and not ignore_pause and not sum([abs(i) for i in LIFE[SETTINGS['controlling']]['velocity']]): if MENUS: return False if LIFE[SETTINGS['controlling']]['targeting']: return False if life.has_dialog(LIFE[SETTINGS['controlling']]): return False if not ignore_tickrate: if time.time()-WORLD_INFO['last_update_time']<1: if WORLD_INFO['tps']<30: WORLD_INFO['tps'] += 1 else: return False else: WORLD_INFO['last_update_time'] = time.time() WORLD_INFO['tps'] = 0 return True
def execute_recipe(life, item, recipe): _difficulty = get_recipe_difficulty(life, item, recipe) _dice_percentage = numbers.roll(2, 5)/(10.0+_difficulty) if _dice_percentage >= .75: _recipe_quality = 'success' elif _dice_percentage >= .5: _recipe_quality = 'partial_success' else: _recipe_quality = 'failure' if recipe['type'] == 'create_item': for create_item in recipe['create_item']: if not _recipe_quality in recipe['create_item'][create_item]: continue for i in range(recipe['create_item'][create_item][_recipe_quality]['amount']): _created_item = items.create_item(create_item) lfe.add_item_to_inventory(life, _created_item) if _recipe_quality in recipe['strings']: gfx.message(recipe['strings'][_recipe_quality]) else: gfx.message('You finish crafting.')
def perform_moves(people): for life_id in people: _life = LIFE[life_id] if not _life['stance'] in _life['moves'] or not _life['next_stance'][ 'towards']: continue if _life['next_stance']['towards']: _target = LIFE[_life['next_stance']['towards']] if _life['stance'] in _life['moves'] and _target[ 'stance'] in _life['moves'][_life['stance']]['counters']: if 'player' in _target: gfx.message('You counter %s\'s %s.' % (' '.join(_life['name']), _target['stance']), style='player_combat_good') elif 'player' in _life: gfx.message('%s counters your %s.' % (' '.join(_target['name']), _life['stance']), style='player_combat_bad') print '%s counters %s\'s %s!' % ( _target['name'], _life['name'], _life['stance']) #react_to_attack(_life, _target['id'], _target['stance']) else: lfe.memory(_life, 'shot', target=_target['id']) lfe.memory(_target, 'attacked', target=_life['id']) alife.judgement.judge_life(_target, _life['id']) if 'player' in _life: gfx.message('You %s %s.' % (_life['stance'], ' '.join(_target['name'])), style='player_combat_good') elif 'player' in _target: gfx.message('%s lands a %s.' % (' '.join(_life['name']), _life['stance']), style='player_combat_bad') print '%s\'s %s hits %s!' % (_life['name'], _life['stance'], _target['name']) react_to_attack(_target, _life['id'], _life['stance']) _life['next_stance']['towards'] = None
def assume_stance(p, stance, towards=None): if p['next_stance']['stance'] == stance and p['next_stance']['towards'] == towards: if 'player' in p: gfx.message('You continue to %s.' % stance) return False if p['next_stance']['forced']: if not p['next_stance']['delay']: p['next_stance']['forced'] = False else: print p['name'], 'cannot move (forced)' return False p['next_stance']['delay'] = get_stance_score(p, stance) p['next_stance']['stance'] = stance p['next_stance']['towards'] = towards p['next_stance']['forced'] = False if 'player' in p: gfx.message('You start to %s.' % stance) elif 'player' in LIFE[towards]: gfx.message('%s begins to %s.' % (' '.join(p['name']), stance)) print p['name'], 'begins', p['next_stance']['stance'], '(%s' % p['next_stance']['delay']+')' return True
def fire(life, target, limb=None): #TODO: Don't breathe this! weapon = get_weapon_to_fire(life) if not weapon: return False _aim_with_limb = None for hand in life['hands']: if weapon['uid'] in lfe.get_limb(life, hand)['holding']: _aim_with_limb = hand _ooa = False _feed_uid = get_feed(weapon) if not _feed_uid: if 'player' in life: gfx.message('The weapon is unloaded.') _ooa = True return False _feed = items.get_item_from_uid(_feed_uid) if not _feed or (_feed and not _feed['rounds']): if 'player' in life: gfx.message('*Click* (You are out of ammo.)') _ooa = True return False _bullet_deviation = (1 - weapon['accuracy']) + life['recoil'] _deviation_mod = SETTINGS['aim_difficulty'] * (1 - ( (life['stats']['firearms'] / 10.0) * SETTINGS['firearms_skill_mod'])) _direction_deviation = (_bullet_deviation * SETTINGS['aim_difficulty']) * _deviation_mod life['recoil'] = bad_numbers.clip( life['recoil'] + (weapon['recoil'] * get_stance_recoil_mod(life)), 0.0, 1.0) _bullet_direction = bad_numbers.direction_to(life['pos'], target) + ( random.uniform(-_direction_deviation, _direction_deviation)) alife.noise.create(life['pos'], 120, '%s fire' % weapon['name'], 'something discharge', target=life['id']) #TODO: Clean this up... _bullet = items.get_item_from_uid(_feed['rounds'].pop()) _bullet['pos'] = life['pos'][:] _bullet['start_pos'] = life['pos'][:] _bullet['owner'] = None _bullet['shot_by'] = life['id'] _bullet['aim_at_limb'] = limb items.add_to_chunk(_bullet) if gfx.position_is_in_frame(life['pos']) or 'player' in life: effects.create_light(life['pos'], tcod.yellow, 7, 1, fade=3.2) effects.create_light(_bullet['pos'], tcod.yellow, 7, .9, fade=.65, follow_item=_bullet['uid']) effects.create_smoke_cloud(life['pos'], 3, color=tcod.light_gray) effects.create_smoke(life['pos'], color=tcod.yellow) _bullet['accuracy'] = int( round(get_accuracy(life, weapon['uid'], limb=_aim_with_limb))) print 'ACCURACY', _bullet['accuracy'] del _bullet['parent'] items.move(_bullet, _bullet_direction, _bullet['max_speed']) _bullet['start_velocity'] = _bullet['velocity'][:] items.tick_item(_bullet) for _life in [LIFE[i] for i in LIFE]: if _life['pos'][0] == target[0] and _life['pos'][1] == target[1]: life['aim_at'] = _life['id'] break if len(lfe.find_action(life, matches=[{'action': 'shoot'}])) == 1: life['firing'] = None
def explode(item): if not item['type'] == 'explosive': return False logging.debug('The %s (item %s) explodes!' % (item['name'], item['uid'])) #TODO: Don't breathe this! item['pos'] = get_pos(item['uid']) if item['damage']['force']: effects.create_explosion(item['pos'], item['damage']['force']) if SETTINGS['controlling'] and alife.sight.can_see_position( LIFE[SETTINGS['controlling']], item['pos']): gfx.message('%s explodes!' % get_name(item)) logic.show_event('%s explodes!' % get_name(item), item=item, delay=0) #elif bad_numbers.distance( #TODO: Dirty hack for life_id in LIFE: _limbs = LIFE[life_id]['body'].keys() if not _limbs: continue _force = bad_numbers.clip( (item['damage']['force'] * 2) - bad_numbers.distance(LIFE[life_id]['pos'], item['pos']), 0, 100) if not _force: continue _known_item = alife.brain.remembers_item(LIFE[life_id], item) _direction = bad_numbers.direction_to(item['pos'], LIFE[life_id]['pos']) #TODO: Intelligent(?) limb groups? _distance = bad_numbers.distance(LIFE[life_id]['pos'], item['pos']) / 2 for i in range(_force - _distance): _limb = random.choice(_limbs) for _attached_limb in life.get_all_attached_limbs( LIFE[life_id], _limb): if _attached_limb in _limbs: _limbs.remove(_attached_limb) #_limb = random.choice(LIFE[life_id]['body'].keys()) if _known_item and _known_item[ 'last_seen_time'] < 100 and _known_item['last_owned_by']: life.memory(LIFE[life_id], 'blown_up_by', target=_known_item['last_owned_by']) #for _limb in _limbs: life.add_wound(LIFE[life_id], _limb, force_velocity=bad_numbers.velocity( _direction, _force * 2)) if not _limbs: break life.push(LIFE[life_id], _direction, _force) if 'player' in LIFE[life_id]: life.say(LIFE[life_id], '@n are thrown by the explosion!', action=True) else: life.say(LIFE[life_id], '@n is thrown by the explosion!', action=True) if 'fire' in item['damage']: _circle = drawing.draw_circle(item['pos'], item['radius']) _zone = zones.get_zone_at_coords(item['pos']) if _zone: for pos in zones.dijkstra_map( item['pos'], [item['pos']], [_zone], return_score_in_range=[0, item['damage']['fire']]): if not pos in _circle: continue if not maps.position_is_in_map(pos): continue for life_id in LIFE_MAP[pos[0]][pos[1]]: for _visible_item in [ get_item_from_uid(i) for i in life.get_all_visible_items(LIFE[life_id]) ]: if not 'CAN_BURN' in _visible_item['flags']: continue burn(_visible_item, item['damage']['fire']) if not random.randint(0, 4): effects.create_fire((pos[0], pos[1], item['pos'][2]), intensity=item['damage']['fire'] / 2) _dist = bad_numbers.distance(item['pos'], pos) / 2 if not random.randint(0, _dist) or not _dist: effects.create_ash(pos) if gfx.position_is_in_frame(pos): _render_pos = gfx.get_render_position(pos) gfx.refresh_view_position(_render_pos[0], _render_pos[1], 'map') #if item['uid'] in ITEMS and ITEMS[item['uid']]['owner'] and item['uid'] in LIFE[ITEMS[item['uid']]['owner']]['inventory']: delete_item(item)
def explode(item): if not item['type'] == 'explosive': return False logging.debug('The %s (item %s) explodes!' % (item['name'], item['uid'])) #TODO: Don't breathe this! item['pos'] = get_pos(item['uid']) if item['damage']['force']: effects.create_explosion(item['pos'], item['damage']['force']) if SETTINGS['controlling'] and alife.sight.can_see_position(LIFE[SETTINGS['controlling']], item['pos']): gfx.message('%s explodes!' % get_name(item)) logic.show_event('%s explodes!' % get_name(item), item=item, delay=0) #elif bad_numbers.distance( #TODO: Dirty hack for life_id in LIFE: _limbs = LIFE[life_id]['body'].keys() if not _limbs: continue _force = bad_numbers.clip((item['damage']['force']*2)-bad_numbers.distance(LIFE[life_id]['pos'], item['pos']), 0, 100) if not _force: continue _known_item = alife.brain.remembers_item(LIFE[life_id], item) _direction = bad_numbers.direction_to(item['pos'], LIFE[life_id]['pos']) #TODO: Intelligent(?) limb groups? _distance = bad_numbers.distance(LIFE[life_id]['pos'], item['pos'])/2 for i in range(_force-_distance): _limb = random.choice(_limbs) for _attached_limb in life.get_all_attached_limbs(LIFE[life_id], _limb): if _attached_limb in _limbs: _limbs.remove(_attached_limb) #_limb = random.choice(LIFE[life_id]['body'].keys()) if _known_item and _known_item['last_seen_time'] < 100 and _known_item['last_owned_by']: life.memory(LIFE[life_id], 'blown_up_by', target=_known_item['last_owned_by']) #for _limb in _limbs: life.add_wound(LIFE[life_id], _limb, force_velocity=bad_numbers.velocity(_direction, _force*2)) if not _limbs: break life.push(LIFE[life_id], _direction, _force) if 'player' in LIFE[life_id]: life.say(LIFE[life_id], '@n are thrown by the explosion!', action=True) else: life.say(LIFE[life_id], '@n is thrown by the explosion!', action=True) if 'fire' in item['damage']: _circle = drawing.draw_circle(item['pos'], item['radius']) _zone = zones.get_zone_at_coords(item['pos']) if _zone: for pos in zones.dijkstra_map(item['pos'], [item['pos']], [_zone], return_score_in_range=[0, item['damage']['fire']]): if not pos in _circle: continue if not maps.position_is_in_map(pos): continue for life_id in LIFE_MAP[pos[0]][pos[1]]: for _visible_item in [get_item_from_uid(i) for i in life.get_all_visible_items(LIFE[life_id])]: if not 'CAN_BURN' in _visible_item['flags']: continue burn(_visible_item, item['damage']['fire']) if not random.randint(0, 4): effects.create_fire((pos[0], pos[1], item['pos'][2]), intensity=item['damage']['fire']/2) _dist = bad_numbers.distance(item['pos'], pos)/2 if not random.randint(0, _dist) or not _dist: effects.create_ash(pos) if gfx.position_is_in_frame(pos): _render_pos = gfx.get_render_position(pos) gfx.refresh_view_position(_render_pos[0], _render_pos[1], 'map') #if item['uid'] in ITEMS and ITEMS[item['uid']]['owner'] and item['uid'] in LIFE[ITEMS[item['uid']]['owner']]['inventory']: delete_item(item)
def fire(life, target, limb=None): #TODO: Don't breathe this! weapon = get_weapon_to_fire(life) if not weapon: return False _aim_with_limb = None for hand in life['hands']: if weapon['uid'] in lfe.get_limb(life, hand)['holding']: _aim_with_limb = hand _ooa = False _feed_uid = get_feed(weapon) if not _feed_uid: if 'player' in life: gfx.message('The weapon is unloaded.') _ooa = True return False _feed = items.get_item_from_uid(_feed_uid) if not _feed or (_feed and not _feed['rounds']): if 'player' in life: gfx.message('*Click* (You are out of ammo.)') _ooa = True return False direction = numbers.direction_to(life['pos'],target)+(random.uniform(-life['recoil'], life['recoil'])) alife.noise.create(life['pos'], 120, '%s fire' % weapon['name'], 'something discharge') #TODO: Clean this up... _bullet = items.get_item_from_uid(_feed['rounds'].pop()) _bullet['pos'] = life['pos'][:] _bullet['start_pos'] = life['pos'][:] _bullet['owner'] = None _bullet['shot_by'] = life['id'] _bullet['aim_at_limb'] = limb life['recoil'] += _bullet['recoil']*(weapon['recoil']*get_stance_recoil_mod(life)) items.add_to_chunk(_bullet) if gfx.position_is_in_frame(life['pos']): effects.create_light(life['pos'], tcod.yellow, 7, 1, fade=3.5) effects.create_light(_bullet['pos'], tcod.yellow, 7, 1, fade=0.65, follow_item=_bullet['uid']) effects.create_smoke_cloud(life['pos'], 3, color=tcod.light_gray) effects.create_smoke(life['pos'], color=tcod.yellow) _bullet['accuracy'] = int(round(get_accuracy(life, weapon['uid'], limb=_aim_with_limb))) del _bullet['parent'] items.move(_bullet, direction, _bullet['max_speed']) _bullet['start_velocity'] = _bullet['velocity'][:] items.tick_item(_bullet) for _life in [LIFE[i] for i in LIFE]: if _life['pos'][0] == target[0] and _life['pos'][1] == target[1]: life['aim_at'] = _life['id'] break if len(lfe.find_action(life, matches=[{'action': 'shoot'}])) == 1: life['firing'] = None