Моя проблема следующая. Есть код, суть которого выдавать приоритет на захват жилищ для ИИ через поток. Всё работает прекрасно, кроме одного. Если 1 из героев ИИ засаживается в замке, то поток крашится. Частоту краша можно сократить раз в 100 если добавить чек IsHeroInTown, но все равно на 2-3 неделе краш случится, когда чек успешно пройден, а в этот момент герой садится в замок. Ещё этот чек утяжеляет поток, из-за чего ищу другие варианты. Можно ли как-то отследить краш и запустить поток заново? Есть ли более интересные идеи?
--global_creature_arrays--------------------------------------------------------
CnogradeID = {};--non-upgrade_creature_IDs_(tier_1-7)
CnogradeID[0] = { 1, 3, 5, 7, 9, 11, 13};--haven
CnogradeID[1] = { 43, 45, 47, 49, 51, 53, 55};--sylvan
CnogradeID[2] = { 57, 59, 61, 63, 65, 67, 69};--academy
CnogradeID[3] = { 71, 73, 75, 77, 79, 81, 83};--dungeon
CnogradeID[4] = { 29, 31, 33, 35, 37, 39, 41};--necropolis
CnogradeID[5] = { 15, 17, 19, 21, 23, 25, 27};--inferno
CnogradeID[6] = { 92, 94, 96, 98,100,102,104};--fortress
CnogradeID[7] = {117,119,121,123,125,127,129};--stronghold
--
Cgrade1ID = {};--first_upgrade_creature_IDs_(tier_1-7)
Cgrade1ID[0] = { 2, 4, 6, 8, 10, 12, 14};--haven
Cgrade1ID[1] = { 44, 46, 48, 50, 52, 54, 56};--sylvan
Cgrade1ID[2] = { 58, 60, 62, 64, 66, 68, 70};--academy
Cgrade1ID[3] = { 72, 74, 76, 78, 80, 82, 84};--dungeon
Cgrade1ID[4] = { 30, 32, 34, 36, 38, 40, 42};--necropolis
Cgrade1ID[5] = { 16, 18, 20, 22, 24, 26, 28};--inferno
Cgrade1ID[6] = { 93, 95, 97, 99,101,103,105};--fortress
Cgrade1ID[7] = {118,120,122,124,126,128,130};--stronghold
--
Cgrade2ID = {};--second_upgrade_creature_IDs_(tier_1-7)
Cgrade2ID[0] = {106,107,108,109,110,111,112};--haven
Cgrade2ID[1] = {145,146,147,148,149,150,151};--sylvan
Cgrade2ID[2] = {159,160,161,162,163,164,165};--academy
Cgrade2ID[3] = {138,139,140,141,142,143,144};--dungeon
Cgrade2ID[4] = {152,153,154,155,156,157,158};--necropolis
Cgrade2ID[5] = {131,132,133,134,135,136,137};--inferno
Cgrade2ID[6] = {166,167,168,169,170,171,172};--fortress
Cgrade2ID[7] = {173,174,175,176,177,178,179};--stronghold
--
Cgrowth = {};--creature_weekly_growth_modifier_(1_weekly_growth+( special_building_growth)/2))
Cgrowth[0] = { 24, 12, 10, 5, 3, 2, 1};--haven
Cgrowth[1] = { 12, 9, 7, 4, 3,2.5, 1};--sylvan
Cgrowth[2] = { 20, 14, 9, 5, 4, 2, 1};--academy
Cgrowth[3] = { 8, 6, 6, 4, 3, 2, 1};--dungeon
Cgrowth[4] = { 23, 15, 9, 5, 3, 2,1.5};--necropolis
Cgrowth[5] = { 16, 16, 8, 5,3.5, 2, 1};--inferno
Cgrowth[6] = { 18, 14, 7, 8,3.5, 2, 1};--fortress
Cgrowth[7] = { 28, 13, 11, 5, 5, 2, 1};--stronghold
--
Cpower = {};--average_power_of_1_weekly_growth_of_units_from_tie r_1_to_tier_7
Cpower[1] = {1100,1700,2000,2600,3300,4300,4850};--non-upgraded
Cpower[2] = {1800,2400,2900,3500,4500,5000,6000};--upgraded
Cpower[3] = {1800,2400,2900,3500,4500,5000,6000};--upgraded
--
Cgradetype = {CnogradeID,Cgrade1ID,Cgrade2ID};--upgrade_type_identifier
--
function GetArmyPower(OBJ)
local VALUE = 0;
for i = 1,3 do--creature_upgrade_type
for j = 0,7 do--creature_race
for k = 1,7 do--creature_tier
if GetObjectCreatures(OBJ,Cgradetype[i][j][k]) > 0 then
VALUE = VALUE + ceil(GetObjectCreatures(OBJ,Cgradetype[i][j][k])/Cgrowth[j][k]*Cpower[i][k]);
end;
end;
end;
end;
return VALUE;
end;
--dwelling_AI_attraction--------------------------------------------------------
function AIAttractionLoop(PLAYER)
if GetPlayerRace(1) == GetPlayerRace(2) then--if_players'_race_is_the_same
while 1 do
for i = 1,2 do--dwelling_side
for j = 1,4 do--dwelling_levels
if GetObjectOwner("Dwel"..j.."P"..i) ~= PLAYER then
SetAIPlayerAttractor("Dwel"..j.."P"..i,PLAYER,1);--set_dwelling_attractor
else
SetAIPlayerAttractor("Dwel"..j.."P"..i,PLAYER,-1);--attractor_cancel
end;
end;
end;
sleep(5);
end;
else--if_players'_race_isn't_the_same
while 1 do
local AIheroes = GetPlayerHeroes(PLAYER);
local ln = length(AIheroes);
for i = 0,ln-1 do--quantity_of_AI_heroes
for j = 1,2 do--dwelling_side
for k = 1,4 do--dwelling_levels
if GetObjectOwner("Dwel"..k.."P"..j) ~= PLAYER then
if GetArmyPower(AIheroes[i]) > GetArmyPower("Dwel"..k.."P"..j.."Gar")*2 then
SetAIHeroAttractor("Dwel"..k.."P"..j,AIheroes[i],1);--set_dwelling_attractor
end;
else
SetAIHeroAttractor("Dwel"..k.."P"..j,AIheroes[i],0);--attractor_cancel
end;
end;
end;
end;
sleep(5);
end;
end;
end;
--
if IsAIPlayer(1) == 1 then
startThread(AIAttractionLoop,1);
elseif IsAIPlayer(2) == 1 then
startThread(AIAttractionLoop,2);
end;