|  |  | @ -10,12 +10,14 @@ This was vanilla behaviour until ``0.31.12``, in which the "bug" was "fixed". | 
			
		
	
		
		
			
				
					
					|  |  |  | =end]] |  |  |  | =end]] | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | function update_pos(pos, ent) |  |  |  | function update_pos(ent) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     pos = df.entity_position:new() |  |  |  |     local pos = df.entity_position:new() | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     ent.positions.own:insert('#', pos) |  |  |  |     ent.positions.own:insert('#', pos) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     pos.code = "DIPLOMAT" |  |  |  |     pos.code = "DIPLOMAT" | 
			
		
	
		
		
			
				
					
					|  |  |  |     pos.id = ent.positions.next_position_id + 1 |  |  |  |     pos.id = ent.positions.next_position_id + 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     ent.positions.next_position_id = ent.positions.next_position_id + 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |     pos.flags.DO_NOT_CULL = true |  |  |  |     pos.flags.DO_NOT_CULL = true | 
			
		
	
		
		
			
				
					
					|  |  |  |     pos.flags.MENIAL_WORK_EXEMPTION = true |  |  |  |     pos.flags.MENIAL_WORK_EXEMPTION = true | 
			
		
	
		
		
			
				
					
					|  |  |  |     pos.flags.SLEEP_PRETENSION = true |  |  |  |     pos.flags.SLEEP_PRETENSION = true | 
			
		
	
	
		
		
			
				
					|  |  | @ -42,14 +44,15 @@ end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | checked = 0 |  |  |  | local checked = 0 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | fixed = 0 |  |  |  | local fixed = 0 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | for _,ent in pairs(df.global.world.entities.all) do |  |  |  | for _,ent in pairs(df.global.world.entities.all) do | 
			
		
	
		
		
			
				
					
					|  |  |  |     if ent.type == 0 and ent.entity_raw.flags.TREE_CAP_DIPLOMACY then |  |  |  |     if ent.type == df.historical_entity_type.Civilization and ent.entity_raw.flags.TREE_CAP_DIPLOMACY then | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         checked = checked + 1 |  |  |  |         checked = checked + 1 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         update = true |  |  |  |         update = true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         local found_position | 
			
		
	
		
		
			
				
					
					|  |  |  |         -- see if we need to add a new position or modify an existing one |  |  |  |         -- see if we need to add a new position or modify an existing one | 
			
		
	
		
		
			
				
					
					|  |  |  |         for _,pos in pairs(ent.positions.own) do |  |  |  |         for _,pos in pairs(ent.positions.own) do | 
			
		
	
		
		
			
				
					
					|  |  |  |             if  pos.responsibilities.MAKE_INTRODUCTIONS and |  |  |  |             if  pos.responsibilities.MAKE_INTRODUCTIONS and | 
			
		
	
	
		
		
			
				
					|  |  | @ -57,37 +60,40 @@ for _,ent in pairs(df.global.world.entities.all) do | 
			
		
	
		
		
			
				
					
					|  |  |  |                 pos.responsibilities.MAKE_TOPIC_AGREEMENTS then |  |  |  |                 pos.responsibilities.MAKE_TOPIC_AGREEMENTS then | 
			
		
	
		
		
			
				
					
					|  |  |  |                     -- a diplomat position exists with the proper responsibilities - skip to the end |  |  |  |                     -- a diplomat position exists with the proper responsibilities - skip to the end | 
			
		
	
		
		
			
				
					
					|  |  |  |                     update = false |  |  |  |                     update = false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     found_position=pos | 
			
		
	
		
		
			
				
					
					|  |  |  |                     break |  |  |  |                     break | 
			
		
	
		
		
			
				
					
					|  |  |  |             end |  |  |  |             end | 
			
		
	
		
		
			
				
					
					|  |  |  |             -- Diplomat position already exists, but has the wrong options - modify it instead of creating a new one |  |  |  |             -- Diplomat position already exists, but has the wrong options - modify it instead of creating a new one | 
			
		
	
		
		
			
				
					
					|  |  |  |             if pos.code == "DIPLOMAT" then break end |  |  |  |             if pos.code == "DIPLOMAT" then  | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             pos = nil |  |  |  |                 found_position=pos | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 break  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             end | 
			
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |         end | 
			
		
	
		
		
			
				
					
					|  |  |  |         if update then |  |  |  |         if update then | 
			
		
	
		
		
			
				
					
					|  |  |  |             -- either there's no diplomat, or there is one and it's got the wrong responsibilities |  |  |  |             -- either there's no diplomat, or there is one and it's got the wrong responsibilities | 
			
		
	
		
		
			
				
					
					|  |  |  |             if not pos then |  |  |  |             if not found_position then | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 pos = add_guild_rep(pos, ent) |  |  |  |                 found_position = add_guild_rep( ent ) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             end |  |  |  |             end | 
			
		
	
		
		
			
				
					
					|  |  |  |             -- assign responsibilities |  |  |  |             -- assign responsibilities | 
			
		
	
		
		
			
				
					
					|  |  |  |             pos.responsibilities.MAKE_INTRODUCTIONS = true |  |  |  |             found_position.responsibilities.MAKE_INTRODUCTIONS = true | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             pos.responsibilities.MAKE_PEACE_AGREEMENTS = true |  |  |  |             found_position.responsibilities.MAKE_PEACE_AGREEMENTS = true | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             pos.responsibilities.MAKE_TOPIC_AGREEMENTS = true |  |  |  |             found_position.responsibilities.MAKE_TOPIC_AGREEMENTS = true | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |         end | 
			
		
	
		
		
			
				
					
					|  |  |  |         -- make sure the diplomat position, whether we created it or not, is set up for proper assignment |  |  |  |         -- make sure the diplomat position, whether we created it or not, is set up for proper assignment | 
			
		
	
		
		
			
				
					
					|  |  |  |         assign = true |  |  |  |         local assign = true | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         for _,p in pairs(ent.positions.assignments) do |  |  |  |         for _,p in pairs(ent.positions.assignments) do | 
			
		
	
		
		
			
				
					
					|  |  |  |             if p.position_id == pos.id then -- it is - nothing more to do here |  |  |  |             if p.position_id == found_position.id then -- it is - nothing more to do here | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 assign = false |  |  |  |                 assign = false | 
			
		
	
		
		
			
				
					
					|  |  |  |                 break |  |  |  |                 break | 
			
		
	
		
		
			
				
					
					|  |  |  |             end |  |  |  |             end | 
			
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |         end | 
			
		
	
		
		
			
				
					
					|  |  |  |         if assign then -- it isn't - set it up |  |  |  |         if assign then -- it isn't - set it up | 
			
		
	
		
		
			
				
					
					|  |  |  |             asn = df.entity_position_assignment:new() |  |  |  |             local asn = df.entity_position_assignment:new() | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             ent.positions.assignments:insert('#', asn); |  |  |  |             ent.positions.assignments:insert('#', asn); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             asn.id = ent.positions.next_assignment_id |  |  |  |             asn.id = ent.positions.next_assignment_id | 
			
		
	
		
		
			
				
					
					|  |  |  |             ent.positions.next_assignment_id = asn.id + 1 |  |  |  |             ent.positions.next_assignment_id = asn.id + 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |             asn.position_id = pos.id |  |  |  |             asn.position_id = found_position.id | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             asn.flags:resize(math.max(32, #asn.flags)) -- make room for 32 flags |  |  |  |             asn.flags:resize(math.max(32, #asn.flags)) -- make room for 32 flags | 
			
		
	
		
		
			
				
					
					|  |  |  |             asn.flags[0] = true  -- and set the first one |  |  |  |             asn.flags[0] = true  -- and set the first one | 
			
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |         end | 
			
		
	
	
		
		
			
				
					|  |  | 
 |