more-descriptions/data-final-fixes.lua

changeset 7
023ee666a3d6
parent 5
4418c07556d4
equal deleted inserted replaced
6:10ef96c4aa69 7:023ee666a3d6
1 local function seconds(x)
2 return {"time-symbol-seconds", tostring(x)}
3 end
4
5 local function build_new_description(main_description, new_descriptions)
6 local new_localised_description = {
7 "",
8 main_description,
9 }
10 for i, k in pairs(new_descriptions)
11 do
12 if i ~= 1
13 then
14 table.insert(new_localised_description, "\n")
15 end
16 table.insert(new_localised_description, k)
17 end
18 return new_localised_description
19 end
20
1 local item_categories = 21 local item_categories =
2 { 22 {
3 "item", 23 "item",
4 "item-with-entity-data", 24 "item-with-entity-data",
5 "rail-planner", 25 "rail-planner",
97 "simple-entity-with-owner", 117 "simple-entity-with-owner",
98 "electric-energy-interface", 118 "electric-energy-interface",
99 "linked-container", 119 "linked-container",
100 "proxy-container", 120 "proxy-container",
101 "heat-interface", 121 "heat-interface",
122 "heat-pipe",
102 "lane-splitter", 123 "lane-splitter",
103 "linked-belt", 124 "linked-belt",
104 "valve", 125 "valve",
105 "infinity-cargo-wagon", 126 "infinity-cargo-wagon",
106 "infinity-container", 127 "infinity-container",
161 end 182 end
162 end 183 end
163 return nil 184 return nil
164 end 185 end
165 186
187 local ammo_categories = {}
188
189 for _, ammo in pairs(data.raw.ammo)
190 do
191 if not ammo_categories[ammo.ammo_category]
192 then
193 ammo_categories[ammo.ammo_category] = ""
194 end
195 if #ammo_categories[ammo.ammo_category] < 120
196 then
197 ammo_categories[ammo.ammo_category] = ammo_categories[ammo.ammo_category].."[item="..ammo.name.."]"
198 elseif string.sub(ammo_categories[ammo.ammo_category], -3, -1) ~= "..."
199 then
200 ammo_categories[ammo.ammo_category] = ammo_categories[ammo.ammo_category] .. "..."
201 end
202 end
203
166 for _, item_type in pairs(item_categories) 204 for _, item_type in pairs(item_categories)
167 do 205 do
168 for _, item in pairs(data.raw[item_type] or {}) 206 for _, item in pairs(data.raw[item_type] or {})
169 do 207 do
170 local new_descriptions = {} 208 local new_descriptions = {}
171 local refining_recipe = data.raw.recipe[item.name.."-refining"]
172 local recycling_recipe = data.raw.recipe[item.name.."-recycling"] 209 local recycling_recipe = data.raw.recipe[item.name.."-recycling"]
210
211 local add_description = function(x)
212 table.insert(new_descriptions, x)
213 end
214
215 local add_ammo_from_attack_parameters = function(attack_parameters)
216 if attack_parameters.ammo_category and ammo_categories[attack_parameters.ammo_category]
217 then
218 add_description{"more-descriptions-mod.gun-accepts-ammo", ammo_categories[attack_parameters.ammo_category]}
219 end
220 for _, category in pairs(attack_parameters.ammo_categories or {})
221 do
222 if ammo_categories[category]
223 then
224 add_description{"more-descriptions-mod.gun-accepts-ammo", ammo_categories[category]}
225 end
226 end
227 end
173 228
174 if recycling_recipe ~= nil 229 if recycling_recipe ~= nil
175 then 230 then
176 local recycling_results = {""} 231 local recycling_results = {""}
177 for _, result in pairs(recycling_recipe.results) 232 for _, result in pairs(recycling_recipe.results)
178 do 233 do
179 table.insert(recycling_results, "[img="..result.type.."."..result.name.."]") 234 table.insert(recycling_results, "[img="..result.type.."."..result.name.."]")
180 end 235 end
181 table.insert(new_descriptions, { 236 add_description{
182 "more-descriptions-mod.recycling", 237 "more-descriptions-mod.recycling",
183 tostring(recycling_recipe.energy_required), 238 seconds(recycling_recipe.energy_required),
184 recycling_results 239 recycling_results
185 }) 240 }
186 end 241 end
187 242
188 if mods["promethium-quality"] 243 if mods["promethium-quality"]
189 then 244 then
245 local refining_recipe = data.raw.recipe[item.name.."-refining"]
190 if refining_recipe ~= nil 246 if refining_recipe ~= nil
191 then 247 then
192 table.insert(new_descriptions, { 248 add_description{
193 "more-descriptions-mod.refining-cost", 249 "more-descriptions-mod.refining-cost",
194 tostring(refining_recipe.energy_required), 250 tostring(refining_recipe.energy_required),
195 }) 251 }
196 elseif recycling_recipe ~= nil 252 elseif recycling_recipe ~= nil
197 then 253 then
198 table.insert(new_descriptions, { 254 add_description{"more-descriptions-mod.cannot-be-refined"}
199 "more-descriptions-mod.cannot-be-refined", 255 end
200 }) 256 end
201 end 257
258 if item.type == "ammo" and (item.reload_time or 0) > 0
259 then
260 add_description{
261 "more-descriptions-mod.reload-time",
262 seconds(tostring(item.reload_time / 60.0)),
263 }
264 end
265
266 if item.type == "active-defense-equipment" and item.automatic
267 then
268 add_description{"more-descriptions-mod.fires-automatically"}
269 end
270
271 if item.type == "armor" and item.provides_flight
272 then
273 add_description{"more-descriptions-mod.armor-provides-flight"}
274 end
275
276 if item.type == "gun"
277 then
278 add_ammo_from_attack_parameters(item.attack_parameters)
202 end 279 end
203 280
204 local entity = item.place_result and find_entity(item.place_result) or nil 281 local entity = item.place_result and find_entity(item.place_result) or nil
205 if entity ~= nil 282 if entity ~= nil
206 then 283 then
207 if entity.collision_box 284 if entity.collision_box
208 then 285 then
209 local cb = entity.collision_box 286 local cb = entity.collision_box
210 local width = math.ceil(cb[2][1] - cb[1][1]) 287 local width = math.ceil(cb[2][1] - cb[1][1])
211 local height = math.ceil(cb[2][2] - cb[1][2]) 288 local height = math.ceil(cb[2][2] - cb[1][2])
212 table.insert(new_descriptions, { 289 add_description{
213 "more-descriptions-mod.size", 290 "more-descriptions-mod.size",
214 tostring(width), 291 tostring(width),
215 tostring(height), 292 tostring(height),
216 }) 293 }
294 end
295
296 if entity.drops_full_belt_stacks
297 then
298 add_description{"more-descriptions-mod.drops-full-belt-stacks"}
299 end
300
301 if entity.heat_buffer and entity.heat_buffer.specific_heat
302 then
303 add_description{
304 "more-descriptions-mod.specific-heat",
305 entity.heat_buffer.specific_heat,
306 }
307 elseif entity.energy_source
308 and entity.energy_source.type == "heat"
309 and entity.energy_source.specific_heat
310 then
311 add_description{
312 "more-descriptions-mod.specific-heat",
313 entity.energy_source.specific_heat,
314 }
315 end
316
317 if entity.is_military_target
318 then
319 add_description{"more-descriptions-mod.is-military-target"}
320 end
321
322 if entity.type == "agricultural-tower"
323 then
324 local cb = entity.collision_box
325 local W = math.ceil(cb[2][1] - cb[1][1])
326 local w = (entity.growth_grid_tile_size or 3)
327 -- width of the "buffer" area around the agricultural tower
328 local z = (2 * w * math.ceil((W - w) / 2 / w)) + w
329 -- num of growth cells extending from the edges of the tower
330 local r = math.floor(entity.radius) -- why is it double..?
331 add_description{"more-descriptions-mod.agricultural-tower-num-inputs",
332 tostring(entity.input_inventory_size)
333 }
334 add_description{"more-descriptions-mod.agricultural-tower-growth-cell-size",
335 tostring(w)
336 }
337 add_description{"more-descriptions-mod.agricultural-tower-growth-cell-count",
338 tostring(4 * r * (r + (z / w)))
339 }
340 add_description{"more-descriptions-mod.agricultural-tower-total-size",
341 tostring(z + 2 * r * w)
342 }
343 elseif entity.type == "ammo-turret"
344 then
345 if entity.energy_per_shot ~= nil
346 then
347 add_description{"more-descriptions-mod.energy-per-shot-fired",
348 entity.energy_per_shot}
349 end
350 add_ammo_from_attack_parameters(entity.attack_parameters)
351 elseif entity.type == "beacon"
352 then
353 add_description{"more-descriptions-mod.beacon-supply-area-distance",
354 tostring(entity.supply_area_distance)
355 }
356 elseif entity.type == "car"
357 then
358 local immunities = ""
359 if (entity.immune_to_tree_impacts or false)
360 then
361 immunities = immunities.."[entity=tree-01]"
362 end
363 if (entity.immune_to_rock_impacts or false)
364 then
365 immunities = immunities.."[entity=big-rock]"
366 end
367 if (entity.immune_to_cliff_impacts or true)
368 then
369 immunities = immunities.."[entity=cliff]"
370 end
371 if immunities ~= ""
372 then
373 add_description{"more-descriptions-mod.car-immune-to-impacts", immunities}
374 end
375 elseif entity.type == "constant-combinator"
376 then
377 -- used by pushbutton mod
378 if (entity.pulse_duration or 0) > 60
379 then
380 add_description{"more-descriptions-mod.constant-combinator-pulse-duration",
381 seconds(entity.pulse_duration / 60.0)}
382 elseif (entity.pulse_duration or 0) > 0
383 then
384 add_description{"more-descriptions-mod.constant-combinator-pulse-duration",
385 {"more-descriptions-mod.ticks", tostring(entity.pulse_duration)}}
386 end
387 elseif (entity.type == "container" or entity.type == "logistic-container")
388 then
389 if entity.inventory_type == "with_filters_and_bar"
390 then
391 add_description{"more-descriptions-mod.container-filters"}
392 end
393 elseif entity.type == "cargo-wagon"
394 then
395 -- all cargo wagons support filters
396 add_description{"more-descriptions-mod.container-filters"}
397 elseif entity.type == "display-panel"
398 then
399 add_description{"more-descriptions-mod.display-panel-max-text-width",
400 tostring(entity.max_text_width or 400)}
401 elseif entity.type == "logistic-robot" or entity.type == "construction-robot"
402 then
403 if entity.speed_multiplier_when_out_of_energy > 0
404 then
405 add_description{"more-descriptions-mod.robot-speed-multiplier-when-out-of-energy",
406 tostring(entity.speed_multiplier_when_out_of_energy * 100)}
407 else
408 add_description{"more-descriptions-mod.robot-crashes-when-out-of-energy"}
409 end
410 elseif entity.type == "inserter"
411 then
412 if entity.wait_for_full_hand
413 then
414 add_description{"more-descriptions-mod.inserter-wait-for-full-hand",
415 tostring(entity.filter_count)}
416 end
417 elseif entity.type == "land-mine"
418 then
419 add_description{"more-descriptions-mod.land-mine-timeout",
420 seconds((entity.timeout or 120) / 60.0)}
421 elseif entity.type == "radar"
422 then
423 if entity.connects_to_other_radars ~= false
424 then
425 add_description{"more-descriptions-mod.radar-connection"}
426 end
427 end
428 if entity.filter_count
429 then
430 add_description{"more-descriptions-mod.filter-count",
431 tostring(entity.filter_count)}
432 end
433 for _, flag in pairs(entity.flags or {})
434 do
435 if flag == "no-automated-item-insertion"
436 then
437 table.insert(new_descriptions, {"more-descriptions-mod.no-automated-item-insertion"})
438 end
217 end 439 end
218 end 440 end
219 441
220 if #new_descriptions > 0 442 if #new_descriptions > 0
221 then 443 then
225 "?", 447 "?",
226 {"", {"entity-description."..item.name}, "\n"}, 448 {"", {"entity-description."..item.name}, "\n"},
227 {"", {"item-description."..item.name}, "\n"}, 449 {"", {"item-description."..item.name}, "\n"},
228 "" 450 ""
229 } 451 }
230 item.localised_description = { 452 item.localised_description = build_new_description(main_description, new_descriptions)
231 "",
232 main_description,
233 }
234 for i, k in pairs(new_descriptions)
235 do
236 if i ~= 1
237 then
238 table.insert(item.localised_description, "\n")
239 end
240 table.insert(item.localised_description, k)
241 end
242 end 453 end
243 end 454 end
244 end 455 end
245 456
246 for _, recipe in pairs(data.raw.recipe) 457 for _, recipe in pairs(data.raw.recipe)
259 or { 470 or {
260 "?", 471 "?",
261 {"", {"recipe-description."..recipe.name}, "\n"}, 472 {"", {"recipe-description."..recipe.name}, "\n"},
262 "" 473 ""
263 } 474 }
264 recipe.localised_description = { 475 recipe.localised_description = build_new_description(main_description, new_descriptions)
265 "", 476 end
266 main_description, 477 end
478
479 -- Stuff mostly specific for entities that you don't place with items (like biters)
480 for _, entity_category in pairs(entity_categories)
481 do
482 for _, entity in pairs(data.raw[entity_category] or {})
483 do
484 local new_descriptions = {}
485
486 if entity.minable
487 then
488 table.insert(new_descriptions, {"more-descriptions-mod.mining-time",
489 seconds(entity.minable.mining_time)})
490 end
491
492 for _, flag in pairs(entity.flags or {})
493 do
494 if flag == "breaths-air"
495 then
496 table.insert(new_descriptions, {"more-descriptions-mod.breathes-air"})
497 end
498 end
499
500 if entity.type == "unit-spawner"
501 then
502 if (entity.time_to_capture or 0) > 0
503 then
504 table.insert(new_descriptions, {"more-descriptions-mod.unit-spawner-time-to-capture",
505 seconds(entity.time_to_capture / 60.0)})
506 end
507 end
508
509 if #new_descriptions > 0
510 then
511 local main_description = entity.localised_description
512 and {"", entity.localised_description, "\n"}
513 or {
514 "?",
515 {"", {"entity-description."..entity.name}, "\n"},
516 ""
517 }
518 entity.localised_description = build_new_description(main_description, new_descriptions)
519 end
520 end
521 end
522
523 for _, space_location in pairs(data.raw["space-location"])
524 do
525 local new_descriptions = {}
526
527 if (space_location.fly_condition or false)
528 then
529 table.insert(new_descriptions, {"more-descriptions-mod.space-location-fly-condition"})
530 end
531
532 if space_location.auto_save_on_first_trip == false -- (nil=true)
533 then
534 table.insert(new_descriptions, {"more-descriptions-mod.space-location-no-autosave"})
535 end
536
537 if #new_descriptions > 0
538 then
539 local main_description = space_location.localised_description
540 and {"", space_location.localised_description, "\n"}
541 or {
542 "?",
543 {"", {"space-location-description."..space_location.name}, "\n"},
544 ""
267 } 545 }
268 for i, k in pairs(new_descriptions) 546 space_location.localised_description = build_new_description(main_description, new_descriptions)
269 do 547 end
270 if i ~= 1 548 end
271 then
272 table.insert(recipe.localised_description, "\n")
273 end
274 table.insert(recipe.localised_description, k)
275 end
276 end
277 end

mercurial