<s> from globals import * <EOL> import life as lfe <EOL> import language <EOL> import graphics <EOL> import numbers <EOL> import timers <EOL> import items <EOL> import alife <EOL> import logging <EOL> import random <EOL> def get_puncture_value ( item , target_structure , target_structure_name = '<STR_LIT:object>' , debug = True ) : <EOL> _damage = ( ( ( item [ '<STR_LIT>' ] / float ( item [ '<STR_LIT>' ] ) ) * item [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) * ( target_structure [ '<STR_LIT>' ] / float ( target_structure [ '<STR_LIT>' ] ) ) ) * ( item [ '<STR_LIT:size>' ] / float ( numbers . get_surface_area ( target_structure ) ) ) <EOL> if debug : <EOL> logging . debug ( '<STR_LIT>' % ( item [ '<STR_LIT:name>' ] , target_structure_name ) ) <EOL> logging . debug ( '<STR_LIT>' % ( item [ '<STR_LIT:name>' ] , item [ '<STR_LIT>' ] , item [ '<STR_LIT>' ] ) ) <EOL> logging . debug ( '<STR_LIT>' % ( target_structure_name , target_structure [ '<STR_LIT>' ] , target_structure [ '<STR_LIT>' ] ) ) <EOL> logging . debug ( '<STR_LIT>' % ( item [ '<STR_LIT:name>' ] , item [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> logging . debug ( '<STR_LIT>' % ( item [ '<STR_LIT:name>' ] , item [ '<STR_LIT:size>' ] , target_structure_name , target_structure [ '<STR_LIT:size>' ] ) ) <EOL> logging . debug ( '<STR_LIT>' % ( item [ '<STR_LIT:name>' ] , _damage , target_structure_name ) ) <EOL> return _damage <EOL> def own_language ( life , message ) : <EOL> _mentioned_name = False <EOL> _ret_string = '<STR_LIT>' <EOL> for txt in message : <EOL> if '<STR_LIT>' in life : <EOL> _ret_string += txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> _name = txt . replace ( '<STR_LIT>' , language . get_name_ownership ( life , pronoun = _mentioned_name ) ) <EOL> if not _name == txt : <EOL> _mentioned_name = True <EOL> _ret_string += _name <EOL> return _ret_string <EOL> def bullet_hit ( life , bullet , limb ) : <EOL> _owner = LIFE [ bullet [ '<STR_LIT>' ] ] <EOL> _actual_limb = lfe . get_limb ( life , limb ) <EOL> _items_to_check = [ ] <EOL> if '<STR_LIT>' in _owner : <EOL> if bullet [ '<STR_LIT>' ] == limb : <EOL> _msg = [ '<STR_LIT>' ] <EOL> elif not limb in life [ '<STR_LIT:body>' ] : <EOL> return '<STR_LIT>' <EOL> else : <EOL> _msg = [ '<STR_LIT>' ] <EOL> _detailed = True <EOL> elif '<STR_LIT>' in life : <EOL> _msg = [ '<STR_LIT>' ] <EOL> else : <EOL> _msg = [ '<STR_LIT>' % ( items . get_name ( bullet ) , life [ '<STR_LIT:name>' ] [ <NUM_LIT:0> ] , limb ) ] <EOL> for item_uid in lfe . get_items_attached_to_limb ( life , limb ) : <EOL> _items_to_check . append ( { '<STR_LIT>' : item_uid , '<STR_LIT>' : True } ) <EOL> _item = items . get_item_from_uid ( item_uid ) <EOL> if '<STR_LIT>' in _item : <EOL> for item_in_container_uid in _item [ '<STR_LIT>' ] : <EOL> _chance_of_hitting_item = _item [ '<STR_LIT>' ] / float ( _item [ '<STR_LIT>' ] ) <EOL> if random . uniform ( <NUM_LIT:0> , <NUM_LIT:1> ) < _chance_of_hitting_item : <EOL> break <EOL> _items_to_check . append ( { '<STR_LIT>' : item_in_container_uid , '<STR_LIT>' : False } ) <EOL> for entry in _items_to_check : <EOL> _item = items . get_item_from_uid ( entry [ '<STR_LIT>' ] ) <EOL> _item_damage = get_puncture_value ( bullet , _item , target_structure_name = _item [ '<STR_LIT:name>' ] ) <EOL> _item [ '<STR_LIT>' ] = numbers . clip ( _item [ '<STR_LIT>' ] - _item_damage , <NUM_LIT:0> , _item [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in _item and not _item [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> _speed_mod = _item_damage <EOL> _can_stop = True <EOL> bullet [ '<STR_LIT>' ] *= _speed_mod <EOL> bullet [ '<STR_LIT>' ] [ <NUM_LIT:0> ] *= _speed_mod <EOL> bullet [ '<STR_LIT>' ] [ <NUM_LIT:1> ] *= _speed_mod <EOL> else : <EOL> _can_stop = False <EOL> if not _item [ '<STR_LIT>' ] : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> if _item [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> items . explode ( _item ) <EOL> else : <EOL> items . delete_item ( _item ) <EOL> else : <EOL> if bullet [ '<STR_LIT>' ] <= <NUM_LIT:1> and _can_stop : <EOL> _msg . append ( '<STR_LIT>' % items . get_name ( _item ) ) <EOL> _ret_string = own_language ( life , _msg ) <EOL> if _ret_string . endswith ( '<STR_LIT:!>' ) : <EOL> return _ret_string <EOL> else : <EOL> return _ret_string + '<STR_LIT:.>' <EOL> else : <EOL> if '<STR_LIT>' in _item : <EOL> if _item [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> else : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> _damage = get_puncture_value ( bullet , _actual_limb , target_structure_name = limb ) <EOL> _actual_limb [ '<STR_LIT>' ] = numbers . clip ( _actual_limb [ '<STR_LIT>' ] - _damage , <NUM_LIT:0> , _actual_limb [ '<STR_LIT>' ] ) <EOL> _damage_mod = <NUM_LIT:1> - ( _actual_limb [ '<STR_LIT>' ] / float ( _actual_limb [ '<STR_LIT>' ] ) ) <EOL> if limb in life [ '<STR_LIT:body>' ] : <EOL> _msg . append ( '<STR_LIT:U+002CU+0020>' + lfe . add_wound ( life , limb , cut = _damage * _damage_mod , impact_velocity = bullet [ '<STR_LIT>' ] ) ) <EOL> _ret_string = own_language ( life , _msg ) <EOL> if _ret_string . endswith ( '<STR_LIT:!>' ) : <EOL> return _ret_string <EOL> else : <EOL> return _ret_string + '<STR_LIT:.>' <EOL> def bite ( life , target_id , limb ) : <EOL> logging . debug ( '<STR_LIT>' % ( '<STR_LIT:U+0020>' . join ( life [ '<STR_LIT:name>' ] ) , '<STR_LIT:U+0020>' . join ( LIFE [ target_id ] [ '<STR_LIT:name>' ] ) , limb ) ) <EOL> target = LIFE [ target_id ] <EOL> _msg = [ '<STR_LIT:%s>' % language . get_introduction ( life ) ] <EOL> _bite_strength = random . randint ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> if numbers . distance ( life [ '<STR_LIT>' ] , target [ '<STR_LIT>' ] ) > <NUM_LIT:1> : <EOL> _msg . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT:U+0020>' . join ( _msg ) + '<STR_LIT:.>' <EOL> _items_to_check = [ ] <EOL> for _item in lfe . get_items_attached_to_limb ( target , limb ) : <EOL> _items_to_check . append ( { '<STR_LIT>' : _item , '<STR_LIT>' : True } ) <EOL> _actual_item = items . get_item_from_uid ( _item ) <EOL> if '<STR_LIT>' in _actual_item : <EOL> for _item_in_container in _actual_item [ '<STR_LIT>' ] : <EOL> _items_to_check . append ( { '<STR_LIT>' : _item_in_container , '<STR_LIT>' : False } ) <EOL> for entry in _items_to_check : <EOL> _item = items . get_item_from_uid ( entry [ '<STR_LIT>' ] ) <EOL> if not '<STR_LIT>' in _item : <EOL> logging . warning ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> _item [ '<STR_LIT>' ] = _item [ '<STR_LIT:size>' ] / <NUM_LIT:2> <EOL> _thickness = _item [ '<STR_LIT>' ] <EOL> _item [ '<STR_LIT>' ] = numbers . clip ( _item [ '<STR_LIT>' ] - _bite_strength , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> _bite_strength -= _thickness <EOL> _tear = _item [ '<STR_LIT>' ] - _thickness <EOL> _limb_in_context = False <EOL> if _item [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if _thickness and not _item [ '<STR_LIT>' ] : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> elif _tear <= - <NUM_LIT:3> : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> elif _tear <= - <NUM_LIT:2> : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> elif _tear <= - <NUM_LIT:1> : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> if _bite_strength <= <NUM_LIT:0> and _item [ '<STR_LIT>' ] : <EOL> _msg . append ( '<STR_LIT>' % _item [ '<STR_LIT:name>' ] ) <EOL> return '<STR_LIT:U+0020>' . join ( _msg ) <EOL> if _bite_strength == <NUM_LIT:1> : <EOL> _msg . append ( '<STR_LIT>' % limb ) <EOL> elif _bite_strength == <NUM_LIT:2> : <EOL> _msg . append ( '<STR_LIT>' % limb ) <EOL> elif _bite_strength == <NUM_LIT:3> : <EOL> _msg . append ( '<STR_LIT>' % limb ) <EOL> if _bite_strength : <EOL> lfe . add_wound ( target , limb , cut = _bite_strength ) <EOL> _bite_strength -= <NUM_LIT:1> <EOL> _ret_string = own_language ( target , _msg ) <EOL> return _ret_string + '<STR_LIT:.>' </s>
