You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: gamedata/scripts/sim_faction.script
+17-12Lines changed: 17 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -478,13 +478,13 @@ function se_sim_faction:calculate_squad_tasks()
478
478
479
479
if script_target ~= nil then
480
480
self.squad_target_cache[squad.squad_id] = script_target -- if squad has script target then assign squad to that target
481
-
if self.target_smart_value[script_target] ~= nil then -- if script target is a registered target smart then
481
+
if self.target_smart_value[script_target] ~= nil then -- if script target is a registered target smart:
482
482
self.target_smart_value[script_target].num = self.target_smart_value[script_target].num + 1 -- increase number of squads going to that target smart by 1
483
483
end
484
-
-- dbglog("Assigned "..self.player_name.." squad with ID "..tostring(squad.squad_id).." to scripted target ["..game.translate_string("st_name_"..board_smarts[script_target].smrt:name()).."].")
484
+
-- dbglog("Assigned "..self.player_name.." squad with ID ["..squad.squad_id.."] to scripted target ["..game.translate_string("st_name_"..board_smarts[script_target].smrt:name()).."].")
485
485
else
486
486
if squad.smart_id == nil then
487
-
abort("[sim_faction.calculate_squad_tasks]: Squad with ID '%s' has no registered source smart.", tostring(squad.squad_id))
487
+
abort("[sim_faction.calculate_squad_tasks]: Squad with ID '%s' has no registered source smart.", squad.squad_id)
488
488
return
489
489
end
490
490
@@ -493,7 +493,7 @@ function se_sim_faction:calculate_squad_tasks()
493
493
local is_stay = false
494
494
local dest_smart, graph_point, graph_point_dest
495
495
496
-
if squad.current_action == nil or squad.current_action.name == "stay_point" then -- if squad is idling around then:
496
+
if squad.current_action == nil or squad.current_action.name == "stay_point" then -- if squad is idling around:
497
497
is_stay = true
498
498
dest_smart = board_smarts[squad.smart_id].smrt -- 'dest_smart' = squad's current smart
@@ -505,13 +505,14 @@ function se_sim_faction:calculate_squad_tasks()
505
505
506
506
squad_need_task[squad.squad_id] =
507
507
{
508
+
squad = squad,
508
509
dest_smart = dest_smart,
509
510
is_stay = is_stay,
510
511
graph_point = graph_point,
511
512
graph_point_dest = graph_point_dest
512
513
}
513
514
514
-
-- dbglog("Inserted "..self.player_name.." squad with ID "..tostring(squad.squad_id).." and dest smart ["..game.translate_string("st_name_"..dest_smart:name()).."] to squad_need_task.")
515
+
-- dbglog("Inserted "..self.player_name.." squad with ID ["..squad.squad_id.."] and dest smart ["..game.translate_string("st_name_"..dest_smart:name()).."] to squad_need_task.")
515
516
end
516
517
end
517
518
@@ -530,13 +531,17 @@ function se_sim_faction:calculate_squad_tasks()
530
531
531
532
for squad_id, squad_data in pairs (squad_need_task) do -- for all squads in need of task (i.e. any squad not assigned to a script target):
532
533
533
-
if level_cluster[squad_data.dest_smart.smart_level] == level_cluster[target_smart_obj.smart_level] then -- if registered target smart is in the same level cluster as 'dest_smart' then
534
+
if level_cluster[squad_data.dest_smart.smart_level] == level_cluster[target_smart_obj.smart_level] then -- if registered target smart is in the same level cluster as 'dest_smart':
534
535
535
536
target_smart_gpoint = target_smart_gpoint or GG:vertex(target_smart_obj.m_game_vertex_id):game_point()
@@ -545,14 +550,14 @@ function se_sim_faction:calculate_squad_tasks()
545
550
end
546
551
end
547
552
548
-
-- dbglog("Graph distance of "..self.player_name.." squad with ID "..tostring(squad_id).." to smart ["..game.translate_string("st_name_"..target_smart_obj:name()).."] is ["..gr_dist.."].")
553
+
-- dbglog("Graph distance of "..self.player_name.." squad with ID ["..squad_id.."] to smart ["..game.translate_string("st_name_"..target_smart_obj:name()).."] is ["..gr_dist.."].")
549
554
550
555
suitable_squads = suitable_squads + 1
551
556
squads[suitable_squads] = {squad_id = squad_id, dist = gr_dist} -- add squad info to table 'squads'
552
557
end
553
558
end
554
559
555
-
if suitable_squads > 0 then -- if at least one squad is in the same level cluster as registered target smart then
560
+
if suitable_squads > 0 then -- if at least one squad is in the same level cluster as registered target smart:
556
561
table_sort(squads, _sort_by_dist_asc) -- sort 'squads' by squad distance to registered target smart in ascending order
557
562
c = c + 1
558
563
distance_table[c] = {target_smart = target_smart, squads = squads, value = target_smart.value} -- and add {target_smart, squad infos from 'squads', target_smart value} to distance_table
@@ -582,11 +587,11 @@ function se_sim_faction:calculate_squad_tasks()
582
587
583
588
self.squad_target_cache[tmp_squad_id] = tmp_smart.smart_id -- assign nearest squad to smart in first element of distance_table
584
589
585
-
-- dbglog("Assigned "..self.player_name.." squad with ID "..tostring(tmp_squad_id).." to ["..game.translate_string("st_name_"..tmp_smart.smart:name()).."].")
590
+
-- dbglog("Assigned "..self.player_name.." squad with ID ["..tmp_squad_id.."] to ["..game.translate_string("st_name_"..tmp_smart.smart:name()).."].")
586
591
587
592
tmp_smart.num = tmp_smart.num + 1 -- increase number of squads assigned to it by 1
588
593
589
-
if tmp_smart.num >= tmp_smart.cap then -- if number of squads assigned to it now meets or exceeds its capacity,
594
+
if tmp_smart.num >= tmp_smart.cap then -- if number of squads assigned to it now meets or exceeds its capacity:
590
595
-- dbglog("Removed ["..game.translate_string("st_name_"..tmp_smart.smart:name()).."] from distance_table since its capacity ("..tostring(tmp_smart.cap)..") is saturated ("..tostring(tmp_smart.num)..").")
591
596
table_remove(distance_table, 1) -- remove it from distance_table
592
597
end
@@ -596,7 +601,7 @@ function se_sim_faction:calculate_squad_tasks()
596
601
for j = #smart_data.squads, 1, -1 do
597
602
if smart_data.squads[j].squad_id == tmp_squad_id then
598
603
-- local smart_name = game.translate_string("st_name_"..smart_data.target_smart.smart:name())
599
-
-- dbglog("Made "..self.player_name.." squad with ID "..tostring(tmp_squad_id).." unassignable to ["..smart_name.."].")
604
+
-- dbglog("Made "..self.player_name.." squad with ID ["..tmp_squad_id.."] unassignable to ["..smart_name.."].")
600
605
if #smart_data.squads == 1 then
601
606
-- dbglog("Removed ["..smart_name.."] from distance_table since no "..self.player_name.." squad is assignable to it.")
602
607
table_remove(distance_table, i) -- remove any smarts from distance_table to which no squad is assignable
0 commit comments