How does research work in PVP?

Place to get help with not working mods / modding interface.
User avatar
yaim904
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

How does research work in PVP?

Post by yaim904 »

Context
I'm creating a MOD that interacts with technologies and research, but I don't know how this part of the game works in multiplayer.
Questions
  1. Each team investigates the technologies separately??
  2. When researching a technology, does it affect both teams?
  3. Each team has a different technology queue??
Want
How do I access the research of both teams?
Last edited by yaim904 on Mon Mar 14, 2022 3:54 pm, edited 1 time in total.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by Deepl.
:D
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2767
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: How does research work in PVP?

Post by FuryoftheStars »

I think, though don't quote me on this, that each team has the same list of technologies (ie, you can't have Tech A available only to Team A), but they research them separately. I believe it's tracked through the Forces object.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How does research work in PVP?

Post by Pi-C »

yaim904 wrote: Mon Mar 14, 2022 3:13 pm How do I access the research of both teams?
Like FuryoftheStars commented, you can access force.technologies["tech-name"].researched (read and write). You definitely should listen to these events
This one could be useful as well: on_technology_effects_reset will give you event.force in the event data, the other events have event.research.force.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
yaim904
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: How does research work in PVP?

Post by yaim904 »

FuryoftheStars wrote: Mon Mar 14, 2022 3:37 pm
So, not exist difference queues for each team.

And i can use the events to do any i want (or can).
Pi-C wrote: Mon Mar 14, 2022 4:03 pm
I am right??
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by Deepl.
:D
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2767
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: How does research work in PVP?

Post by FuryoftheStars »

yaim904 wrote: Mon Mar 14, 2022 4:35 pm So, not exist difference queues for each team.
I'm sorry, I'm reading the word "queue" differently then how I intended my post to be interpreted.

Let me try this over. :)
yaim904 wrote: Mon Mar 14, 2022 3:13 pm
  1. Each team investigates the technologies separately??
  2. When researching a technology, does it affect both teams?
  3. Each team has a different technology queue??
  1. Yes
  2. No
  3. Yes
  4. (What I meant in my post) Can each team have a different technology tree? No
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How does research work in PVP?

Post by Pi-C »

yaim904 wrote: Mon Mar 14, 2022 4:35 pm So, not exist difference queues for each team.
Yes: All technologies in the game can be researched by all forces (even the biters have force.technologies although they'll never research anything -- at least in vanilla). But each force must research individually, so if force A has researched cars (for example), force B must also research it before they can build cars.
And i can use the events to do any i want (or can).
Yes. For example, if a force has researched the rocket silo, you could reset all their research so they must start over again. That wouldn't make sense, but you could do it. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
yaim904
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: How does research work in PVP?

Post by yaim904 »

LuaForce
I thought foce.player has all the players.
Pi-C wrote: Mon Mar 14, 2022 4:52 pm
So, force has force.team1 and force.team2??

Ok, I'm learning a lot.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by Deepl.
:D
robot256
Smart Inserter
Smart Inserter
Posts: 1248
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How does research work in PVP?

Post by robot256 »

In this context, "force" means any LuaForce object reference. You can get the LuaForce reference from an event, a player or entity object, or from the game.forces list.

game.forces is the list of all forces (teams).

For example, `game.forces["team1"].players` is the list of all players on team1.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
User avatar
yaim904
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: How does research work in PVP?

Post by yaim904 »

LuaForce I feel that the guide lacks more information and/or details.

When I tried to see the name of the forces it showed me this.

Code: Select all

for _, Force in pairs( game.forces ) do
   log( "'" .. Force.name .. "'" )
end

'player'
'enemy'
'neutral'
'conquest'
'ignore'
'capture'
'friendly'
What would it look like in a team multiplayer?

I want a way to identify the forces that contain the players.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by Deepl.
:D
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How does research work in PVP?

Post by Pi-C »

yaim904 wrote: Mon Mar 14, 2022 11:48 pm LuaForce I feel that the guide lacks more information and/or details.

When I tried to see the name of the forces it showed me this.

Code: Select all

for _, Force in pairs( game.forces ) do
   log( "'" .. Force.name .. "'" )
end

'player'
'enemy'
'neutral'
'conquest'
'ignore'
'capture'
'friendly'
Each game will always have the default forces: 'player', 'enemy', and 'neutral'. Mods can create additional forces, so eventually, there may be a maximum of 64 forces in a game. You have a mod that added 'conquest', 'ignore', capture', and 'friendly'.
What would it look like in a team multiplayer?
It depends. In the most simple case, there could be just the three default forces, and all players belong to force 'player'. But you could do this:

Code: Select all

script.on_init(function() 
	game.create_force("all_players_are_here") 
end) 

script.on_event(defines.events.on_player_created, function(event) 
	local player = game.players[event.player_index]
	player.force = game.forces["all_players_are_here"]
end)
In that case, all players would belong to 'all_players_are_here', and if a tech is researched, all players would benefit from it. However, there would be nobody on force 'player'.

Consider this:

Code: Select all

script.on_init(function() 
	local new_force = game.create_force("second_player_force") 
	new_force.set_friend('player', true)
end) 

script.on_event(defines.events.on_player_created, function(event) 
	if event.player_index % 2 == 0 then
		local player = game.players[event.player_index]
		player.force = game.forces["second_player_force"]
	end
end)
Players 1, 3, 5, … would belong to 'player', players 2, 4, 6, … to 'second_player_force'. These forces would be allies, so turrets from one force wouldn't attack players from the other force, and players from 'player' could open buildings from 'second_player_force' as if they were their own. However, both forces would have to do their own research.

You can set the relations of forces:

Code: Select all

local force = game.player.force
force.set_friend(other_force, Boolean)
force.set_ceasefire(other_force, Boolean) 
and read them:

Code: Select all

local is_friend = function(force, other_force)
	return force.get_friend(other_force)
end

local is_neutral = function(force, other_force)
	if force.get_ceasefire(other_force) and not force.get_friend(other_force) then
		return true
	end
end

local is_enemy = function(force, other_force)
	if force.get_friend(other_force) or force.get_ceasefire(other_force) then
		return false
	end
	return true
end
I want a way to identify the forces that contain the players.
All forces have the property force.players (a table). In unmodded games, game.forces['enemy'].players and game.forces['neutral'].players will be empty, and game.forces['player'].players will be a list of all players in the game. So you could do this:

Code: Select all

for f, force in pairs(game.forces) do
	local p = next(force.players) and true or false
	game.print("Force "..f.." has players: "..tostring(p))
end
next(table) will return the first element of a table, or nil if the table is empty.
Last edited by Pi-C on Tue Mar 15, 2022 8:36 pm, edited 1 time in total.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
yaim904
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: How does research work in PVP?

Post by yaim904 »

I understood everything!! :D

And my question changes to: Why is all this not in the API guide?
Thanks for the explanation.
I have to reconstruct a part of the code, but now that I understand it, it excites me.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by Deepl.
:D
Post Reply

Return to “Modding help”