GetUnitCount(0)
Posted: Thu Aug 01, 2013 2:10 pm
I was trying to define a border to exit units and I remembered in Rommel expansion you get a similar rutine.
I tried that rutine, but there should be something wrong with the loop that checks units as the result is that all units with higer id are also removed:
- if you move the unit ID 0 to the border all units are removed (no matter where they are)
- if you move unit 1 to the border all units except unit id 0 are removed
- if you move unit 6 to the border al units with ID >= 6 are removed.
- etc
The rutine is Rescue() and taked from AXIS10.BSF, is called from Tick()
FUNCTION RescueUnits()
{
int id ;
int i ;
for(i=0;i<GetUnitCount(0);i++)
{
id = GetUnitID(0, i) ;
if( GetUnitActive( id ) == 1)
{
if( GetUnitY(id) == 16 ) // 16 is the border
{
// rescue it
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;
// anything loaded on it?
if( GetLoadedUnit(id) != -1 )
{
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;
RemoveUnit( GetLoadedUnit(id), 1 ) ;
}
RemoveUnit(id, 1) ;
}
}
}
}
I tried that rutine, but there should be something wrong with the loop that checks units as the result is that all units with higer id are also removed:
- if you move the unit ID 0 to the border all units are removed (no matter where they are)
- if you move unit 1 to the border all units except unit id 0 are removed
- if you move unit 6 to the border al units with ID >= 6 are removed.
- etc
The rutine is Rescue() and taked from AXIS10.BSF, is called from Tick()
FUNCTION RescueUnits()
{
int id ;
int i ;
for(i=0;i<GetUnitCount(0);i++)
{
id = GetUnitID(0, i) ;
if( GetUnitActive( id ) == 1)
{
if( GetUnitY(id) == 16 ) // 16 is the border
{
// rescue it
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;
// anything loaded on it?
if( GetLoadedUnit(id) != -1 )
{
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;
RemoveUnit( GetLoadedUnit(id), 1 ) ;
}
RemoveUnit(id, 1) ;
}
}
}
}