AMAI
AMAI copied to clipboard
Town track job function SeedNewTownAtLoc
function SeedNewTownAtLoc takes location l, integer p returns nothing
set town_owner[town_num] = p
set town_loc[town_num] = l
set town_threat[town_num] = 0
set town_group[town_num] = CreateGroup()
call TrackTown(town_num)
set town_num = town_num + 1
endfunction
call TrackTown(town_num) meaningless maybe here is like SeedNewArmyAtLoc , if TrackArmy(army_num) then
function SeedNewArmyAtLoc takes location l, integer p returns nothing
if army_num_excretion != army_num then
set army_dir[army_num] = Location(0,0)
set army_future[army_num] = Location(0,0)
set army_group[army_num] = CreateGroup()
set army_owner[army_num] = p
elseif army_num_Count_ex >= 1 and army_loc[army_num] != null then //prevent army_loc[army_num] is army_loc[to]
call RemoveLocation(army_loc[army_num])
endif
set army_loc[army_num] = l
set army_num_excretion = army_num
set army_num_Count_ex = army_num_Count_ex + 1
if TrackArmy(army_num) then
set army_num_Count_ex = 0
set army_num = army_num + 1
endif
endfunction
this fix
function SeedNewTownAtLoc takes location l, integer p returns nothing
if town_num_excretion != town_num then
set town_group[town_num] = CreateGroup()
set town_owner[town_num] = p
set town_threat[town_num] = 0
elseif town_num_Count_ex >= 1 and town_loc[town_num] != null then //prevent town_loc[town_num] is town_loc[to]
call RemoveLocation(town_loc[town_num])
endif
set town_loc[town_num] = l
set town_num_excretion = town_num
set town_num_Count_ex = town_num_Count_ex + 1
if TrackTown(town_num) then
set town_num_Count_ex = 0
set town_num = town_num + 1
endif
endfunction
call CopyArmy(i, first_free) and call CopyTown(i, first_free) , if i = first_free , then meaningless too so I change the code
function TrackExistingArmies takes nothing returns nothing
local integer i = 0
local integer first_free = 0
loop
exitwhen i >= army_num
if TrackArmy(i) then
if i != first_free then
call CopyArmy(i, first_free)
endif
set first_free = first_free + 1
endif
set i = i + 1
endloop
set army_num = first_free
endfunction
function TrackExistingTowns takes nothing returns nothing
local integer i = 0
local integer first_free = 0
loop
exitwhen i >= town_num
if TrackTown(i) then
if i != first_free then
call CopyTown(i, first_free)
endif
set first_free = first_free + 1
endif
set i = i + 1
endloop
set town_num = first_free
endfunction