I was in the process of choosing which mods to use and which mods not to use - and what works - on a multiplayer map.
Then all of a sudden, my friend and I decided to mod some stuff of our own. So... I've created a simple mod that adds a tier 2 and tier 3 radar, each scans a larger area but draws significantly more power (300kW for base, 900kW for MkII, 5MW for MkIII).
Unfortunately, the area that the radar scans constantly and allows you to see all active entities within, does not increase and I cannot find anything within the base game files to do with how wide an area the radar can see... So how would I go about modding that area?
Thanks!
Re: Modding radar areas - how to change active area
Posted: Mon Feb 09, 2015 6:42 pm
by FreeER
xBlizzDevious wrote:Unfortunately, the area that the radar scans constantly and allows you to see all active entities within, does not increase and I cannot find anything within the base game files to do with how wide an area the radar can see... So how would I go about modding that area?
Unfortunately that is currently hard coded in C++ as 3 chunks around the radar.
hm, what could be done, with some work, is to add another radar with a small sector area (1, or maybe 0), a transparent image, and no collision box, and in control.lua during the onbuiltentity event place those around the main radar with game.createentity. The problem with that is the code placed radars would still need energy (even if it is just a small amount) so you'd either need to store them in a table (you'd want to do so anyways so you could destroy them when the main radar is destroyed) and manually add energy or also place some more entities to provide power to them (modded accumulators with large storage and a pole with a small radius for example)...
It's not the easiest thing to do but it can be done.
Re: Modding radar areas - how to change active area
Posted: Mon Feb 09, 2015 7:10 pm
by xBlizzDevious
FreeER wrote:
xBlizzDevious wrote:Unfortunately, the area that the radar scans constantly and allows you to see all active entities within, does not increase and I cannot find anything within the base game files to do with how wide an area the radar can see... So how would I go about modding that area?
Unfortunately that is currently hard coded in C++ as 3 chunks around the radar.
hm, what could be done, with some work, is to add another radar with a small sector area (1, or maybe 0), a transparent image, and no collision box, and in control.lua during the onbuiltentity event place those around the main radar with game.createentity. The problem with that is the code placed radars would still need energy (even if it is just a small amount) so you'd either need to store them in a table (you'd want to do so anyways so you could destroy them when the main radar is destroyed) and manually add energy or also place some more entities to provide power to them (modded accumulators with large storage and a pole with a small radius for example)...
It's not the easiest thing to do but it can be done.
Aww damn. That kinda ruins the point of them. A huge area radar that only uncovers in the first place just isn't the same as one that can show a huge area all of the time.
Would it be possible to reduce the energy needed per sector scan to something miniscule (1kJ, for example) and then feed it with 5MW of power to scan; would that kinda do the same thing? It would make the radar fill in all sectors very fast, though.
Re: Modding radar areas - how to change active area
Posted: Mon Feb 09, 2015 7:49 pm
by FreeER
xBlizzDevious wrote:A huge area radar that only uncovers in the first place
It wouldn't be just the first place if you used the ontick event to add energy or setup some other way for them to continuously receive power.
xBlizzDevious wrote:Would it be possible to reduce the energy needed per sector scan to something miniscule (1kJ, for example) and then feed it with 5MW of power to scan; would that kinda do the same thing? It would make the radar fill in all sectors very fast, though.
you can lower the energy per sector, however there is a limit on the amount of energy an entity can hold, which for radars, I believe, that would be at least partially based on the energy per sector so it wouldn't really help.
require "defines"
local modName = "Radar Extension"
-- seconds between energy fill, adjust as needed
local secondsDelay = 10
-- space between small radars, adjust as needed
local distance_step = 5
-- create the glob.radars table when game is started, or mod is first added to a save
game.oninit(function()
glob.radars = {}
end)
game.onevent(defines.event.onbuiltentity, function(event)
local built = event.createentity
if built.name == "your_radar" then
-- 10 is arbitrary, adjust for effect
local pos = built.position
glob.radars[built.position] = {} -- empty table for small radars
table.insert(glob.radars[built.position], built) -- main radar is always first
for x = -20, 20, distance_step do
for y = -20, 20, distance_step do
-- if not on top of the main radar
if (x > 0 and y > 0) then
local small = game.createentity{name="your_small_radar", position={pos.x+x, pos.y+y}}
table.insert(glob.radars[built.position], small)
end
end
end
end
end)
game.onevent(defines.event.ontick, function(event)
if event.tick % (60 * secondsDelay)
for pos, radarList in pairs(glob.radars) do
-- if the main radar has been destroyed / mined
if not radarList[1].valid then
-- destroy all small radars
for _, radar in ipairs(radarList) do
if radar.valid then radar.destroy() end
end
-- remove from table
glob.radars[pos] = nil
else
-- loop backwards since we might remove something from numeric table
-- a remove while looping forward would skip an entry
for index=#radarList, 1, -1
if radar.valid then
-- max out it's energy
radar.energy = 10000000000000
else -- should not happen, but.
printToAll("Internal Error ("..modName.."): small radar did not exist")
table.remove(radarList, index)
end
end
end
end
end
end)
function printToAll(message)
for _, player in ipairs(game.players) do
player.print(message)
end
end
Re: Modding radar areas - how to change active area
Posted: Thu Mar 19, 2015 11:36 pm
by SirRichie
This thread is over a month old, but you may still find this useful:
I'm not sure since when, but radars do now have a property max_distance_of_nearby_sector_revealed which is the number of chunks that remain revealed.
If you create your own radar and set this to a high number like... 32, you will even see how the map is very quickly revealed in that area.