local function damage_entity(surface, distSq, ePos, fireballSq, initialDamage, v, force, cause, corpseMap) local damage = fireballSq*initialDamage/distSq local eProto = v.prototype if(v.type=="tree") then -- efficient tree handling if(math.random(0, 100)<1) then surface.create_entity{name="fire-flame-on-tree", target = v, position=ePos} end local damage = math.random(damage/8, damage)/2 if((((not eProto.resistances) or not eProto.resistances.fire) and v.health=1000000) then fireShield = e; break; end end if fireShield then fireShield.energy = fireShield.energy-1000000 else surface.create_entity{name="fire-sticker", position=ePos, target=v} end end else if(((not eProto.resistances) or not eProto.resistances.fire) and v.health>damage) then v.health = v.health-damage elseif(eProto.resistances and eProto.resistances.fire and v.health>(damage-eProto.resistances.fire.decrease)*(1-eProto.resistances.fire.percent)) then v.health = v.health-(damage-eProto.resistances.fire.decrease)*(1-eProto.resistances.fire.percent) else if(corpseMap[v.name]) then local corpseName = corpseMap[v.name] --local ghost --if(eProto.create_ghost_on_death or eProto.create_ghost_on_death == nil) then -- ghost = {inner_name = v.name, name = "entity-ghost", direction = v.direction, expires = true, force = v.force, position = v.position} -- if(v.type == "assembling-machine" and v.get_recipe()) then -- ghost.recipe = v.get_recipe().name -- end --end v.destroy{raise_destroy = true} surface.create_entity{name=corpseName, position=ePos} --if(eProto.create_ghost_on_death or eProto.create_ghost_on_death == nil) then -- surface.create_entity(ghost) --end else if(cause and cause.valid) then v.damage(damage, force, "fire", cause) else v.damage(damage, force, "fire") end end end end end end local function atomic_thermal_blast_internal(surface_index, position, force, cause, thermal_max_r, initialDamage, fireball_r, initial_x, initial_y, corpseMap) -- do thermal heat-wave damage local thermSq = thermal_max_r*thermal_max_r; local fireballSq = fireball_r*fireball_r; local surface = game.surfaces[surface_index] local areas = {} local y = -1; local x = -1; if(thermal_max_r<500) then areas = {{{position.x-thermal_max_r, position.y-thermal_max_r}, {position.x+thermal_max_r, position.y+thermal_max_r}}} else local i = 0; y = initial_y; x = initial_x; local distSq1 local distSq2 local distSq3 local distSq4 while(y+100<=position.y+thermal_max_r) do initial_x = position.x-thermal_max_r; while(x+100<=position.x +thermal_max_r) do distSq1 = (x-position.x)*(x-position.x) +(y-position.y)*(y-position.y) distSq2 = (x+100-position.x)*(x+100-position.x)+(y-position.y)*(y-position.y) distSq3 = (x-position.x)*(x-position.x) +(y+100-position.y)*(y+100-position.y) distSq4 = (x+100-position.x)*(x+100-position.x)+(y+100-position.y)*(y+100-position.y) if(distSq1=100) then break; end end if(i<100 and y ~= position.y +thermal_max_r) then while(x+100<=position.x +thermal_max_r) do if(distSq1fireballSq and v.prototype.max_health ~= 0 and ePos.x>=a[1][1] and ePos.x=a[1][2] and ePos.yfireballSq and v.prototype.max_health ~= 0 and ePos.x>=x and ePos.x=y and ePos.y