int Infantry::Advance()
{
int mpc;
int i, o, k;
int x,y,Move = On, dam;
int BuildingHeight = 0;
int BuildingModifier = 0;

x = Vector.x + vec[Vector.head/30].x;
y = Vector.y + vec[Vector.head/30].y;

// if (AdvanceOpen())
// AdvanceOpen
int UnitsInHex=0;
for (i=0;i<Units;i++)
  if ( (x == unit[i]->Vector.x && \
        y == unit[i]->Vector.y ) ) {
        UnitsInHex ++;
        if (Options.Stacking==On)
          if (unit[i]->Side!=Side)
   	    Move = Off; // Can't stack with an enemy on the ground
          else {
            if (Stacked == Off)
              LastVector = Vector;              
            Stacked = On;
            }
        }

// Max Units in hex
//if (UnitsInHex >= 5) Move = Off, Stacked = Off;

  // Hex Open, Unit can Advance
/*
if (x<Xmin || x >= Xmax) // Mech Out Off bounds
  {Move = Off;MP = 0;
  if(Options.Retreat==On) Retreat(0); }

if (y<Ymin || y >= Ymax) // Mech Out Off bounds
  {Move = Off;MP = 0;
  if(Options.Retreat==On) Retreat(0); }
*/
  if(MoveType<0) // If a Mech is Jumping, can't Jump over obstacle
    if(Altitude+Jump < MPH[Map.Hex[x][y].Alt])
      Move = Off;

// Buildings
  if (Map.Hex[x][y].Type == 'L') BuildingModifier = 1, BuildingHeight = 1;
  if (Map.Hex[x][y].Type == 'M') BuildingModifier = 2, BuildingHeight = 2;
  if (Map.Hex[x][y].Type == 'H') BuildingModifier = 3, BuildingHeight = 2;
  if (Map.Hex[x][y].Type == 'A') BuildingModifier = 5, BuildingHeight = 3;
/*
  if (BuildingModifier != 0 && MoveType >= 0) // Buildings on Foot
    if (PilotingRoll >= genPilotModifier()+BuildingModifier) {
      Move = On;
        if (Tons > Map.Hex[x][y].Index) DamageHex(x,y,Map.Hex[x][y].Index), BuildingHeight = 0;}
      else Move = Off;
*/
  if (Position+1 <= - MPH[Map.Hex[Vector.x][Vector.y].Alt] && Map.Hex[Vector.x][Vector.y].Type == 'w') Move = Off;
//    else Submersed = Off;

  if (MPC[Map.Hex[x][y].Type] == 20 && MoveType>=0) // Impassable by Foot
    Move=Off;
  if (Map.Hex[x][y].Fire == 'f' || Map.Hex[x][y].Fire == 'F')
    Move=Off;

if (Move == On) {

  mpc = MPC[Map.Hex[x][y].Type];
  if (onRiver(x,y)) mpc ++;
  if (onRoad(Vector.x,Vector.y) && onRoad(x,y))
    mpc = 1, BuildingHeight = (RoadHeight(x,y) - MPH[Map.Hex[x][y].Alt])>=0?(RoadHeight(x,y) - MPH[Map.Hex[x][y].Alt]):0;

//  mpc += abs(MPH[Map.Hex[Vector.x][Vector.y].Alt] - MPH[Map.Hex[x][y].Alt]);
  mpc += 2*abs(Altitude - MPH[Map.Hex[x][y].Alt]-BuildingHeight);

  MoveType< 0?mpc =1:mpc; // If a Mech is Jumping, only one MP / HEX

//  Submersed==On?mpc+=4:mpc; // If Mech under water

  if (HexesMoved == 0 || MP >= mpc) { // Can't advance if Infantry lacks MP

    if (onRoad(x,y)) OnRoad = On;
      else OnRoad = Off;

    Altitude = MPH[Map.Hex[x][y].Alt] + BuildingHeight;
//      HeatTurn += 2;

    drawHex(Vector.x,Vector.y);

    Vector.x = x;
    Vector.y = y;

  if (UnitsInHex == 0) {
    if (Stacked = On)
      drawUnits();
      Stacked = Off;
      }

    drawMech(Vector,UnitColour,Position);
//    drawUnit();
  
//    if (Carrying >= 0) Item[Carrying].Vector = Vector; // If Mech moves, Item moves with it

//    if (MoveType >= 1)
//      if (Map.Hex[Vector.x][Vector.y].Type == 'w' && PilotingRoll < (genPilotModifier()-1)) putString("Slid Fall",Colour),getkey(),Fall(0); // Mech can fall if it enters water hex
//    if ((Map.Hex[x][y].Type == 'w') && (PilotingRoll < (genPilotModifier()-1))) putString("Slid Fall",Colour),getkey(),Fall(0); // Mech can fall if it enters water hex

    MP -= mpc;
    HexesMoved ++;
    }
    else Move = Off; // Not Enough MP
  }

return Move;
}


int Infantry::Reverse()
{
int mpc;
int i, o, k;
int x,y,Move = On, dam;
int BuildingHeight = 0;
int BuildingModifier = 0;
mpc = MPH[Map.Hex[Vector.x][Vector.y].Alt];
i = Vector.head + 180;
if (i > 360) i -= 360;
if (i <   0) i += 360;
x = Vector.x + vec[i/30].x;
y = Vector.y + vec[i/30].y;

// if (AdvanceOpen())
// AdvanceOpen
if (MoveType == 1) {
int UnitsInHex=0;
for (i=0;i<Units;i++)
  if ( (x == unit[i]->Vector.x && \
        y == unit[i]->Vector.y ) ) {
        UnitsInHex ++;
        if (Options.Stacking==On)
          if (unit[i]->Side!=Side)
   	    Move = Off; // Can't stack with an enemy on the ground
          else {
            if (Stacked == Off)
              LastVector = Vector;              
            Stacked = On;
            }
        }

  // Hex Open, Unit can Advance
/*
if (x<=Xmin || x >= Xmax) { // Mech Out Off bounds
  Move = Off,MP = 0;
  if(Options.Retreat==On) Retreat(0); }

if (y<=Ymin || y >= Ymax) { // Mech Out Off bounds
  Move = Off,MP = 0;
  if(Options.Retreat==On) Retreat(0); }
*/
  if(MoveType<0) // If a Mech is Jumping, can't Jump over obstacle
    if(Altitude+Jump < MPH[Map.Hex[x][y].Alt])
      Move = Off;

// Buildings
  if (Map.Hex[x][y].Type == 'L') BuildingModifier = 1, BuildingHeight = 1;
  if (Map.Hex[x][y].Type == 'M') BuildingModifier = 2, BuildingHeight = 2;
  if (Map.Hex[x][y].Type == 'H') BuildingModifier = 3, BuildingHeight = 2;
  if (Map.Hex[x][y].Type == 'A') BuildingModifier = 5, BuildingHeight = 3;

  if (BuildingModifier != 0 && MoveType >= 0) // Buildings on Foot
      Move = Off;

// Water Submersion
  if (Position+1 <= - MPH[Map.Hex[Vector.x][Vector.y].Alt] && Map.Hex[Vector.x][Vector.y].Type == 'w') Move=Off;//Submersed = On;
//    else Submersed = Off;

  if (MPC[Map.Hex[x][y].Type] == 20 && MoveType>=0) // Impassable by Foot
    Move=Off;
  if (Map.Hex[x][y].Fire == 'f' || Map.Hex[x][y].Fire == 'F')
    Move=Off;
    
if (Move == On) {

  mpc = MPC[Map.Hex[x][y].Type];
  if (onRiver(x,y)) mpc ++;
  if (onRoad(Vector.x,Vector.y) && onRoad(x,y))
    mpc = 1, BuildingHeight = (RoadHeight(x,y) - MPH[Map.Hex[x][y].Alt])>=0?(RoadHeight(x,y) - MPH[Map.Hex[x][y].Alt]):0;
    
//  mpc += abs(MPH[Map.Hex[Vector.x][Vector.y].Alt] - MPH[Map.Hex[x][y].Alt]);
  mpc += 2*abs(Altitude - MPH[Map.Hex[x][y].Alt]-BuildingHeight);

  MoveType< 0?mpc =1:mpc; // If a Mech is Jumping, only one MP / HEX
//  Position==0?mpc+=4:mpc; // If Mech is Prone, crawl costs 4 MP
//  Submersed==On?mpc+=4:mpc; // If Mech under water

  if (HexesMoved == 0 || MP >= mpc) { // Can't advance if Mech lacks MP, MPC of 20 denotes Impassable

    if (onRoad(x,y)) OnRoad = On;
      else OnRoad = Off;

    Altitude = MPH[Map.Hex[x][y].Alt] + BuildingHeight;
//      HeatTurn += 2;

    drawHex(Vector.x,Vector.y);
    Vector.x = x;
    Vector.y = y;

    if (UnitsInHex == 0) {
      if (Stacked = On)
        for (i=0;i<Units;i++)
          unit[i]->drawUnit();
        Stacked = Off;
        }

    drawMech(Vector,UnitColour,Position);
//    drawUnit();

//    if (Carrying != -1) Item[Carrying].Vector = Vector; // If Mech moves, Item moves with it
//    if (Map.Hex[x][y].Type == 'w' && PilotingRoll < (genPilotModifier()-1-Pilot.FallBonus)) Fall(0); // Mech can fall if it enters water hex

    MP -= mpc;
    HexesMoved ++;
    Reversed ++;
    }
    else Move = Off;
  }
}
//  else Charge(Unit[i])

return Move;
}

int Infantry::TurnLeft()
{
//if (onRoad(Vector.x,Vector.y) == On && RoadHeight(Vector.x,Vector.y) == Altitude && MoveType >= 2)
//  if (PilotingRoll < genPilotModifier()+TargetEvasion[HexesMoved]-1) Skid();

Vector.head -= 60;
if (Vector.head < 0) Vector.head += 360;
//if (MP > 0) MoveType < 0 ? MP : MP -= 1; // If unit Jumps no MP cost

  drawHex(Vector.x,Vector.y);
  drawMech(Vector,UnitColour,Position);
//  drawUnit();

return 1;
}

int Infantry::TurnRight()
{
//if (onRoad(Vector.x,Vector.y) == On && RoadHeight(Vector.x,Vector.y) == Altitude && MoveType >= 2)
//  if (PilotingRoll < genPilotModifier()+TargetEvasion[HexesMoved]-1) Skid();

Vector.head += 60;
if (Vector.head >= 360) Vector.head -= 360;
//if (MP > 0) MoveType < 0 ? MP : MP -= 1;// If unit Jumps no MP cost

  drawHex(Vector.x,Vector.y);
  drawMech(Vector,UnitColour,Position);
//  drawUnit();
  
return 1;
}
