Repository navigation
Expand file tree
/
Copy pathcontrol.lua
More file actions
637 lines (596 loc) · 39.2 KB
/
Copy pathcontrol.lua
File metadata and controls
637 lines (596 loc) · 39.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
script.on_init(function()
storage.check_fires = {}
storage.enable_robots = {}
local ver = string.gsub((script.active_mods["uniturret"] or ""), "%.", "")
if (tonumber(ver) or 0) >=174 then
storage.uniturret = true
end
storage.items = {}
--register_ammo()
end)
script.on_configuration_changed(function()
local ver = string.gsub((script.active_mods["uniturret"] or ""), "%.", "")
if not storage.uniturret and ((tonumber(ver) or 0) >=174) then
for id, tbl in pairs(storage.check_fires) do
if tbl.fire and tbl.fire.valid then
tbl.hitbox = tbl.fire.surface.create_entity{name = "fide_hitbox", position=tbl.fire.position, force = "fide-forces-fires"}
end
end
storage.uniturret = true
elseif storage.uniturret and not ((tonumber(ver) or 0) >=174) then
storage.uniturret = nil
end
storage.items = {}
--register_ammo()
end)
--function register_ammo()
--for name, item in pairs(game.item_prototypes) do
--if item.type == "ammo" and item.name ~= "fide-water-gun-ammo" and item.name ~= "rr-decon-sprayer-ammo" then
--local fuel_value = 45 * 10^6
--local ammo_cat = item.get_ammo_type("default").category
----local fuel_cat = "explosive"
--local explosion = nil
--if ammo_cat == "bullet" then
--fuel_value = 25 * 10^6
--explosion = 1
--elseif ammo_cat == "cannon-shell" then
--fuel_value = 50 * 10^6
--explosion = 2
--elseif ammo_cat == "rocket" then
--fuel_value = 100 * 10^6
--explosion = 3
--elseif ammo_cat == "artillery-shell" then
--fuel_value = 75 * 10^6
--explosion = 4
--elseif ammo_cat == "flamethrower" then
--fuel_value = 120 * 10^6
----fuel_cat = "chemical"
--end
--storage.items[name] = {fuel_value = fuel_value, fuel_category = "chemical", explosion = explosion}
--elseif item.type == "capsule" and item.name:find("grenade") then
--storage.items[name] = {fuel_value = 15*10^6, fuel_category = "chemical", explosion = 2}
--end
--end
--end
local explosions = {
"explosion-hit",
"explosion",
"big-explosion",
"ground-explosion"
}
local burning_types = {
"furnace",
"furnace",
"furnace",
"furnace",
"boiler",
"boiler",
"generator",
"radar",
"assembling-machine",
"assembling-machine",
"assembling-machine",
"assembling-machine",
"lamp",
"lab",
"electric-energy-interface",
"mining-drill",
"rocket-silo",
"accumulator",
"reactor",
}
local not_burning_types = {
["entity-ghost"] = true,
["corpse"] = true,
["fire"] = true,
["particle"] = true,
["player"] = true,
["stream"] = true,
--["item-entity"] = true,
["resource"] = true,
["explosion"] = true,
["fish"] = true,
["heat-pipe"] = true,
["construction-robot"] = true,
["logistic-robot"] = true,
["locomotive"] = true,
["cargo-wagon"] = true,
["fluid-wagon"] = true,
["rail-remnants"] = true,
--["unit"] = true,
--[""] = true,
--[""] = true,
--[""] = true,
--[""] = true,
--[""] = true,
}
script.on_event(defines.events.on_tick, function(event)
if not storage.enable_robots then storage.enable_robots = {} end -- REMOVE LATER
if not storage.check_fires then storage.check_fires = {} end -- REMOVE LATER
if not storage.remove_fires then storage.remove_fires = {} end -- REMOVE LATER
if not storage.items then storage.items = {} end
if storage.remove_fires[event.tick] then
for _, fire in pairs(storage.remove_fires[event.tick]) do
if fire and fire.valid then
fire.destroy()
end
end
storage.remove_fires[event.tick]=nil
end
if storage.enable_robots[event.tick] then
for _, robot in pairs(storage.enable_robots[event.tick]) do
if robot and robot.valid then
robot.active = true
end
end
storage.enable_robots[event.tick]=nil
end
local runs = math.max(1,(storage.firecount or 0)/5) + (storage.fractional_tick or 0)
storage.fractional_tick = runs % 1
for i=1,runs do
local remove_entry
if storage.iterate_fires and not storage.check_fires[storage.iterate_fires] then
--remove_entry = storage.iterate_fires
elseif storage.iterate_fires then
--if event.tick >= storage.check_fires[storage.iterate_fires].next_growth then
if not storage.check_fires[storage.iterate_fires].fire or not storage.check_fires[storage.iterate_fires].fire.valid or (storage.uniturret and (not storage.check_fires[storage.iterate_fires].hitbox or not storage.check_fires[storage.iterate_fires].hitbox.valid)) then
remove_entry = storage.iterate_fires
if storage.check_fires[storage.iterate_fires].ghost then
storage.check_fires[storage.iterate_fires].ghost.destroy()
end
if storage.check_fires[storage.iterate_fires].hitbox then
storage.check_fires[storage.iterate_fires].hitbox.destroy()
end
if storage.check_fires[storage.iterate_fires].fire then
storage.check_fires[storage.iterate_fires].fire.destroy()
end
else
end
end
storage.iterate_fires = next(storage.check_fires ,storage.iterate_fires)
if not storage.iterate_fires then
storage.iterate_fires = next(storage.check_fires ,storage.iterate_fires)
end
if remove_entry then
storage.check_fires[remove_entry] = nil
end
end
spread_fires(event)
end)
local function table_length(tbl)
local i=0
for _ in pairs(tbl) do
i=i+1
end
return i
end
function dbg(str)
if str == nil then
str = "nil"
elseif type(str) ~= "string" and type(str) ~= "number" then
if type(str)=="boolean" then
if str == true then
str = "true"
else
str = "false"
end
else
str=type(str)
end
end
game.players[1].print(game.tick.. " "..str)
end
local function random_point_in_box (collision_box)
end
local function spread_fire(src_pos, entity)
local collision_box = entity.prototype.collision_box
local left_top_x = collision_box.left_top.x
local right_bottom_x = collision_box.right_bottom.x
local left_top_y = collision_box.left_top.y
local right_bottom_y = collision_box.right_bottom.y
local random_point_x = left_top_x*0.85+math.random()*(right_bottom_x-left_top_x)*0.7
local random_point_y = left_top_y*0.85+math.random()*(right_bottom_y-left_top_y)*0.7
local entity_pos = entity.position
--same entity
if src_pos.x > entity_pos.x+left_top_x and src_pos.x < entity_pos.x+right_bottom_x and src_pos.y > entity_pos.y+left_top_y and src_pos.y < entity_pos.y+right_bottom_y then
--if math.random() > 0.4 then
random_point_x = entity.position.x+random_point_x
random_point_y = entity.position.y+random_point_y
--end
else
if src_pos.x > entity_pos.x then
random_point_x = math.min(entity.position.x + right_bottom_x, src_pos.x)-0.2
else
random_point_x = math.max(entity.position.x + left_top_x, src_pos.x)+0.2
end
if src_pos.y > entity_pos.y then
random_point_y = math.min(entity.position.y + right_bottom_y, src_pos.y)-0.2
else
random_point_y = math.max(entity.position.y + left_top_y, src_pos.y)+0.2
end
end
local fires = entity.surface.find_entities_filtered{area = {{random_point_x-0.6,random_point_y-0.6},{random_point_x+0.6,random_point_y+0.6}}, name='fide-fire-flame'}
if #fires <1 then
entity.surface.create_entity{name = "fide-fire-flame", position = {random_point_x,random_point_y}, raise_built =true}
end
end
if settings.startup["fide-high-performance"].value then
function spread_fires(event)
-- spread fires
if not storage.check_fires then storage.check_fires = {} end -- REMOVE LATER
local runs = math.min(4,(storage.firecount or 0)/200 + (storage.fractional_tick_spread or 0))
storage.fractional_tick_spread = runs % 1
for i=1,runs do
local remove_entry
if storage.iterate_fires2 and not storage.check_fires[storage.iterate_fires2] then
remove_entry = storage.iterate_fires2
end
if storage.iterate_fires2 and not remove_entry then
--if event.tick >= storage.check_fires[storage.iterate_fires2].next_growth then
if not storage.check_fires[storage.iterate_fires2].fire or not storage.check_fires[storage.iterate_fires2].fire.valid or (storage.uniturret and (not storage.check_fires[storage.iterate_fires2].hitbox or not storage.check_fires[storage.iterate_fires2].hitbox.valid))then
remove_entry = storage.iterate_fires2
if storage.check_fires[storage.iterate_fires2].ghost then
storage.check_fires[storage.iterate_fires2].ghost.destroy()
end
if storage.check_fires[storage.iterate_fires2].hitbox then
storage.check_fires[storage.iterate_fires2].hitbox.destroy()
end
if storage.check_fires[storage.iterate_fires2].fire then
storage.check_fires[storage.iterate_fires2].fire.destroy()
end
elseif event.tick > storage.check_fires[storage.iterate_fires2].tick then
local pos = storage.check_fires[storage.iterate_fires2].fire.position
local surroundings2 = storage.check_fires[storage.iterate_fires2].fire.surface.find_entities_filtered{area={{pos.x-4.5,pos.y-4.5},{pos.x+4.5,pos.y+4.5}}}
for _, ent in pairs(surroundings2) do
--dbg( math.random() > 0.1 and ent ~= storage.check_fires[storage.iterate_fires2].fire and ent.prototype.resistances and not ( ent.prototype.resistances.fire and ent.prototype.resistances.fire.percent and ent.prototype.resistances.fire.percent > 0.90))
if math.random() > 0.33 and ent.valid and ent ~= storage.check_fires[storage.iterate_fires2].fire and not not_burning_types[ent.type] and not (ent.prototype.resistances and ent.prototype.resistances.fire and ent.prototype.resistances.fire.percent and ent.prototype.resistances.fire.percent >= 0.90) then
--dbg(ent.type)
if ent.type == "character" then
elseif ent.type == "item-entity" then
local itemname = ent.stack.name
if not storage.items[itemname] then
local prototype = ent.stack.prototype
storage.items[itemname] ={fuel_value = prototype.fuel_value, fuel_category = prototype.fuel_category}
end
if storage.items[itemname].fuel_value and storage.items[itemname].fuel_category == "chemical" and math.log(storage.items[itemname].fuel_value+1, 10)/9 > math.random() then
----dbg(math.log10(ent.stack.prototype.fuel_value+1)/9)
-- --dbg("burning item")
local entpos = nil
local entsurface = ent.surface
if math.random() > 0.8 then
if distance(ent.position, pos) < 3.5 then
entpos = ent.position
spread_fire(pos, ent)
elseif math.random()>0.6 then
entpos = ent.position
spread_fire(pos, ent)
end
end
ent.destroy()
if entpos and storage.items[itemname].explosion then
entsurface.create_entity{name = explosions[storage.items[itemname].explosion], position = entpos}
local surroundings = entsurface.find_entities_filtered{position = entpos, radius = storage.items[itemname].explosion}
for _, surr in pairs(surroundings) do
if surr.health and surr.type ~= "transport-belt" then
surr.damage(storage.items[itemname].explosion*50, "neutral")
end
end
end
end
elseif ent.type == "transport-belt" then
local line1 = ent.get_transport_line(1)
local line2 = ent.get_transport_line(2)
--local contents1 = line1.get_contents()
--local contents2 = line2.get_contents()
local burn_value = 0
local explosion = 0
for index = 1, #line1 do --, itemstack in pairs(line1) do
local itemname = line1[index].name
if not storage.items[itemname] then
local prototype = line1[index].prototype
storage.items[itemname] ={fuel_value = prototype.fuel_value, fuel_category = prototype.fuel_category}
end
if storage.items[itemname].fuel_value and storage.items[itemname].fuel_category == "chemical" then
burn_value = burn_value+storage.items[itemname].fuel_value
if storage.items[itemname].explosion and storage.items[itemname].explosion > explosion then
explosion = storage.items[itemname].explosion
end
end
end
for index = 1, #line2 do --for index, itemstack in pairs(line2) do
local itemname = line2[index].name
if not storage.items[itemname] then
local prototype = line2[index].prototype
storage.items[itemname] ={fuel_value = prototype.fuel_value, fuel_category = prototype.fuel_category}
end
if storage.items[itemname].fuel_value and storage.items[itemname].fuel_category == "chemical" then
burn_value = burn_value+storage.items[itemname].fuel_value
if storage.items[itemname].explosion and storage.items[itemname].explosion > explosion then
explosion = storage.items[itemname].explosion
end
end
end
if burn_value > 0 then
if math.max(0.5,math.log(burn_value+1, 10)/9) > math.random() then
local entpos = nil
local entsurface = ent.surface
if distance(ent.position, pos) < 3.5 then
entpos = ent.position
spread_fire(pos, ent)
elseif math.random()>0.6 then
entpos = ent.position
spread_fire(pos, ent)
end
if entpos and explosion>0 then
entsurface.create_entity{name = explosions[explosion], position = entpos}
local surroundings = entsurface.find_entities_filtered{position = entpos, radius = explosion}
for _, surr in pairs(surroundings) do
if surr.health and surr.type ~= "transport-belt" then
surr.damage(explosion*50, "neutral")
end
end
end
--ent.damage(50,"enemy")
end
elseif event.tick > storage.check_fires[storage.iterate_fires2].tick+105 and math.random() > 0.85 then
if distance(ent.position, pos) < 3.5 then
spread_fire(pos, ent)
elseif math.random()>0.6 then
spread_fire(pos, ent)
end
end
elseif event.tick > storage.check_fires[storage.iterate_fires2].tick+105 and math.random() > 0.85 then
--dbg(ent.type)
if distance(ent.position, pos) < 3.5 then
spread_fire(pos, ent)
elseif math.random()>0.6 then
spread_fire(pos, ent)
end
end
end
end
end
end
storage.iterate_fires2 = next(storage.check_fires ,storage.iterate_fires2)
if not storage.iterate_fires2 then
storage.iterate_fires2 = next(storage.check_fires ,storage.iterate_fires2)
end
if remove_entry then
storage.check_fires[remove_entry] = nil
end
end
end
else
not_burning_types["item-entity"] = true
function spread_fires(event)
-- spread fires
if not storage.check_fires then storage.check_fires = {} end -- REMOVE LATER
local runs = math.min(5,(storage.firecount or 0)/200 + (storage.fractional_tick_spread or 0))
storage.fractional_tick_spread = runs % 1
for i=1,runs do
local remove_entry
if storage.iterate_fires2 and not storage.check_fires[storage.iterate_fires2] then
remove_entry = storage.iterate_fires2
end
if storage.iterate_fires2 and not remove_entry then
--if event.tick >= storage.check_fires[storage.iterate_fires2].next_growth then
if not storage.check_fires[storage.iterate_fires2].fire or not storage.check_fires[storage.iterate_fires2].fire.valid or (storage.uniturret and (not storage.check_fires[storage.iterate_fires2].hitbox or not storage.check_fires[storage.iterate_fires2].hitbox.valid))then
remove_entry = storage.iterate_fires2
if storage.check_fires[storage.iterate_fires2].ghost then
storage.check_fires[storage.iterate_fires2].ghost.destroy()
end
if storage.check_fires[storage.iterate_fires2].hitbox then
storage.check_fires[storage.iterate_fires2].hitbox.destroy()
end
if storage.check_fires[storage.iterate_fires2].fire then
storage.check_fires[storage.iterate_fires2].fire.destroy()
end
elseif event.tick > storage.check_fires[storage.iterate_fires2].tick + 105 then
local pos = storage.check_fires[storage.iterate_fires2].fire.position
local surroundings2 = storage.check_fires[storage.iterate_fires2].fire.surface.find_entities_filtered{area={{pos.x-4.5,pos.y-4.5},{pos.x+4.5,pos.y+4.5}}}
for _, ent in pairs(surroundings2) do
--dbg( math.random() > 0.1 and ent ~= storage.check_fires[storage.iterate_fires2].fire and ent.prototype.resistances and not ( ent.prototype.resistances.fire and ent.prototype.resistances.fire.percent and ent.prototype.resistances.fire.percent > 0.90))
if math.random() > 0.9 and ent.valid and ent ~= storage.check_fires[storage.iterate_fires2].fire and not not_burning_types[ent.type] and not (ent.prototype.resistances and ent.prototype.resistances.fire and ent.prototype.resistances.fire.percent and ent.prototype.resistances.fire.percent >= 0.90) then
--dbg(ent.type)
if distance(ent.position, pos) < 3.5 then
spread_fire(pos, ent)
elseif math.random()>0.6 then
spread_fire(pos, ent)
end
end
end
end
end
storage.iterate_fires2 = next(storage.check_fires ,storage.iterate_fires2)
if not storage.iterate_fires2 then
storage.iterate_fires2 = next(storage.check_fires ,storage.iterate_fires2)
end
if remove_entry then
storage.check_fires[remove_entry] = nil
end
end
end
end
function distance(pos1,pos2)
local x=(pos1.x-pos2.x)^2
local y=(pos1.y-pos2.y)^2
return(x+y)^0.5
end
script.on_nth_tick(61, function(event)
storage.firecount = table_length(storage.check_fires)
--game.players[1].print(storage.firecount)
if settings.global["fide-random-breakouts"].value and math.random() >(1-1/(settings.global["fide-interval"].value*(2-math.min(500,(storage.assembling_machines or 500))/500))) then
if not storage.researchdelay then
storage.researchdelay = event.tick + 3600
return
elseif event.tick < storage.researchdelay then
return
end
--dbg("fire")
for _, surface in pairs(game.surfaces) do
for force_name, force in pairs(game.forces) do
--if force.players and #force.players > 0 and force.technologies["fide-fire-department"].researched then
--dbg(force.name)
local type = burning_types[math.floor((math.random()-0.01)*#burning_types+1)]
local entities = surface.find_entities_filtered{force = force_name,type = type, limit = 1000}
--dbg(type)
local tbllength = #entities
if type == "assembling-machine" then
storage.assembling_machines = tbllength
end
local i=0
--dbg("length: "..tbllength)
if tbllength >1 then
while i<math.min(tbllength,100) do
local rnd = math.max(math.floor(math.random()*tbllength),1)
local ent = entities[rnd]
--dbg(ent.type)
if ent and (ent.energy and ent.energy>0) then
local collision_box = ent.prototype.collision_box
local left_top_x = collision_box.left_top.x
local right_bottom_x = collision_box.right_bottom.x
local left_top_y = collision_box.left_top.y
local right_bottom_y = collision_box.right_bottom.y
local size_x = right_bottom_x-left_top_x
local size_y = right_bottom_y-left_top_y
local random_point_x = left_top_x*0.9+math.random()*(size_x)*0.8
if size_x <= 2 then
random_point_x = left_top_x*0.8+math.random()*(size_x)*0.6
end
local random_point_y = left_top_y*0.9+math.random()*(size_y)*0.8
if size_y <= 2 then
random_point_y = left_top_y*0.9+math.random()*(size_y)*0.5
end
ent.surface.create_entity{name = "fide-fire-flame", position = {ent.position.x+random_point_x, ent.position.y+random_point_y}, raise_built =true}
break
end
i=i+1
end
--dbg(i.."runs")
end
end
end
end
--~ end
end)
script.on_event(defines.events.on_built_entity, function(event)
if event.entity and event.entity.name == "fide-extinguish-fire" then
local pos = event.entity.position
local surface = event.entity.surface
event.entity.destroy()
surface.create_entity { name = "fide-extinguish-fire-effect", position = pos }
local surroundings = surface.find_entities_filtered { area = { { pos.x - 3, pos.y - 3 }, { pos.x + 3, pos.y + 3 } } }
for _, ent in pairs(surroundings) do
if ent.name == 'fire-flame' or ent.name == 'oil-fire-flame' or ent.name == 'fire-flame-on-tree' or ent.name == "fide-fire-flame" then
if not storage.remove_fires[event.tick + 26] then storage.remove_fires[event.tick + 26] = {} end
table.insert(storage.remove_fires[event.tick + 26], ent)
end
end
end
end)
script.on_event(defines.events.on_robot_built_entity, function(event)
if event.entity and event.entity.name == "fide-extinguish-fire" then
if event.robot then
event.robot.active = false
if not storage.enable_robots[event.tick+25] then storage.enable_robots[event.tick+25] = {} end
table.insert(storage.enable_robots[event.tick+25], event.robot)
end
local pos = event.entity.position
local surface = event.entity.surface
event.entity.destroy()
surface.create_entity{name="fide-extinguish-fire-effect", position = pos}
local surroundings = surface.find_entities_filtered{area={{pos.x-3,pos.y-3},{pos.x+3,pos.y+3}}}
for _, ent in pairs(surroundings) do
if ent.name == 'fire-flame' or ent.name == 'oil-fire-flame' or ent.name == 'fire-flame-on-tree' or ent.name == "fide-fire-flame" then
if not storage.remove_fires[event.tick+26] then storage.remove_fires[event.tick+26] = {} end
table.insert(storage.remove_fires[event.tick+26], ent)
end
end
end
end)
function register_flame(event)
if event.entity and event.entity.name == "oil-fire-flame" or event.entity.name == "fide-fire-flame" or event.entity.name == "fire-flame" then
if storage.uniturret then
event.entity.force = "fide-forces-fires"
end
--game.players[1].print(event.entity.unit_number)
local struct = {}
struct.fire = event.entity
struct.ghost = event.entity.surface.create_entity{name = "entity-ghost", position={event.entity.position.x+0.8, event.entity.position.y-0.65}, inner_name = "fide-extinguish-fire", force = "player", expires = false}
struct.tick = event.tick+45
if storage.uniturret then
struct.hitbox = event.entity.surface.create_entity{name = "fide_hitbox", position=event.entity.position, force = "fide-forces-fires"}
end
for _, player in pairs(game.players) do
player.add_custom_alert(event.entity,{type="virtual", name="fide-fire"},"Fire",true)
end
table.insert(storage.check_fires, struct)
end
end
script.on_event(defines.events.script_raised_built, register_flame)
script.on_event(defines.events.on_entity_died, function(event)
if math.random() > 0.5 and settings.global["fide-destroyed"].value and (event.entity.energy >1 or event.entity.type == "ammo-turret" or event.entity.type == "fluid-turret") and event.entity.force and event.entity.force.players and #event.entity.force.players > 0 and event.entity.force.technologies["fide-fire-department"].researched then
event.entity.surface.create_entity{name = "fide-fire-flame", position = {event.entity.position.x+(math.random()-0.5),event.entity.position.y+(math.random()-0.5)}, raise_built =true}
end
end)
script.on_event(defines.events.on_trigger_created_entity, function(event)
if not event.entity then return end
if event.entity.name == "fire-flame" then
register_flame(event)
elseif event.entity.name == "fide-water-gun-decal" then
if event.source and event.source.name == "uniturret-water" then
return
end
local surface = event.entity.surface
local fire = surface.find_entities_filtered{area = {{event.entity.position.x-2,event.entity.position.y-2},{event.entity.position.x+2,event.entity.position.y+2}}, name='fire-flame'}
local fire_flammable_oils = surface.find_entities_filtered{area = {{event.entity.position.x-2,event.entity.position.y-2},{event.entity.position.x+2,event.entity.position.y+2}}, name='oil-fire-flame'}
local area_fires = 0
for _, ent in pairs(fire) do
area_fires = area_fires +1
local rnd = math.random()
if rnd > 0.9 then
ent.destroy()
end
end
for _, ent in pairs(fire_flammable_oils) do
area_fires = area_fires +1
local rnd = math.random()
if rnd > 0.92 then
ent.destroy()
end
end
local fide_fires = surface.find_entities_filtered{area = {{event.entity.position.x-2,event.entity.position.y-2},{event.entity.position.x+2,event.entity.position.y+2}}, name='fide-fire-flame'}
for _, ent in pairs(fide_fires) do
area_fires = area_fires +1
local rnd = math.random()
if rnd > 0.9 then
ent.destroy()
end
end
--local sticker_entities = surface.find_entities_filtered{area = {{event.entity.position.x-2,event.entity.position.y-2},{event.entity.position.x+2,event.entity.position.y+2}}}
--for _, tbl in pairs(sticker_entities) do
-- game.players[1].print(tbl.name)
-- if tbl.stickers then
-- game.players[1].print("hi")
-- for _, ent in pairs(tbl.stickers) do
-- game.players[1].print(ent.name)
-- if ent.name == "fire-sticker" then
-- area_fires = area_fires +1
-- local rnd = math.random()
-- if rnd > 0.94 then
-- ent.destroy()
-- end
-- end
-- end
-- end
--end
local tree_flames = surface.find_entities_filtered{area = {{event.entity.position.x-2,event.entity.position.y-2},{event.entity.position.x+2,event.entity.position.y+2}}, name = 'fire-flame-on-tree'}
for _, ent in pairs(tree_flames) do
area_fires = area_fires +1
local rnd = math.random()
if rnd > 0.9 then
ent.destroy()
end
end
end
end)