[MOD 0.12.x] Roboport Quick Charge 0.2.0

Topics and discussion about specific mods
nDeavor
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Jun 09, 2016 11:26 pm
Contact:

Re: [MOD 0.12.x] Roboport Quick Charge 0.2.0

Post by nDeavor »

The mod does not work with multiple factions. I have a MP server with 3 teams and all upgraded roboports the others build are marked as enemy structure. Any way to make this work with multiple factions?
For now I changed the config to manual upgrade so they can still use the base version.

Zahne
Manual Inserter
Manual Inserter
Posts: 1
Joined: Mon Jun 13, 2016 7:08 pm
Contact:

Re: [MOD 0.12.x] Roboport Quick Charge 0.2.0

Post by Zahne »

What I like about your mod is that it fixes a major bottleneck with vanilla roboports while being modular--most other solutions to roboports seem to be integrated into overhaul packs which almost invariably require a core mod with some side effects(eg. moving stuff around and changing vanilla recipes and/or vanilla tech tree). Unfortunately, if you do happen to use this mod with any other mod pertaining to roboports, this mod will replace their roboports with its own. I don't know if this is intentional or not, as it seems to be a side effect of automatically upgrading to the latest roboport. Assuming this isn't intentional, I'd like to propose a fix. The root cause of this is that you wrote your upgradeRoboports and onBuiltEntity functions to act on any entities of type="roboport."

Code: Select all

function upgradeRoboports(upgrade)

	local surface = game.players[1].surface
	for c in surface.get_chunks() do
		--replace all roboports preserving contents
		if roboport_auto_replace_method == "both" or roboport_auto_replace_method == "onresearch" then
			for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="roboport"})) do
				local pos = entity.position
				local countC = entity.get_inventory(1).get_item_count("construction-robot")
				local countL = entity.get_inventory(1).get_item_count("logistic-robot")
				local countR = entity.get_inventory(2).get_item_count("repair-pack")
				local backerName = entity.backer_name
				entity.destroy()
				newRobo = surface.create_entity({name=itemList[upgrade+1], position=pos, force="player"})
				if countC > 0 then
					newRobo.get_inventory(1).insert({name="construction-robot", count=countC})
				end
				if countL > 0 then
					newRobo.get_inventory(1).insert({name="logistic-robot", count=countL})
				end
				if countR > 0 then
					newRobo.get_inventory(2).insert({name="repair-pack", count=countR})
				end
				newRobo.backer_name = backerName
			end
		end
		--change any roboport assembling machines to have upgraded recipe and convert any old roboports in the output slot to new ones
		if roboport_recipe_update then
			for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="assembling-machine"})) do
				if entity.recipe then
					if entity.recipe.name == "roboport" or string.sub(entity.recipe.name, 1, 20) == "qcm-roboport-upgrade" then
						local itemcount = entity.get_output_inventory().get_item_count(itemList[upgrade+0])
						entity.recipe=game.players[1].force.recipes[recipeList[upgrade+1]]
						if itemcount > 0 then
							entity.get_output_inventory().clear()
							entity.get_output_inventory().insert({name=itemList[upgrade+1], count=itemcount})
						end
					end
				end
			end
		end
	end
	
end

Code: Select all

function onBuiltEntity(event)
	local entity = event.created_entity
	if entity.type == "roboport" then
		local versionNumber = getVersion()
		
		if versionNumber > 0 then
			local pos = entity.position
			local backerName = entity.backer_name
			entity.destroy()
			newRobo = game.players[1].surface.create_entity({name=itemList[versionNumber], position=pos, force="player"})
			newRobo.backer_name = backerName
		end
	end
end
A way to fix these, in a way that I think matches your intent, would be to use this condition

Code: Select all

entity.name == "roboport" or string.sub(entity.name, 1, 20) == "qc-roboport-upgrade"
to get the following modified functions:

Code: Select all

function upgradeRoboports(upgrade)

	local surface = game.players[1].surface
	for c in surface.get_chunks() do
		--replace all roboports preserving contents
		if roboport_auto_replace_method == "both" or roboport_auto_replace_method == "onresearch" then
			for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="roboport"})) do
				if entity.name == "roboport" or string.sub(entity.name, 1, 20) == "qc-roboport-upgrade" then
					local pos = entity.position
					local countC = entity.get_inventory(1).get_item_count("construction-robot")
					local countL = entity.get_inventory(1).get_item_count("logistic-robot")
					local countR = entity.get_inventory(2).get_item_count("repair-pack")
					local backerName = entity.backer_name
					entity.destroy()
					newRobo = surface.create_entity({name=itemList[upgrade+1], position=pos, force="player"})
					if countC > 0 then
						newRobo.get_inventory(1).insert({name="construction-robot", count=countC})
					end
					if countL > 0 then
						newRobo.get_inventory(1).insert({name="logistic-robot", count=countL})
					end
					if countR > 0 then
						newRobo.get_inventory(2).insert({name="repair-pack", count=countR})
					end
					newRobo.backer_name = backerName
				end
			end
		end
		--change any roboport assembling machines to have upgraded recipe and convert any old roboports in the output slot to new ones
		if roboport_recipe_update then
			for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="assembling-machine"})) do
				if entity.recipe then
					if entity.recipe.name == "roboport" or string.sub(entity.recipe.name, 1, 20) == "qcm-roboport-upgrade" then
						local itemcount = entity.get_output_inventory().get_item_count(itemList[upgrade+0])
						entity.recipe=game.players[1].force.recipes[recipeList[upgrade+1]]
						if itemcount > 0 then
							entity.get_output_inventory().clear()
							entity.get_output_inventory().insert({name=itemList[upgrade+1], count=itemcount})
						end
					end
				end
			end
		end
	end
	
end

Code: Select all

function onBuiltEntity(event)
	local entity = event.created_entity
	if entity.name == "roboport" or string.sub(entity.name, 1, 20) == "qc-roboport-upgrade" then
		local versionNumber = getVersion()
		
		if versionNumber > 0 then
			local pos = entity.position
			local backerName = entity.backer_name
			entity.destroy()
			newRobo = game.players[1].surface.create_entity({name=itemList[versionNumber], position=pos, force="player"})
			newRobo.backer_name = backerName
		end
	end
end
There was also a reference to entity.name ~= "roboport" in the uninstall portion of your code which may need to be changed for compatibility with other mods, so that you don't replace other people's roboports with vanilla roboports when your mod is uninstalled, but I didn't actually check to see when that gets called.

I hope that these suggestions are helpful and welcome, and I apologize if this was intentional behavior or if criticism is unwelcome, or if this is the wrong way to communicate this, and I mean absolutely no offense.

DarkHelmet
Inserter
Inserter
Posts: 40
Joined: Sat Apr 16, 2016 5:46 pm
Contact:

Re: [MOD 0.12.x] Roboport Quick Charge 0.2.0

Post by DarkHelmet »

I made some quick fixes to get this working on 0.13. However, I realized I was out of my depth when the upgraded roboports didn't have logistics connections. I was having all the same problems that were mentioned by Zahne above - this mod interferes with other roboport mods in unfortunate ways.

I ended up switching to having stand-alone charging towers to boost the network. I'm using the "Roboport Charging Station 0.3.3 (Robo-Charge)" mod. Not the similarly named one that's called "RoboCharge 0.0.7". With its 4 charge pads, no robot storage and just a 1x1 grid space I'm finding that a quite workable alternative.
A guide to planning your factory's space requirements:
1) Figure out how much space you need, double it to be safe.
2) Wrong! There's never enough space.

Post Reply

Return to “Mods”