Code: Select all
FUNCTION PlaceUnit(x, y, facing, side, team, type)
{
int id ;
int radius ;
int x1 ;
int y1 ;
int dx ;
int dy ;
int deploy ;
// place the unit out of map bounderies, so we can test its type later on
id = AddUnit(15, 15, side, type) ;
// check if tile is unoccupied and not blocked
if( (GetUnitOnTile(x, y) == -1) && (IsTileBlocked(id, x, y) == 0) )
{
dx = x ;
dy = y ;
deploy = 1 ;
}
else
{
// if target tile was occupied, try adjacent tiles
radius = 1 ;
for(x1=0; x1<=radius*2; x1++)
{
for(y1=0; y1<=radius*2; y1++)
{
dx = x+x1-radius ;
dy = y+y1-radius ;
if( (IsTileBlocked(id, dx, dy) == 0) && (IsValidTile(dx, dy) == 1) && (deploy == 0) && (GetTileCost(id, dx, dy) <GetBaseAttrib> -1 )
{
LoadUnit(GetGlobal("gTransport"), id) ;
SetGlobal("gTransport", id) ;
}
else
{
// remove unit if transport does not exist
RemoveUnit(id, 1) ;
}
}
else
{
UnitDeploy(id, dx, dy) ;
// Set team
SetUnitTeam(id, team) ;
// Set facing
SetUnitFacing(id, facing * 45) ;
// Store id in global variable
SetGlobal("gTransport", id) ;
}
}
else
{
RemoveUnit(id, 1) ;
// mark gTransport as invalid in case id was a transport unit
SetGlobal("gTransport", -1) ;
}
}
Code: Select all
SetUnitTeam(id, team) ;Code: Select all
if( facing == 8 )Code: Select all
FUNCTION PlaceUnit2(x, y, facing, side, team, type)
{
int id ;
int radius ;
int x1 ;
int y1 ;
int dx ;
int dy ;
int deploy ;
// place the unit out of map bounderies, so we can test its type later on
id = AddUnit(15, 15, side, type) ;
// check if tile is unoccupied and not blocked
if( (GetUnitOnTile(x, y) == -1) && (IsTileBlocked(id, x, y) == 0) )
{
dx = x ;
dy = y ;
deploy = 1 ;
}
else
{
// if target tile was occupied, try adjacent tiles
radius = 1 ;
for(x1=0; x1<=radius*2; x1++)
{
for(y1=0; y1<=radius*2; y1++)
{
dx = x+x1-radius ;
dy = y+y1-radius ;
if( (IsTileBlocked(id, dx, dy) == 0) && (IsValidTile(dx, dy) == 1) && (deploy == 0) && (GetTileCost(id, dx, dy) <GetBaseAttrib> -1 )
{
//Fix team setting in case of loaded unit <------------------ here
SetUnitTeam(id, team) ;
LoadUnit(GetGlobal("gTransport"), id) ;
SetGlobal("gTransport", id) ;
}
else
{
// remove unit if transport does not exist
RemoveUnit(id, 1) ;
}
}
else
{
UnitDeploy(id, dx, dy) ;
// Set team
SetUnitTeam(id, team) ;
// Set facing
SetUnitFacing(id, facing * 45) ;
// Store id in global variable
SetGlobal("gTransport", id) ;
}
}
else
{
RemoveUnit(id, 1) ;
// mark gTransport as invalid in case id was a transport unit
SetGlobal("gTransport", -1) ;
}
}

