from __future__ import division
import math, random
import constants, physics

"""TO DO: create suite of variable assigning fucntions that reflect inheritance 
and assign multiple properties as automatically as possible"""

def add_thermo_material(dict, material, rho, shc, heat_transfer, burn_min, burn_temp, burn_max, burn_rate, burn_damage):
    """setup function for quickly creating new materials.
    not actually used, just built for practice
    """
    dict[material]['rho'] = rho
    dict[material]['shc'] = shc
    dict[material]['heat_transfer'] = heat_transfer
    dict[material]['burn_min'] = burn_min
    dict[material]['burn_temp'] = burn_temp
    dict[material]['burn_max'] = burn_max
    dict[material]['burn_rate'] = burn_rate
    dict[material]['burn_damage'] = burn_damage

materials = {}
#add_thermo_material(materials, 'air', 1.293, 1004, 300, 100, 10000, 100, 1, 0.01)

materials['air']={'rho':1.293,'shc':1004,'heat_transfer':300,'burn_min':100,
'burn_temp':10000,'burn_max':100,'burn_rate':1,'burn_damage':0.01}

materials['water']={'rho':1000,'shc':4181,'heat_transfer':100,'burn_min':100,
'burn_temp':10000,'burn_max':100,'burn_rate':1,'burn_damage':0.01}

materials['wood']={'rho':900,'shc':100,'heat_transfer':100,'burn_min':80,
'burn_temp':150,'burn_max':1300,'burn_rate':1,'burn_damage':0.01}

materials['shrub']={'rho':500,'shc':10,'heat_transfer':200,'burn_min':50,
'burn_temp':50,'burn_max':350,'burn_rate':1,'burn_damage':0.05}

materials['petrol']={'rho':770,'shc':20,'heat_transfer':250,'burn_min':15,
'burn_temp':15,'burn_max':250,'burn_rate':1,'burn_damage':0.0002}

materials['phosphorus']={'rho':1300,'shc':20,'heat_transfer':450,'burn_min':10,
'burn_temp':10,'burn_max':10000,'burn_rate':1,'burn_damage':0.01}

materials['concrete']={'rho':2750,'shc':1000,'heat_transfer':50,'burn_min':1000,
'burn_temp':10000,'burn_max':10000,'burn_rate':1,'burn_damage':0.01}

materials['animal']={'rho':800,'shc':30,'heat_transfer':10,'burn_min':45,
'burn_temp':120,'burn_max':250,'burn_rate':1,'burn_damage':0.01}



def default(sim):
    #setup physics time for physics integrator
    sim.physics_dt = sim.world.physics_dt
    sim.physics_time_remaining = sim.world.dt
    
    #setup grid properties
    sim.grid_viewed = False
    sim.sight_radius = 0
    
    #setup faction properties
    sim.faction = None
    
    #setup simulation properties
    sim.physical = True # can have physics, heat, appied to it (NOT YET USED)
    sim.collidable = False # can collide with other stuff, but cannot penetrate
    sim.penetrating = False # can move though other stuff, like a bullet
    sim.mobile = False # can move, apply physics to it
    sim.motive = False # can move under own power, sim.memory dont remember it
    
    sim.heatable = False
    sim.opaque = False # does not block sight
    sim.block = False # does not block movement
    
    sim.indicator_color = None # for drawing screen edge indicators
    
    sim.zombie_food = 0
    
    ##sim.attrs = {} # a dict of attributes for sims. physical data, game data, stats, etc.
    ##sim.attrs['physics'] = {}
    ##sim.attrs['physics']['shape'] = "circle"
    sim.boundary_method = 'stop' # need to make this an attr as well
    
    sim.max_health = 1 # need to ake this part of the attrs dict, as well as all other sim "game attrs
    
    sim.load_image(sim.world.images[sim.sim_type+"_image"])
    
    sim.attrs = {} # attributes dictionary. can have sub-dictionary values for groups of attributes
    
    sim.stack_count = 1
    sim.stackable = False
    
def load_thermo_constants(sim, materials, material):
    sim.heatable = True
    
    sim.attrs['thermo'] = {}
    sim.attrs['thermo']['material'] = material
    for key, val in materials[material].items():
        sim.attrs['thermo'][key] = val

def load_physical_constants(sim, sim_type):
    
    sim.attrs['physics'] = {}
    for key, val in physics[sim_type].items():
        sim.attrs['physics'][key] = val
    
def concrete_block(sim):
    sim.sim_cat = "block"
    sim.elevation = 1
    sim.collidable = True
    sim.opaque = True
    sim.block = True

    load_thermo_constants(sim, materials, 'concrete')
    
    sim.attrs['physics']= dict(
                                shape = 'square', 
                                mass = 2750*2,
                                friction_0 = 10, 
                                friction_1 = 8, 
                                coeff_drag = 2, 
                                reference_area = 2, 
                                hardness = 10**8, 
                                elasticity =0.95
                                )

    
    sim.max_health = 10**5




def shrub(sim):
    sim.sim_cat = "block"
    sim.heatable = True
    
    load_thermo_constants(sim, materials, 'shrub')
    sim.attrs['physics']= dict(
                                shape = 'square', 
                                mass = 20,
                                friction_0 = 10, 
                                friction_1 = 8, 
                                coeff_drag = 2, 
                                reference_area = 2, 
                                hardness = 0, 
                                elasticity =0.2
                                )
    
    sim.max_health =random.uniform(500,2000)

     
    sim.opaque = True
    sim.elevation = 2   
    
def zombie_hive(sim):
    sim.sim_cat = "block"
    sim.faction = "horde"
    sim.collidable = True
    load_thermo_constants(sim, materials, 'animal')
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 100,
                                friction_0 = 10, 
                                friction_1 = 8, 
                                coeff_drag = 2, 
                                reference_area = 2, 
                                hardness = 100, 
                                elasticity =0.9
                                )


    sim.max_health = 10**3

    sim.opaque = True
    sim.block = True
    sim.elevation = 1

    sim.world.num_hives +=1
    sim.world.num_zom +=1
    
    sim.points = 1000    

def survivor(sim):
    sim.sim_cat = "biped"
    sim.faction = "survivors"
     
    sim.elevation = 1
    sim.mobile = True
    sim.motive = True
    sim.collidable = True
    load_thermo_constants(sim, materials, 'animal')
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 80,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**6, 
                                elasticity =0.0
                                )

    
    sim.speed_mod = 1
    sim.speed_max = 12/3.6 #km/h into m/s
    sim.acc_max = 4*constants.GRAVITY
    sim.acc_profile = lambda sim: max(sim.acc_max*(1-(sim.speed/(sim.speed_max*sim.speed_mod))**2),0)
    sim.turn_rate = math.pi*2
    sim.agility = 1.8

    sim.max_ammo = constants.MAX_AMMO
    sim.max_health = 250
    
    sim.max_grenades  = constants.MAX_GRENADES
    
    
    sim.zombie_food = 20
    
    sim.indicator_color = (0,0,255)
    sim.alive = True
    sim.sight_radius = constants.survivor_SIGHT_RADIUS
    
    sim.throw_radius = constants.survivor_SIGHT_RADIUS
    
    sim.max_sprint_energy = 20
    sim.sprint_energy = sim.max_sprint_energy
    sim.fitness = 5 
    sim.sprinting = False
    
    
    sim.melee_damage = 10 #he much damage sim does per attack
    sim.melee_range = 0.5 # how far sim can reach beyond sim radius to attack
    sim.melee_arc = 0.5 #cos(theta), theta is melee arc angle, can attack in this angle
    sim.melee_delay = 1

    sim.world.num_hum +=1
    sim.points = -1000
            
def zombie_normal(sim):
    sim.sim_cat = "biped"
    sim.faction = "horde"
     
    sim.sound_groan = sim.world.sounds[sim.sim_type+"_groan"]
    sim.elevation = 1
    sim.mobile = True
    sim.motive = True
    sim.collidable = True
    load_thermo_constants(sim, materials, 'animal')

    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 100,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.acc_max = 2*constants.GRAVITY
    sim.speed_max = 10/3.6 #km/h into m/s
    sim.acc_profile = lambda sim: max(sim.acc_max*(1-(sim.speed/sim.speed_max)**2),0)
    sim.turn_rate = math.pi
    sim.agility = 1.4

    sim.max_health = 80
      
    sim.indicator_color = (255,0,0)
    sim.alive = False
    sim.sight_radius = constants.ZOMBIE_SIGHT_RADIUS
    
    sim.sprinting = False
    sim.max_sprint_energy = 20
    sim.sprint_energy = sim.max_sprint_energy
    sim.fitness = 5 

    sim.melee_damage = 40 #he much damage sim does per attack
    sim.melee_range = 0.5 # how far sim can reach beyond sim radius to attack
    sim.melee_arc = 0.4 #cos(theta), theta is melee arc angle, can attack in this angle
    sim.melee_delay = 1
    sim.world.num_zom +=1
    
    sim.points = 5
            
def zombie_massive(sim):
    sim.sim_cat = "biped"
    sim.faction = "horde"
     
    sim.sound_groan = sim.world.sounds[sim.sim_type+"_groan"]
    sim.elevation = 1
    sim.mobile = True
    sim.motive = True
    sim.collidable = True
    load_thermo_constants(sim, materials, 'animal')
  
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 200,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.acc_max = 4*constants.GRAVITY
    sim.speed_max = 15/3.6 #km/h into m/s
    sim.acc_profile = lambda sim: max(sim.acc_max*(1-(sim.speed/sim.speed_max)**2),0)
    sim.turn_rate = math.pi/4*1.2
    sim.agility = -0.7
    #sim.acc_profile = "0.001*sim.acc_max/(sim.speed/sim.speed_max+1)"
    #sim.acc_profile = "sim.acc_max/(sim.speed/sim.speed_max)"

    sim.max_health = 1000
      
    sim.indicator_color = (100,0,0)
    sim.alive = False
    sim.sight_radius = constants.ZOMBIE_SIGHT_RADIUS
    
    sim.sprinting = False
    sim.max_sprint_energy = 20
    sim.sprint_energy = sim.max_sprint_energy
    sim.fitness = 5 
    
    sim.melee_damage = 100 #he much damage sim does per attack
    sim.melee_range = 0.5 # how far sim can reach beyond sim radius to attack
    sim.melee_arc = 0.4 #cos(theta), theta is melee arc angle, can attack in this angle
    sim.melee_delay = 1
    
    sim.world.num_zom +=1
    
    sim.points = 250
            
def zombie_fast(sim):
    sim.sim_cat = "biped"
    sim.faction = "horde"
     
    sim.sound_groan = sim.world.sounds[sim.sim_type+"_groan"]
    sim.elevation = 1
    sim.mobile = True
    sim.motive = True
    sim.collidable = True
    load_thermo_constants(sim, materials, 'animal')
  
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.acc_max = 6*constants.GRAVITY
    sim.speed_max = 30/3.6 #km/h into m/s
    sim.acc_profile = lambda sim: 0.1*sim.acc_max/(sim.speed/sim.speed_max+0.1)
    sim.turn_rate = math.pi*4
    sim.agility = 1.3

    sim.max_health = 30
      
    sim.indicator_color = (175,0,0)
    sim.alive = False
    sim.sight_radius = constants.ZOMBIE_SIGHT_RADIUS
    
    sim.sprinting = False
    sim.max_sprint_energy = 20
    sim.sprint_energy = sim.max_sprint_energy
    sim.fitness = 5 
    
    sim.melee_damage = 30 #he much damage sim does per attack
    sim.melee_range = 0.5 # how far sim can reach beyond sim radius to attack
    sim.melee_arc = 0.5 #cos(theta), theta is melee arc angle, can attack in this angle
    sim.melee_delay = 0.5
    
    sim.world.num_zom +=1
    
    sim.points = 10
    
def remains(sim):
    sim.sim_cat = "pickup"
    
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    
    load_thermo_constants(sim, materials, 'animal')

    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 20 # seconds
    sim.zombie_food = 1

    sim.alive = False
    sim.elevation = 0
    
    sim.decay_rate = sim.max_health/constants.CORPSE_LIFETIME

def zombie_normal_corpse(sim):
    sim.sim_cat = "pickup"
    
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    
    load_thermo_constants(sim, materials, 'animal')
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 100,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 50 # seconds
    sim.zombie_food = 1

    sim.alive = False
    sim.elevation = 0
    
    sim.decay_rate = sim.max_health/constants.CORPSE_LIFETIME

def zombie_massive_corpse(sim):
    sim.sim_cat = "pickup"
    
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    
    load_thermo_constants(sim, materials, 'animal')
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 200,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 250 # seconds
    sim.zombie_food = 1

    sim.alive = False
    sim.elevation = 0
    
    sim.decay_rate = sim.max_health/constants.CORPSE_LIFETIME

def zombie_fast_corpse(sim):
    sim.sim_cat = "pickup"
    
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    
    load_thermo_constants(sim, materials, 'animal')
  
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 25 # seconds
    sim.zombie_food = 1

    sim.alive = False
    sim.elevation = 0
    
    sim.decay_rate = sim.max_health/constants.CORPSE_LIFETIME

def ammo(sim):
    sim.sim_cat = "pickup"
    
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    sim.stackable = True
    
    sim.boundary_method = "stop"
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2.1, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 50 

    sim.stack_count = 1000
    sim.stack_max = 1000
    
    sim.elevation = 0
    
    sim.decay_rate = -1

def medkit(sim):
    sim.sim_cat = "pickup"
    
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    sim.stackable = True
    
    sim.boundary_method = "stop"
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 2000

    sim.stack_count = 1000
    sim.stack_max = 1000
    
    sim.elevation = 0
    
    sim.decay_rate = -1


def petrol(sim):
    sim.sim_cat = "pickup"
    sim.mobile = True
    
    load_thermo_constants(sim, materials, 'petrol')
  
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 1.3, 
                                reference_area = 1, 
                                hardness = 10**2, 
                                elasticity =0.0
                                )

    sim.max_health = 200

    sim.elevation = 0
    sim.decay_rate = 0  
    
def Pistol(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]
    
    sim.length = 0.20
    sim.recoil = 17/180
    sim.muzzle_velocity = 350
    sim.recock_time = 1/6
    sim.reload_time = 0.5
    sim.clip_size = 10
    sim.clip_ammo = 0
    sim.ammo_use = 0
    sim.ammo = 0
    sim.firemode = "semi"
    sim.weapon_num = 1
    sim.bullets = 1
    
def SMG(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]

    sim.length = 0.4
    sim.recoil = 12/180
    sim.muzzle_velocity = 350
    sim.recock_time = 1/50
    sim.reload_time = 1
    sim.clip_size = 100
    sim.clip_ammo = 0
    sim.ammo_use = 1
    sim.ammo = 0
    sim.firemode = "full"
    sim.weapon_num = 2
    sim.bullets = 1
    
    
    
    
def AssaultR(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]
    
    sim.length = .65
    sim.recoil = 5/180
    sim.muzzle_velocity = 800
    sim.recock_time = 1/10
    sim.reload_time = 1.5
    sim.clip_size = 30
    sim.clip_ammo = 0
    sim.ammo_use = 2
    sim.ammo = 0
    sim.firemode = "full"
    sim.weapon_num = 3
    sim.bullets = 1
    
def SniperR(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]

    sim.length = 1.0
    sim.recoil = 0.01/180
    sim.muzzle_velocity = 1000
    sim.recock_time = .5
    sim.reload_time = 1
    sim.clip_size = 5
    sim.clip_ammo = 0
    sim.ammo_use = 6
    sim.ammo = 0
    sim.firemode = "manual"
    sim.weapon_num = 4
    sim.bullets = 1
    
def GaussR(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]

    sim.length = 0.6
    sim.recoil = 0.0/180
    sim.muzzle_velocity = 3000
    sim.recock_time = .4
    sim.reload_time = 2
    sim.clip_size = 10
    sim.clip_ammo = 0
    sim.ammo_use = 20
    sim.ammo = 0
    sim.firemode = "manual"
    sim.weapon_num = 6
    sim.bullets = 1

def MiniGun(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]

    sim.length = 0.7
    sim.recoil = 5/180
    sim.muzzle_velocity = 800
    sim.recock_time = .01
    sim.reload_time = 3
    sim.clip_size = 250
    sim.clip_ammo = 0
    sim.ammo_use =  constants.MAX_AMMO/sim.clip_size
    sim.ammo = 0
    sim.firemode = "full"
    sim.weapon_num = 7
    sim.bullets = 1
    

def LaserR(sim):
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]

    sim.length = 0.6
    sim.recoil = 0
    sim.muzzle_velocity = 3000
    sim.recock_time = 0
    sim.reload_time = sim.world.dt
    sim.clip_size = 1
    sim.clip_ammo = 0
    sim.ammo_use = 1
    sim.ammo = 0
    sim.firemode = "full"
    sim.weapon_num = 5
    sim.bullets = 1

def Pistol_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 24*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0.009**2, 
                                hardness = 0, 
                                elasticity =0.1
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.reload_time = 1/50
    sim.color = (254,254,0)

    sim.trail_thickness = 1
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1

def SMG_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
    
        
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 8*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0.009**2, 
                                hardness = 0, 
                                elasticity =0.05
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (254,254,0)

    sim.trail_thickness = 1
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1

def AssaultR_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
    
        
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 10*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0.01**2, 
                                hardness = 0, 
                                elasticity =0.1
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (254,254,0)

    sim.trail_thickness = 1
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1

def SniperR_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 65*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0.01**2, 
                                hardness = 0, 
                                elasticity =0.9
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (254,254,0)

    sim.trail_thickness = 1
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1
    
def GaussR_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 100*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0, 
                                hardness = 100, 
                                elasticity = 1
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (102,0,153)

    sim.trail_thickness = 2
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1
    
def MiniGun_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
    
        
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 50*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0.01**2, 
                                hardness = 0.5, 
                                elasticity = 0.3
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (255,255,125)

    sim.trail_thickness = 1
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1
    
def LaserR_bullet(sim):
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.boundary_method = "kill"
        
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1*10**-9,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0, 
                                reference_area =  0, 
                                hardness = 0, 
                                elasticity = 0
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (255,0,0)

    sim.trail_thickness = 3
    sim.mobile = True
    sim.motive = True
    sim.elevation = 1
    
    #sim.damage = 25
def muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1

def Pistol_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1

def SMG_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1

def AssaultR_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1

def SniperR_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1
    
def LaserR_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1


def GaussR_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1  
    
def MiniGun_muzzle_flash(sim):
    sim.sim_cat = "effect"
    sim.penetrating = True
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.01 # seconds
    sim.elevation = 1
    sim.decay_rate = 1  
    
def blood(sim):
    sim.sim_cat = "effect"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = False
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = 0.2 # seconds
     
    sim.elevation = 2
    sim.decay_rate = 1
    
def ricochet(sim):
    sim.sim_cat = "effect"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = False
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.max_health = sim.world.dt/2 # seconds
     
    sim.elevation = 2
    sim.decay_rate = 1
    
def fire(sim):
    sim.sim_cat = "effect"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = False
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.sound = sim.world.sounds[sim.sim_type]
    sim.max_health = 0.2 # seconds
    
     
    sim.elevation = 2
    
    sim.decay_rate = 1

def rip(sim):
    sim.sim_cat = "effect"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = False
    sim.motive = True
    sim.boundary_method = "stop"
     
    sim.sound = sim.world.sounds[sim.sim_type]
    sim.max_health = 0.2 # seconds
    sim.elevation = 2
    sim.decay_rate = 1  
    
def grenade_concussion(sim):
    sim.sim_cat = "grenade"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = True
    sim.motive = True
    sim.boundary_method = "stop"
    
        
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 0.5,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0, 
                                reference_area =  0**2, 
                                hardness = 15, 
                                elasticity = 1
                                )

    sim.sound_explosion = sim.world.sounds[sim.sim_type]
    sim.max_health = 0.5 


    sim.elevation = 2
    sim.grenade_num = 1
    
    sim.decay_rate = 1

def grenade_molotov(sim):
    sim.sim_cat = "grenade"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = True
    sim.motive = True
    sim.boundary_method = "stop"
       
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 0.5,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0, 
                                reference_area =  0**2, 
                                hardness = 15, 
                                elasticity = 1
                                )

    sim.sound_explosion = sim.world.sounds[sim.sim_type]
    sim.max_health = 0.5 

    sim.elevation = 2
    sim.grenade_num = 2
    
    sim.decay_rate = 1
    
def grenade_incendiary(sim):
    sim.sim_cat = "grenade"
    sim.collidable = False
    sim.penetrating = True
    sim.mobile = True
    sim.motive = True
    sim.boundary_method = "stop"
       
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 0.5,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0, 
                                reference_area =  0**2, 
                                hardness = 15, 
                                elasticity = 1
                                )
    
    sim.sound_explosion = sim.world.sounds[sim.sim_type]
    sim.max_health = 0.5 


    sim.elevation = 2
    sim.grenade_num = 3
    
    sim.decay_rate = 1

def Shotgun(sim):
    "From Sean Lange"
    sim.sim_cat = "weapon"
    sim.mobile = True
    sim.collidable = True
    sim.penetrating = True

    sim.boundary_method = "stop"
    sim.elevation = 2

    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 1,
                                friction_0 = 1, 
                                friction_1 = 0.9, 
                                coeff_drag = 2, 
                                reference_area = 0.1, 
                                hardness = 0, 
                                elasticity =0
                                )

    sim.sound_shoot = sim.world.sounds["shoot_"+sim.sim_type]
    sim.sound_reload = sim.world.sounds["reload_"+sim.sim_type]
    
    sim.length = 0.5
    sim.recoil = 6/180
    sim.muzzle_velocity = 600
    sim.recock_time = 1/2
    sim.reload_time = 1.5
    sim.clip_size = 8
    sim.clip_ammo = 0
    sim.ammo_use = 5
    sim.ammo = 0
    sim.firemode = "semi"
    sim.weapon_num = 8
    sim.bullets = 6

def Shotgun_bullet(sim):
    "From Sean Lange"
    sim.sim_cat = "bullet"
    sim.collidable = True
    sim.penetrating = True
    sim.mobile = True
    sim.motive = True
    sim.boundary_method = "kill"
    
    sim.attrs['physics']= dict(
                                shape = 'circle', 
                                mass = 8*10**-3,
                                friction_0 = 0, 
                                friction_1 = 0, 
                                coeff_drag = 0.295, 
                                reference_area =  0.009**2, 
                                hardness = 0, 
                                elasticity = 0
                                )

    sim.load_image(sim.world.images["bullet_image"])
    sim.color = (254,254,0)

    sim.trail_thickness = 1

    sim.elevation = 1
    
def find_drag(sim):
    if sim.mobile:
        sim.attrs['physics']['drag_term_1'] = constants.RHO_AIR*sim.attrs['physics']['reference_area']*sim.attrs['physics']['coeff_drag']
        sim.attrs['physics']['drag_term_2'] = 1/2*constants.RHO_AIR*sim.attrs['physics']['reference_area']*sim.attrs['physics']['coeff_drag']
##        sim.max_speed = physics.get_max_speed(sim)

def load_physical_attributes(sim):
    """ loads the sim data based on the sim_type automatically
    uses icky eval, but eval makes the code so compact!
    """
    default(sim)
    apply(eval(sim.sim_type), [sim])
    find_drag(sim)