Skip to content

Commit

Permalink
Fixed game sometimes losing track of 'capture' task giver
Browse files Browse the repository at this point in the history
  • Loading branch information
Decane committed Jan 29, 2023
1 parent 4b4a2b1 commit 7d89f09
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ function sim_squad_generic:init_squad_task()
local tm = task_manager.get_task_manager()
local squad_faction_name = self.player_id
local random_tasks = self.random_tasks
local old_capture_task_1 = random_tasks[1]
local old_capture_task_2 = random_tasks[2]
local recover_task = random_tasks[3]
local squad_smart_id = self.smart_id
local squad_smart = board.smarts[squad_smart_id].smrt
Expand All @@ -763,26 +765,42 @@ function sim_squad_generic:init_squad_task()
random_tasks = {}
self.random_tasks = random_tasks

if board:get_smart_population(squad_smart) > 1 or (board_factions[squad_faction_name].precondition_targets[squad_smart_id] == nil and smart_under_attack(squad_faction_name, board_factions, squad_smart_id) == false) then
if self:get_script_target() == nil and not tm:get_tasks_by_smart(squad_smart_id) then
local level_cluster = sim_board.sim_level_cluster
local squad_smart_cluster = level_cluster[squad_smart.smart_level]
for neighbor_smart_id, neighbor_smart in pairs (board:get_nearest_smarts(squad_smart)) do
if level_cluster[neighbor_smart.smart_level] == squad_smart_cluster then
if sim_board.is_point_avail(neighbor_smart, squad_faction_name) then
local neighbor_faction_name = neighbor_smart.player_name
if neighbor_faction_name ~= "none" then
if game_relations.is_factions_enemies(squad_faction_name, neighbor_faction_name) then
if smart_under_attack(neighbor_faction_name, board_factions, neighbor_smart_id) == false then
local neighbor_smart_task = tm:get_tasks_by_smart(neighbor_smart_id)
if not neighbor_smart_task or neighbor_smart_task.base_prior <= 1 then -- only permits replacing 'generic' eliminate tasks with capture tasks
task = tm:select_task("capture_smart", neighbor_smart, squad_faction_name)
task.src_obj = self.squad_id
if random_tasks[1] == nil then
random_tasks[1] = task.entity_id
elseif random_tasks[2] == nil then
random_tasks[2] = task.entity_id
break
if old_capture_task_1 ~= nil then
task = tm:get_task_by_entity_id(old_capture_task_1)
if task and task.status == "selected" then
random_tasks[1] = old_capture_task_1
end
end

if old_capture_task_2 ~= nil then
task = tm:get_task_by_entity_id(old_capture_task_2)
if task and task.status == "selected" then
random_tasks[#random_tasks + 1] = old_capture_task_2
end
end

if random_tasks[2] == nil then
if board:get_smart_population(squad_smart) > 1 or (board_factions[squad_faction_name].precondition_targets[squad_smart_id] == nil and smart_under_attack(squad_faction_name, board_factions, squad_smart_id) == false) then
if self:get_script_target() == nil and not tm:get_tasks_by_smart(squad_smart_id) then
local level_cluster = sim_board.sim_level_cluster
local squad_smart_cluster = level_cluster[squad_smart.smart_level]
for neighbor_smart_id, neighbor_smart in pairs (board:get_nearest_smarts(squad_smart)) do
if level_cluster[neighbor_smart.smart_level] == squad_smart_cluster then
if sim_board.is_point_avail(neighbor_smart, squad_faction_name) then
local neighbor_faction_name = neighbor_smart.player_name
if neighbor_faction_name ~= "none" then
if game_relations.is_factions_enemies(squad_faction_name, neighbor_faction_name) then
if smart_under_attack(neighbor_faction_name, board_factions, neighbor_smart_id) == false then
local neighbor_smart_task = tm:get_tasks_by_smart(neighbor_smart_id)
if not neighbor_smart_task or neighbor_smart_task.base_prior <= 1 then -- only permits replacing 'generic' eliminate tasks with capture tasks
task = tm:select_task("capture_smart", neighbor_smart, squad_faction_name)
task.src_obj = self.squad_id
if random_tasks[1] == nil then
random_tasks[1] = task.entity_id
else
random_tasks[2] = task.entity_id
break
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ function sim_squad_generic:init_squad_task()
local tm = task_manager.get_task_manager()
local squad_faction_name = self.player_id
local random_tasks = self.random_tasks
local old_capture_task_1 = random_tasks[1]
local old_capture_task_2 = random_tasks[2]
local recover_task = random_tasks[3]
local squad_smart_id = self.smart_id
local squad_smart = board.smarts[squad_smart_id].smrt
Expand All @@ -765,26 +767,42 @@ function sim_squad_generic:init_squad_task()
random_tasks = {}
self.random_tasks = random_tasks

if board:get_smart_population(squad_smart) > 1 or (board_factions[squad_faction_name].precondition_targets[squad_smart_id] == nil and smart_under_attack(squad_faction_name, board_factions, squad_smart_id) == false) then
if self:get_script_target() == nil and not tm:get_tasks_by_smart(squad_smart_id) then
local level_cluster = sim_board.sim_level_cluster
local squad_smart_cluster = level_cluster[squad_smart.smart_level]
for neighbor_smart_id, neighbor_smart in pairs (board:get_nearest_smarts(squad_smart)) do
if level_cluster[neighbor_smart.smart_level] == squad_smart_cluster then
if sim_board.is_point_avail(neighbor_smart, squad_faction_name) then
local neighbor_faction_name = neighbor_smart.player_name
if neighbor_faction_name ~= "none" then
if game_relations.is_factions_enemies(squad_faction_name, neighbor_faction_name) then
if smart_under_attack(neighbor_faction_name, board_factions, neighbor_smart_id) == false then
local neighbor_smart_task = tm:get_tasks_by_smart(neighbor_smart_id)
if not neighbor_smart_task or neighbor_smart_task.base_prior <= 1 then -- only permits replacing 'generic' eliminate tasks with capture tasks
task = tm:select_task("capture_smart", neighbor_smart, squad_faction_name)
task.src_obj = self.squad_id
if random_tasks[1] == nil then
random_tasks[1] = task.entity_id
elseif random_tasks[2] == nil then
random_tasks[2] = task.entity_id
break
if old_capture_task_1 ~= nil then
task = tm:get_task_by_entity_id(old_capture_task_1)
if task and task.status == "selected" then
random_tasks[1] = old_capture_task_1
end
end

if old_capture_task_2 ~= nil then
task = tm:get_task_by_entity_id(old_capture_task_2)
if task and task.status == "selected" then
random_tasks[#random_tasks + 1] = old_capture_task_2
end
end

if random_tasks[2] == nil then
if board:get_smart_population(squad_smart) > 1 or (board_factions[squad_faction_name].precondition_targets[squad_smart_id] == nil and smart_under_attack(squad_faction_name, board_factions, squad_smart_id) == false) then
if self:get_script_target() == nil and not tm:get_tasks_by_smart(squad_smart_id) then
local level_cluster = sim_board.sim_level_cluster
local squad_smart_cluster = level_cluster[squad_smart.smart_level]
for neighbor_smart_id, neighbor_smart in pairs (board:get_nearest_smarts(squad_smart)) do
if level_cluster[neighbor_smart.smart_level] == squad_smart_cluster then
if sim_board.is_point_avail(neighbor_smart, squad_faction_name) then
local neighbor_faction_name = neighbor_smart.player_name
if neighbor_faction_name ~= "none" then
if game_relations.is_factions_enemies(squad_faction_name, neighbor_faction_name) then
if smart_under_attack(neighbor_faction_name, board_factions, neighbor_smart_id) == false then
local neighbor_smart_task = tm:get_tasks_by_smart(neighbor_smart_id)
if not neighbor_smart_task or neighbor_smart_task.base_prior <= 1 then -- only permits replacing 'generic' eliminate tasks with capture tasks
task = tm:select_task("capture_smart", neighbor_smart, squad_faction_name)
task.src_obj = self.squad_id
if random_tasks[1] == nil then
random_tasks[1] = task.entity_id
else
random_tasks[2] = task.entity_id
break
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions SRP v1.1.4 - Version History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ v1.1.4
+ Fixed the issue where the player would be rejected from playing the shooting minigame if their money precisely matches the entry fee instead of exceeding it. - Decane
+ Fixed an SRP v1.1.3 (or v1.0.2 with the optional 'No NPC Weapon Tossing Upon Death' feature) regression that prevented killed NPCs from ever dropping a grenade. - Decane
+ Fixed an SRP v1.1.3 regression that caused some NPCs to keep repeating their goodbye phrase ad nauseum until the player faces away from them after closing their dialogue window. - Decane
+ Fixed an SRP v1.1.1 regression that caused the game to forget the squad from which the player accepted a 'capture' task via dialogue under certain circumstances. - Decane
+ Fixed an SRP v1.0.4 regression that caused several dialogue options to be erroneously unavailable when speaking to generic mercenary NPCs, including Hog's subordinates at the Army Warehouses and Leshiy's subordinates at the Red Forest. - Decane
+ Fixed an SRP v1.0.3 regression that caused Yoga's walkie-talkie transmissions to the player to sound as if Yoga were speaking to the player in person rather than over walkie-talkie. - Decane
+ Worked around an SRP v1.0.3 regression introduced by the Dunin Ammo Aggregation mod that caused ammo unloaded from a weapon to disappear under certain circumstances. - Decane, Alex Rinic
Expand Down
58 changes: 38 additions & 20 deletions gamedata/scripts/sim_squad_generic.script
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ function sim_squad_generic:init_squad_task()
local tm = task_manager.get_task_manager()
local squad_faction_name = self.player_id
local random_tasks = self.random_tasks
local old_capture_task_1 = random_tasks[1]
local old_capture_task_2 = random_tasks[2]
local recover_task = random_tasks[3]
local squad_smart_id = self.smart_id
local squad_smart = board.smarts[squad_smart_id].smrt
Expand All @@ -765,26 +767,42 @@ function sim_squad_generic:init_squad_task()
random_tasks = {}
self.random_tasks = random_tasks

if board:get_smart_population(squad_smart) > 1 or (board_factions[squad_faction_name].precondition_targets[squad_smart_id] == nil and smart_under_attack(squad_faction_name, board_factions, squad_smart_id) == false) then
if self:get_script_target() == nil and not tm:get_tasks_by_smart(squad_smart_id) then
local level_cluster = sim_board.sim_level_cluster
local squad_smart_cluster = level_cluster[squad_smart.smart_level]
for neighbor_smart_id, neighbor_smart in pairs (board:get_nearest_smarts(squad_smart)) do
if level_cluster[neighbor_smart.smart_level] == squad_smart_cluster then
if sim_board.is_point_avail(neighbor_smart, squad_faction_name) then
local neighbor_faction_name = neighbor_smart.player_name
if neighbor_faction_name ~= "none" then
if game_relations.is_factions_enemies(squad_faction_name, neighbor_faction_name) then
if smart_under_attack(neighbor_faction_name, board_factions, neighbor_smart_id) == false then
local neighbor_smart_task = tm:get_tasks_by_smart(neighbor_smart_id)
if not neighbor_smart_task or neighbor_smart_task.base_prior <= 1 then -- only permits replacing 'generic' eliminate tasks with capture tasks
task = tm:select_task("capture_smart", neighbor_smart, squad_faction_name)
task.src_obj = self.squad_id
if random_tasks[1] == nil then
random_tasks[1] = task.entity_id
elseif random_tasks[2] == nil then
random_tasks[2] = task.entity_id
break
if old_capture_task_1 ~= nil then
task = tm:get_task_by_entity_id(old_capture_task_1)
if task and task.status == "selected" then
random_tasks[1] = old_capture_task_1
end
end

if old_capture_task_2 ~= nil then
task = tm:get_task_by_entity_id(old_capture_task_2)
if task and task.status == "selected" then
random_tasks[#random_tasks + 1] = old_capture_task_2
end
end

if random_tasks[2] == nil then
if board:get_smart_population(squad_smart) > 1 or (board_factions[squad_faction_name].precondition_targets[squad_smart_id] == nil and smart_under_attack(squad_faction_name, board_factions, squad_smart_id) == false) then
if self:get_script_target() == nil and not tm:get_tasks_by_smart(squad_smart_id) then
local level_cluster = sim_board.sim_level_cluster
local squad_smart_cluster = level_cluster[squad_smart.smart_level]
for neighbor_smart_id, neighbor_smart in pairs (board:get_nearest_smarts(squad_smart)) do
if level_cluster[neighbor_smart.smart_level] == squad_smart_cluster then
if sim_board.is_point_avail(neighbor_smart, squad_faction_name) then
local neighbor_faction_name = neighbor_smart.player_name
if neighbor_faction_name ~= "none" then
if game_relations.is_factions_enemies(squad_faction_name, neighbor_faction_name) then
if smart_under_attack(neighbor_faction_name, board_factions, neighbor_smart_id) == false then
local neighbor_smart_task = tm:get_tasks_by_smart(neighbor_smart_id)
if not neighbor_smart_task or neighbor_smart_task.base_prior <= 1 then -- only permits replacing 'generic' eliminate tasks with capture tasks
task = tm:select_task("capture_smart", neighbor_smart, squad_faction_name)
task.src_obj = self.squad_id
if random_tasks[1] == nil then
random_tasks[1] = task.entity_id
else
random_tasks[2] = task.entity_id
break
end
end
end
end
Expand Down

0 comments on commit 7d89f09

Please sign in to comment.