local oldModBP = ModBlueprints 
function ModBlueprints(all_bps) 
   oldModBP(all_bps) 


	    for id,bp in all_bps.Unit do 
	        if bp.Buffs then 
	            local healthbuff, newBuff 
				for i,buff in ipairs(bp.Buffs) do 
					if buff.BuffType == 'MAXHEALTH' then 
	                    healthbuff = buff.Value * 0.5 
	                end 
	            end 
	            newBuff = { 
	                Add = { VeteranLevel1 = true }, 
	                BuffType = 'MAXHEALTH', 
	                Value = healthbuff,
	            }, 
	            table.insert(bp.Buffs, newBuff) 
	            newBuff = { 
	                Add = { VeteranLevel1 = true }, 
	                BuffType = 'HEALTH', 
	                Value = healthbuff, 
	            }, 
	            table.insert(bp.Buffs, newBuff) 
	           	newBuff = { 
	                Add = { VeteranLevel3 = true }, 
	                BuffType = 'MAXHEALTH', 
	                Value = healthbuff,
	            }, 
	            table.insert(bp.Buffs, newBuff) 
	            newBuff = { 
	                Add = { VeteranLevel3 = true }, 
	                BuffType = 'HEALTH', 
	                Value = healthbuff, 
	            }, 
	            table.insert(bp.Buffs, newBuff) 
	        end


      
  			if bp.Wreckage then
        		bp.Wreckage.MassMult = bp.Wreckage.MassMult * 0.4
        		bp.Wreckage.ReclaimTimeMultiplier = 8
        	end
                
        	if bp.Buffs then
				for i, v in ipairs(bp.Buffs) do 
	
			    	if (v.BuffType == 'MAXHEALTH') then 
        	        	v.Value = v.Value
            		end  
            		if (v.BuffType == 'HEALTH') then 
	                	v.Value = v.Value
    	        	end 
        	    	if (v.BuffType == 'HEALTHREGENRATE') then 
            	    	v.Value = v.Value * 10
                		if  v.Value > 30 then
                			v.value = 30
                		end
	            	end    
		 		end
		 	end
			
		 	
		 if bp.Veteran then
			local list = false
			local structure = false
			
			local weaponAdd = 0
			local EconomyAdd = 0
			local techAdd = 1
			for i, cat in bp.Categories do
				if cat == 'EXPERIMENTAL' then
					techAdd = 100
				elseif cat == 'COMMAND' then
					techAdd = 20
				elseif cat == 'TECH3' then
					techAdd = 4
				elseif cat == 'TECH2' then
					techAdd = 2
				elseif cat == 'TECH1' then
					techAdd = 1
				end
				
				if cat == 'STRUCTURE' then
					if bp.Weapon then
						EconomyAdd = math.pow(bp.Economy.BuildCostMass, 0.8) / 15
						weaponAdd = math.pow(bp.Weapon[1].MaxRadius, 0.8)/ 2
						structure = true
					end
				else
					if bp.Weapon and not structure then
						EconomyAdd = math.pow(bp.Economy.BuildCostMass, 0.8) / 30
						weaponAdd = math.pow(bp.Weapon[1].MaxRadius, 0.8)/ 4
					end
				end

				--[[if string.sub(bp.BlueprintId, 2, 2) == 'a' and cat == 'TECH3' then
				if cat == 'EXPERIMENTAL' or cat == 'COMMAND' then
					LOG('-------------------------------------')
					local name = string.gsub(bp.Description, '<(.*)>(.*)', '%2')
					LOG(name)
					LOG('Old: ', repr(bp.Veteran))
					list = true
				end]]
			end
			for i in bp.Veteran do
				local level = 1
				if i == 'Level5' then
					level = 5
				elseif i == 'Level4' then
					level = 4
				elseif i == 'Level3' then
					level = 3
				elseif i == 'Level2' then
					level = 2
				elseif i == 'Level1' then
					level = 1
				end
				bp.Veteran[i] = math.floor( level * ( weaponAdd + techAdd + EconomyAdd ) )
			end
			--[[if list then
				--LOG('WeaponAdd/TechAdd: ' .. weaponAdd .. '/' ..techAdd)
				LOG('New: ', repr(bp.Veteran))
			end]]
		end 
		
			local civilian = 0
			if bp.Display.Tarmacs then 
 	           for i,v in pairs(bp.Categories) do 
 	           		if v == 'CIVILIAN' then 
 	           			civilian = 1
 	           		end
 	           	end
 	           	
 	           		for i,v in pairs(bp.Categories) do 
 	               		if v == 'UEF' and civilian == 0 then 
	                  			bp.Display.Tarmacs[1].Length = bp.Display.Tarmacs[1].Length * 2
	                    		bp.Display.Tarmacs[1].Width = bp.Display.Tarmacs[1].Width * 2
 	                   			bp.Display.Tarmacs[1].FadeOut = 900
	                		end 
	                	if v == 'CYBRAN' and civilian == 0 then
 	               			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar12x_cybran_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar12x_01_albedo_cybran.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar12x_01_normals'
                				end
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar6x_cybran_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar6x_01_albedo_cybran.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar6x_01_normals'
                			end
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar8x_cybran_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar8x_01_albedo_cybran.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar8x_01_normals'
                			end
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar10x_cybran_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar10x_01_albedo_cybran.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar10x_01_normals'
                			end
                    		bp.Display.Tarmacs[1].Length = bp.Display.Tarmacs[1].Length * 2
                    		bp.Display.Tarmacs[1].Width = bp.Display.Tarmacs[1].Width * 2 
                    		bp.Display.Tarmacs[1].FadeOut = 900    
                		end     
                		if v == 'AEON' and civilian == 0 then
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar12x_aeon_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar12x_01_albedo_aeon.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar12x_01_normals'
                			end
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar6x_aeon_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar6x_01_albedo_aeon.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar6x_01_normals'
                			end
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar8x_aeon_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar8x_01_albedo_aeon.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar8x_01_normals'
                			end
                			if bp.Display.Tarmacs[1].Albedo == 'Tarmacs/Tar10x_aeon_01_albedo'
                				then bp.Display.Tarmacs[1].Albedo = '/mods/4th_Dimension 191/hook/env/Common/decals/Tarmacs/Tar10x_01_albedo_aeon.dds'
                					bp.Display.Tarmacs[1].Normal = 'Tarmacs/Tar10x_01_normals'
                			end
                    		bp.Display.Tarmacs[1].Length = bp.Display.Tarmacs[1].Length * 2
                    		bp.Display.Tarmacs[1].Width = bp.Display.Tarmacs[1].Width * 2 
                    		bp.Display.Tarmacs[1].FadeOut = 900    
                		end 
                	end		                       	
            	end 

        if bp.Defense then 
            for i,v in pairs(bp.Categories) do 
                if v == 'CYBRAN' then 
                	for i,v in pairs(bp.Categories) do
                		if v == 'TECH1' then 
                			for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.25
                					end
                				end
                			end
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 1
							end
						end	
						if v == 'TECH2' then 
						    for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.5
                					end
                				end
                			end
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 2
							end
						end
                		if v == 'TECH3' then 
                			for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 1
                					end
                				end
                			end		
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 4
							end
						end	
                		if v == 'EXPERIMENTAL' then 
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 10
							end
						end														
					end	
                end 
				if v == 'AEON' then 
                	for i,v in pairs(bp.Categories) do
                		if v == 'TECH1' then
                		    for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.0625
                					end
                				end
                			end
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 0.25
							end
						end	
						if v == 'TECH2' then 
                			for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.125
                					end
                				end
                			end						
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 0.5
							end
						end
                		if v == 'TECH3' then 
                			for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.25
                					end
                				end
                			end                		
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 1
							end
						end	
                		if v == 'EXPERIMENTAL' then 
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 2
							end
						end														
					end	
                end
                if v == 'UEF' then 
                	for i,v in pairs(bp.Categories) do
                		if v == 'TECH1' then 
                		    for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.0625
                					end
                				end
                			end                		
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 0.25
							end
						end	
						if v == 'TECH2' then
                		    for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.125
                					end
                				end
                			end						 
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 0.5
							end
						end
                		if v == 'TECH3' then 
                		    for i,v in pairs(bp.Categories) do
                				if v == 'AIR' then 
                					if bp.Defense.RegenRate == 0 then
                						bp.Defense.RegenRate = 0.25
                					end
                				end
                			end                		
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 1
							end
						end	
                		if v == 'EXPERIMENTAL' then 
							if bp.Defense.RegenRate == 0 then
								bp.Defense.RegenRate = 2.5
							end
						end														
					end	
                end                 
            end 
        end 
	end
end
