
I back.
Tell me what need to do.
Code: Select all
add_attack_mission_group( array_of_unit_index, ... normal parameters)
Code: Select all
NewGroup
GroupAdd
GroupOrder
GroupExist
function NewGroup (GroupID)
GroupID.Num= 0
GroupID.invalid= 0
return GroupID
end
function GroupAdd (GroupID, UnitID)
if GroupID.invalid= 0
then
GroupID["Unit" .. GroupID.Num]= UnitID
GroupID.Num= GroupID.Num+ 1
else
GroupAdd (NewGroup (GroupID), UnitID)
end
return GroupID
end
function GroupMove (GroupID, pos_x, pos_z)
for (i=0; i< GroupID.Num; i= i+ 1)
add_move_mission ( GroupID["Unit" .. i], pos_x, pos_z )
end
end
function GroupAttack (GroupID, target_id)
for (i=0; i< GroupID.Num; i= i+ 1)
add_attack_mission ( GroupID["Unit" .. i], target_id )
end
end
function GroupGuard (GroupID, target_id)
for (i=0; i< GroupID.Num; i= i+ 1)
add_guard_mission ( GroupID["Unit" .. i], target_id )
end
end
function GroupPartrol (GroupID, pos_x, pos_z)
for (i=0; i< GroupID.Num; i= i+ 1)
add_patrol_mission( GroupID["Unit" .. i], pos_x, pos_z )
end
end
function GroupExist (GroupID)
if GroupID.invalid= 0 then
for (i=0; i< GroupID.Num; i= i+ 1)
if has_unit( Me, GroupID["Unit" .. i])==false
local tmp= i+ 1
GroupID["Unit" .. i]= GroupID["Unit" .. tmp]
GroupID["Unit" .. tmp]= nil
end
end
return ture
end
return false
end
Code: Select all
function NewGroup ()
local GroupID = {Num = 0, -- starts with 0 units in the group
Add = GroupAdd, -- allows object like calling convention: group:Add(myUnitID)
Move = GroupMove,
Attack = GroupAttack,
Guard = GroupGuard,
Patrol = GroupPatrol,
Exist = GroupExist};
return GroupID
end
function GroupAdd (GroupID, UnitID)
if GroupID ~= nil
then
GroupID.Num = GroupID.Num + 1
GroupID[GroupID.Num] = UnitID
else
GroupID = GroupAdd (NewGroup (), UnitID)
end
return GroupID
end
function GroupMove (GroupID, pos_x, pos_z)
for i = 1, GroupID.Num do
add_move_mission ( GroupID[i], pos_x, pos_z )
end
end
function GroupAttack (GroupID, target_id)
for i = 1, GroupID.Num do
add_attack_mission ( GroupID[i], target_id )
end
end
function GroupGuard (GroupID, target_id)
for i = 1, GroupID.Num do
add_guard_mission ( GroupID[i], target_id )
end
end
function GroupPartrol (GroupID, pos_x, pos_z)
for i = 1, GroupID.Num do
add_patrol_mission( GroupID[i], pos_x, pos_z )
end
end
function GroupExist (GroupID)
if GroupID ~= nil then
for i = 1, GroupID.Num do
if not has_unit( Me, GroupID[i]) then
local tmp = i + 1
GroupID[i] = GroupID[tmp]
GroupID[tmp] = nil
i = i - 1
end
end
return true
end
return false
end
Code: Select all
group = NewGroup()
group:Add(1)
GroupAdd(group, 2)
Code: Select all
function GroupCall (GroupID, F, ...)
for i = 1, GroupID.Num do
F ( GroupID[i], ... )
end
end
GroupMove = function (GroupID, ...) GroupCall (GroupID, add_move_mission, ...) end
It's cool!Units have an ID which identifies them in the engine data structures and a UUID (Unique Unit ID) which identifies a unit for the whole game as opposed to ID which is a slot in an array (if the unit dies it can be replaced which is confusing ... but the new unit will have a higher UUID).
Code: Select all
section =
{
nw_x= 0;
nw_y= 0;
se_x= 0;
se_y= 0;
}
SecUnits (localplayer (), CORCA, section)
Code: Select all
function GroupAdd (GroupID, UnitID)
if GroupID ~= nil
then
GroupID.Num = GroupID.Num + 1
GroupID[GroupID.Num] = UnitID
UnitID.Group = GroupID --xp addtion
else
GroupID = GroupAdd (NewGroup (), UnitID)
end
return GroupID
end
Users browsing this forum: No registered users and 2 guests