[0.17] Adding Ore Hardness and Pickaxes back in
[0.17] Adding Ore Hardness and Pickaxes back in
There seems to be a lot of controversy about this, and even so nobody has made a thread to actually discuss a solution. I personally did not get involved until now because:
A) I'm the one who pushed for the change so I am biased
B) Factorio attracts a well educated and capable player base, so I always had faith that our modders will sort this out.
Please keep this thread free of discussion about The Problem Existing in the first place and Why the problem is the worst case of negligence in a dev team. There are other places to discuss that.
So the problem:
How do we mod tiered mining back into a game which has had the underlying mechanics removed?
Edit: To the moderators, feel free to shut this thread down if it gets out of hand and sorry in advance
A) I'm the one who pushed for the change so I am biased
B) Factorio attracts a well educated and capable player base, so I always had faith that our modders will sort this out.
Please keep this thread free of discussion about The Problem Existing in the first place and Why the problem is the worst case of negligence in a dev team. There are other places to discuss that.
So the problem:
How do we mod tiered mining back into a game which has had the underlying mechanics removed?
Edit: To the moderators, feel free to shut this thread down if it gets out of hand and sorry in advance
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Ill start with a crappy implementation. Im sure someone can come up with a much nicer one but this one works for hand mining.
Explanation: I added a bunch of generic objects called pickaxes into the game. They can go anywhere in your inventory. When you mine something the mod checks if you have the correct tier of pickaxe item otherwise it puts the resource back (currently just removes it, but whatever it is a prototype).
Benefits over the old system:
You can precisely control which item mines which resource.
It is script modding, not data modding so it can be added server side.
Downsides over(under?) the old system:
It is script modding, not data modding so it feel a little more ... messy?Shouldnt write this stuff when tired, clearly this is both script and data modding.
control.lua
data.lua
Explanation: I added a bunch of generic objects called pickaxes into the game. They can go anywhere in your inventory. When you mine something the mod checks if you have the correct tier of pickaxe item otherwise it puts the resource back (currently just removes it, but whatever it is a prototype).
Benefits over the old system:
You can precisely control which item mines which resource.
Downsides over(under?) the old system:
It is script modding, not data modding so it feel a little more ... messy?
control.lua
Code: Select all
local commodities = {}
commodities['copper-ore'] = {tier = 3}
commodities['iron-ore'] = {tier = 2}
commodities['coal'] = {tier = 1}
commodities['stone'] = {tier = 0}
local axes = {}
axes['pickaxe-stone'] = {tier = 1}
axes['pickaxe-coal'] = {tier = 2}
axes['pickaxe-iron'] = {tier = 3}
axes['pickaxe-copper'] = {tier = 4}
local get_highest_pickaxe_tier = function(player)
local tier = 0
for axename, axedata in pairs(axes) do
if player.get_item_count(axename) > 0 and axedata.tier > tier then
tier = axedata.tier
end
end
return tier
end
local get_highest_commodity_tier = function(inventory)
local tier = 0
for name, data in pairs(commodities) do
if inventory.get_item_count(name) > 0 and data.tier > tier then
tier = data.tier
end
end
return tier
end
script.on_event(defines.events.on_player_mined_entity, function(event)
local player = game.players[event.player_index]
local mined_tier = get_highest_commodity_tier(event.buffer)
local axe_tier = get_highest_pickaxe_tier(player)
player.print("Mined tier "..mined_tier.." with axe tier "..axe_tier)
if mined_tier > axe_tier then
player.print("you cant mine that")
event.buffer.clear()
else
player.print("you mined something")
end
end)
script.on_event(defines.events.on_player_mined_item, function(event)
end)
Code: Select all
data:extend(
{
{
type = "item",
name = "pickaxe-stone",
icon = "__base__/graphics/icons/coin.png",
icon_size = 32,
flags = {"goes-to-quickbar", "hidden"},
subgroup = "science-pack",
order = "y",
stack_size = 1
},
{
type = "item",
name = "pickaxe-coal",
icon = "__base__/graphics/icons/coin.png",
icon_size = 32,
flags = {"goes-to-quickbar", "hidden"},
subgroup = "science-pack",
order = "y",
stack_size = 1
},
{
type = "item",
name = "pickaxe-iron",
icon = "__base__/graphics/icons/coin.png",
icon_size = 32,
flags = {"goes-to-quickbar", "hidden"},
subgroup = "science-pack",
order = "y",
stack_size = 1
},
{
type = "item",
name = "pickaxe-copper",
icon = "__base__/graphics/icons/coin.png",
icon_size = 32,
flags = {"goes-to-quickbar", "hidden"},
subgroup = "science-pack",
order = "y",
stack_size = 1
},
})
data:extend(
{
{
type = "recipe",
name = "pickaxe-stone",
ingredients =
{
{"stone", 1},
},
result = "pickaxe-stone",
enabled = true,
},
{
type = "recipe",
name = "pickaxe-coal",
ingredients =
{
{"coal", 1},
},
result = "pickaxe-coal",
enabled = true,
},
{
type = "recipe",
name = "pickaxe-iron",
ingredients =
{
{"iron-ore", 1},
},
result = "pickaxe-iron",
enabled = true,
},
{
type = "recipe",
name = "pickaxe-copper",
ingredients =
{
{"copper-ore", 1},
},
result = "pickaxe-copper",
enabled = true,
},
})
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Anything you did in your last post is also possible with resource/mining categories. You can make a research that changes them, make that research take whatever resource that's needed for your "upgrade" and there you go. This was already proposed here viewtopic.php?p=390220#p390220 but dismissed because the readers missed the explicitly mentioned extra research. This is of course assuming that 63291 gets implemented. The chance for that is rather high, Rseding already approved adding it + force (research) effects. Now I just have to code it once I'm done with the script rendering.
Using this built-in tier system is a lot cleaner than the code in your last post :)
Using this built-in tier system is a lot cleaner than the code in your last post :)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
- featherwinglove
- Filter Inserter
- Posts: 579
- Joined: Sat Jun 25, 2016 6:14 am
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Alright, I'll get the ball rolling by collating what ones I already know of, and I'm getting close to sleep time, so I hope I don't screw any of the quote pastes...
And my brain is too mushy to find anyone else's; I know they're there, hopefully, they can jump in. Rythe probably has one, I'll pull this quote from him to make sure he gets a notification this thread exists.featherwinglove wrote: βFri Dec 14, 2018 6:40 am Let's meet half way, shall we?
Engine:
1. Reimplement the axe in the engine, along with a moddable wear rate that can be set to zero.
2. Write in the ability for a technology research complete event to spawn inventory items.
3. Write in some easy inventory management setting that automatically equips the best hand tools and armor in the player's inventory; make it easy to turn off just in case it causes issues in the power armor phase (i.e. someone's combat armor suit is a Mk. 2 PA, while his personal roboport kit is in a Mk. 1 PA and he needs to have the latter stay in the armor slot while keeping the former in inventory.)
Base mod:
4. Set the hand axe wear rate to zero in the base mod.
5. Put an iron axe in the start kit for the player, with the exception of the First Steps-01 mission unless you want to-[Events overtook these steps before I even wrote this.]
6. Remove the First Steps-01 mission, which is mostly about building the hand axe and hand mining enough to build a burner drill. The latter half can be blended into the First Steps-02 - destroy the burner drills (and I mean literally so that there is wreckage on the iron patch identified by character or tab balloon dialogue) and instruct the player to hand mine enough iron to build one. Congratulate him on his ingenuity should he go grab one from the coal patch and put it on the iron patch instead. This should be put between the inspection of the chest with the pistol in it, and the burner inserter rotation. (Copyedit pass: The above is from memory, Ima go play First Steps-01 and -02 to verify, brb. Good thing I did: the misrotated inserter pulled the plates from the furnace and put them on the belt leading to it We might have to add it after the rotation lesson instead.)
7. Have the Steel Processing technology automatically spawn a steel axe by default. (Modders can turn this off if desired.) Combined with the easy inventory management and zero wear rate, the only effect that's different from the engine change is the appearance of the old iron axe in the inventory after researching Steel Processing.
8. At some point in the First Steps-03 mission, instruct the player to build a steel axe. Character dialogue (the chat line) explains why it automatically appears in the tool slot and where the old iron axe went. Tab balloon dialogue can explain how easy inventory management can turned off. The same tab balloon dialogue can be programmed to appear on the event of Power Armor research complete because that's far enough down the road that new players might have forgotten about it, and the point at which they might wish to turn it off.
Option 1. Easy inventory management for tools but not armor - possibly separate options for both.
Option 2. In lieu of enabling the steel axe for First Steps-03, automatically have the Steel Processing research complete event delete iron axes from the inventory. This would make the vanilla game's behaviour identical to the current 0.17 baseline.
Finally, if anyone thinks I've been too emotional, please go back and actually read this post. (Copyedit pass: emphasis added.)
Edit: There is also a discussion of the pickaxe on the General Discussion forum.
He might be a bit more hyperbolic (and I might be a bit more hypergolic), but our arguments ascend from the same basic theme.Rythe wrote: βTue Oct 30, 2018 1:49 amNow gather around, because this explanation starts in the way back[,] when we thought of our industrious little avatars as crash survivors trying to overcome a hostile, alien world, and maybe, one day, even escape it. This was when Factorio was a different game.
Rythe wrote: βTue Oct 30, 2018 1:49 amNow gather around, because this explanation starts in the way back[,] when we thought of our industrious little avatars as crash survivors trying to overcome a hostile, alien world, and maybe, one day, even escape it. This was when Factorio was a different game.
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Just :facepalm:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Interesting post. The event's buffer is very flexible. You could, for example, mine purer/higher quality materials with better equipment rather than it just be a allowed/denied.abregado wrote: βSun Dec 30, 2018 6:21 am ......Code: Select all
script.on_event(defines.events.on_player_mined_entity, function(event) local player = game.players[event.player_index] local mined_tier = get_highest_commodity_tier(event.buffer) local axe_tier = get_highest_pickaxe_tier(player) player.print("Mined tier "..mined_tier.." with axe tier "..axe_tier) if mined_tier > axe_tier then player.print("you cant mine that") event.buffer.clear() else player.print("you mined something") end end)
I've had a bunch of mod ideas thinking about all this.
Shameless mod plugging: Ribbon Maze
- featherwinglove
- Filter Inserter
- Posts: 579
- Joined: Sat Jun 25, 2016 6:14 am
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Oktokolo said "faking it" ...um, like what? Then someone went on to say that scripting and data were two different "engines"? Perhaps the modding documentation needs a laymen's intro to some basic programming terminology.
"Laggy" might be the right word, since I'm using a mod which is definitely using script-side code for its tools, and I get a noticeable and slightly annoying lag spike every time I change hand tools (of 8 tools, it adds only two actual "axes", one of which is just a new recipe for the vanilla iron axe.)
I'm going to see if I can ring up the StoneAge guy, since script-modding hand tools is already his schtick, and his mod already uses both, and these changes will probably mean starting over from scratch for him.
And my favorite quote from that Bob guyBuilderOfAges wrote: βFri Oct 26, 2018 7:04 am Version 0.0.2 released.
Major changes
- The endgoal of the Stone Age is now to make an iron axe, rather than a copper
axe.
bobingabout wrote: βFri Oct 26, 2018 5:29 pm I'm just going to go sit in the corner and cry now...
- featherwinglove
- Filter Inserter
- Posts: 579
- Joined: Sat Jun 25, 2016 6:14 am
- Contact:
-
- Inserter
- Posts: 35
- Joined: Thu Aug 02, 2018 3:02 pm
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Summon him and he shall apear .featherwinglove wrote: βSun Dec 30, 2018 5:56 pm I'm going to see if I can ring up the StoneAge guy, since script-modding hand tools is already his schtick, and his mod already uses both, and these changes will probably mean starting over from scratch for him.
Anyway: I've decided to wait a while for 0.17 to come out and all these changes to settle. From what I gather you are right and I will have to change some mechanics. I think it'll work out though. Especially if this will eventually be added:
If it becomes possible to limit the mining categories that the character has access to, that'll simplify my mod a lot.
As a replacement for the tool slot, I'm thinking that I can make it so you need to hold the right tool in the cursor in order to mine a resource. Guess that'll make the mod even closer to Minecraft, but I don't mind that . Of course, I don't want the player to have to hold an iron axe throughout the entire game, so I'll make the iron axe a kind of "character upgrade".
For now I'm just "watching the cat out of the tree" as we say in my country.
Mod: Stone Age Factorio
-
- Inserter
- Posts: 35
- Joined: Thu Aug 02, 2018 3:02 pm
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
The devs are way ahead of you . https://lua-api.factorio.com/latest/Data-Lifecycle.htmlfeatherwinglove wrote: βSun Dec 30, 2018 5:56 pmThen someone went on to say that scripting and data were two different "engines"? Perhaps the modding documentation needs a laymen's intro to some basic programming terminology.
Mod: Stone Age Factorio
- featherwinglove
- Filter Inserter
- Posts: 579
- Joined: Sat Jun 25, 2016 6:14 am
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
BuilderOfAges wrote: βWed Jan 02, 2019 3:58 amSummon him and he shall apear .featherwinglove wrote: βSun Dec 30, 2018 5:56 pm I'm going to see if I can ring up the StoneAge guy, since script-modding hand tools is already his schtick, and his mod already uses both, and these changes will probably mean starting over from scratch for him.
For whatever reasons, it seems that I get stuck with the stone axe for a significant length of time. ...although I think it's more like just a significant amount of chopping trees. I think that would be the best place to stop the cursor-mining phase in the extant Stone Age mod. I hope you've had time to read my thought dump on what I had in mind when contemplating jumping into the deep end of modding with something I would have called Stone Age. It's a lot different!
Indeed, it has been a while since I read that page.BuilderOfAges wrote: βWed Jan 02, 2019 4:00 am The devs are way ahead of you . https://lua-api.factorio.com/latest/Data-Lifecycle.html
-
- Inserter
- Posts: 35
- Joined: Thu Aug 02, 2018 3:02 pm
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Good point. I'll keep it in mind when I update for 0.17.featherwinglove wrote: βWed Jan 02, 2019 5:04 am I think that would be the best place to stop the cursor-mining phase in the extant Stone Age mod.
I hadn't yet, but I have now. My experience has been that jumping into modding Factorio isn't easy, but well worth the effort. So if you feel strongly about your ideas, I recommend you try and make it yourself. Feel free to use my mod as a starting point and modifying it.featherwinglove wrote: βWed Jan 02, 2019 5:04 am I hope you've had time to read my thought dump on what I had in mind when contemplating jumping into the deep end of modding with something I would have called Stone Age. It's a lot different!
Mod: Stone Age Factorio
Re: [0.17] Adding Ore Hardness and Pickaxes back in
I'm speaking from almost complete ignorance of the api here, but couldn't the pickaxe be an armor module, and wouldn't that apply directly to the player state rather than run through an inventory check?
You'd just have to start the player with a 1-2 slot armor with pickaxe already equipped into it, if desired. Would turn the player's armor into an equipment harness more fully, which is nifty in a design sense if cumbersome to introduce a player to with current UI.
You'd just have to start the player with a 1-2 slot armor with pickaxe already equipped into it, if desired. Would turn the player's armor into an equipment harness more fully, which is nifty in a design sense if cumbersome to introduce a player to with current UI.
- featherwinglove
- Filter Inserter
- Posts: 579
- Joined: Sat Jun 25, 2016 6:14 am
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
There was a "survivial mod" (misspelled that way) in the 0.12 days that took a very similar approach to life support. I don't know if there are any equipments that change mining speed, I know there was something that did it for character crafting speed, let's see (flip flip) ...whoa... WTF? Okay, I thought this site was down, lemme see if it has anything else I remember from the 0.12 days... There's one I miss! And yet another (that's a pun on a very similar modern mod.) Oh, there it is! I can't even misspell it rightRythe wrote: βFri Jan 04, 2019 8:52 am I'm speaking from almost complete ignorance of the api here, but couldn't the pickaxe be an armor module, and wouldn't that apply directly to the player state rather than run through an inventory check?
You'd just have to start the player with a 1-2 slot armor with pickaxe already equipped into it, if desired. Would turn the player's armor into an equipment harness more fully, which is nifty in a design sense if cumbersome to introduce a player to with current UI.
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: [0.17] Adding Ore Hardness and Pickaxes back in
another option is to link mineability to the force which can then be tweaked by research.
Re: [0.17] Adding Ore Hardness and Pickaxes back in
So I've looked at this a wee bit more. What appears to be missing from the modding API is an event that fires before a player begins to mine an entity, firing on the initial attempt itself, that has the ability to flag a cancel/invalid state for the mining attempt. I don't know how the implementation of mining category is suppose to work, but sounded like it was a yes/no force state that bypassed any event checks completely?
But a proper mod re-implementation of hardness and pickaxes looks like it would be simple apart from that lack of pre-mining event making it currently impossible - as far as I can tell. Something like...
One way or another, extend the player entity like:
The number value is mining power, with 0 as signifier for none.
On the 'on_player_placed_equipment' and 'on_player_removed_equipment' events, this table would be updated by using highest values for equipped armor modules with mining capabilities. So same table attached to relevant equipment prototypes? Player's mining category yes/no flag would be updated as well for UI purposes if nothing else.
Now this is where the event before entity mining starts is needed. So on mining attempt event...
The (power > 0) check is here in case this logic would work around the player entity's mining category flags.
The other wrinkle would be working with any research-based speed boost in the background. But beyond that, I think this should cover it?
And yes, this is JavaScript-esque pseudo code. It's allllll wrong.
Edit: The ore hardness should be added to the ore entity prototype if possible, and since the prototype should already have mining category, that'd make things cleaner. Duh.
But a proper mod re-implementation of hardness and pickaxes looks like it would be simple apart from that lack of pre-mining event making it currently impossible - as far as I can tell. Something like...
One way or another, extend the player entity like:
Code: Select all
player.mining = {
'cat_a' : 1,
'cat_b' : 0.45,
'cat_c' : 0,
}
On the 'on_player_placed_equipment' and 'on_player_removed_equipment' events, this table would be updated by using highest values for equipped armor modules with mining capabilities. So same table attached to relevant equipment prototypes? Player's mining category yes/no flag would be updated as well for UI purposes if nothing else.
Code: Select all
local ores = {
'iron' : {
'category' : 'cat_a',
'hardness' : 0.9
},
'copper' : {
'category' : 'cat_a',
'hardness' : 0.75
}
}
Code: Select all
if (targetEntity.name in ores){
var hardness = ores[targetEntity.name].hardness;
var power = player.mining[ores[targetEntity.name].category];
if (power > 0){ player.character_mining_speed_modifier = power / hardness; }
else { /* Cancel Player Mining */ }
}
else {
player.character_mining_speed_modifier = default_mining_speed;
}
The other wrinkle would be working with any research-based speed boost in the background. But beyond that, I think this should cover it?
And yes, this is JavaScript-esque pseudo code. It's allllll wrong.
Edit: The ore hardness should be added to the ore entity prototype if possible, and since the prototype should already have mining category, that'd make things cleaner. Duh.
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Why would you bother with power/hardness at all, if you're using categories? Why not just store speed on the category?
Re: [0.17] Adding Ore Hardness and Pickaxes back in
Because the category represents a hard distinction between mining complexity/methodology and the hardness represents graduated difficulty within a category?
In order to increase the resolution of the sim / provide more variation and steps in equipment development so the player can experience a greater sense of progression?
Re: [0.17] Adding Ore Hardness and Pickaxes back in
But that last did jog my memory on the old discussion about hardness and mining power being removed. Which is a detail worth noting about the simple formula I ran here.
The 0.16 formula for mining is (Mining power - Mining hardness) * Mining speed / Mining time = Production rate (in resource/sec).
In my eyes, the only excessive variable is Mining Time which is attached to the ore, so I should have done player.character_mining_speed_modifier = (Mining power - Mining hardness) * Mining speed for the faithful reproduction of what the sim fans wanted that doesn't include the redundant variable.
The 0.17 setup shifts (Mining power - Mining hardness) to category, and the complaint about this change was that this doesn't allow for power vs. hardness to determine whether mining is possible as a dynamic outcome rather than something the mod developers has to set directly via category.
I side with the sim fans here in the sense that (Mining power - Mining Hardness) is easier to manage rather than having to make a mess of mining categories and manually set every one on every mining entity in order to get the differentiation the mod developer is going for.
Mining category is still a useful division in that it can create a distinction of process (oil wells vs surface mines vs deep mines vs sand mines), and keeping (Mining Power - Mining Hardness) creates a second useful distinction in that, for surface mining, a diamond drill could harvest titanium in a surface deposit where a stone axe couldn't.
Why care? Because sim fans and greater sense of progression.
The 0.16 formula for mining is (Mining power - Mining hardness) * Mining speed / Mining time = Production rate (in resource/sec).
In my eyes, the only excessive variable is Mining Time which is attached to the ore, so I should have done player.character_mining_speed_modifier = (Mining power - Mining hardness) * Mining speed for the faithful reproduction of what the sim fans wanted that doesn't include the redundant variable.
The 0.17 setup shifts (Mining power - Mining hardness) to category, and the complaint about this change was that this doesn't allow for power vs. hardness to determine whether mining is possible as a dynamic outcome rather than something the mod developers has to set directly via category.
I side with the sim fans here in the sense that (Mining power - Mining Hardness) is easier to manage rather than having to make a mess of mining categories and manually set every one on every mining entity in order to get the differentiation the mod developer is going for.
Mining category is still a useful division in that it can create a distinction of process (oil wells vs surface mines vs deep mines vs sand mines), and keeping (Mining Power - Mining Hardness) creates a second useful distinction in that, for surface mining, a diamond drill could harvest titanium in a surface deposit where a stone axe couldn't.
Why care? Because sim fans and greater sense of progression.