Пример #1
0
int Map::updateInfectionState( void )
{
  int counter = 0;

  for( int y = 0; y < levels; y++ )
    for( int z = 0; z < height; z++ )
      for(  int x = 0; x < width; x++ )
      {
        int infection = getInfection(x, y, z);
        if(infection < MAX_INFECTION)
          continue;

        Cube *cube;

        for( int i = -1; i < 2; i++ )
          for( int j = -1; j < 2; j++ )
            for( int k = -1; k < 2; k++ )
            {
              if(!i &&!j && !k)
                continue;

              cube = getCube(x+k, y+i, z+j);
              if(cube && !cube->isTransparent())
              {
                int inf = cube->getInfection();
                counter += cube->incInfection() - inf;
              }
            }

        getCube(x,y,z)->setInfection(0);
        getCube(x,y,z)->setTransparent(true);
      }

  return counter;
}
Пример #2
0
unsigned char HealAgent::makePlan(Map *map, QList<CubeBasic *> enemy, int coord[])
{
  qDebug() << "Heal step!";

  Cube *cube;
  unsigned char plan = 0;
  for( int y = coord[1]-1; y < coord[1]+2; y++ )
    for( int z = coord[2]-1; z < coord[2]+2; z++ )
      for( int x = coord[0]-1; x < coord[0]+2; x++ )
      {
        cube = map->getCube(x,y,z);
        if(!cube)
          continue;

        if(x == coord[0] && y == coord[1] && z == coord[2])
          continue;

        if(x > coord[0])
          plan = plan | (1 << 4);
        else if(x < coord[0])
          plan = plan | (1 << 5);

        if(y > coord[1])
          plan = plan | (1 << 2);
        else if(y < coord[1])
          plan = plan | (1 << 3);

        if(z > coord[2])
          plan = plan | (1 << 6);
        else if(z < coord[2])
          plan = plan | (1 << 7);

        if(isEnemy(map, enemy, x,y,z))
        {
          plan = plan | 3;

          return plan;
        }

        if(cube->getInfection())
        {
          plan = plan | 1;

          return plan;
        }

        plan = 0;
      }


  int i, j, k;
  cube = NULL;
  while(!cube)
  {
    i = qrand() % 3 - 1;
    j = qrand() % 3 - 1;
    k = qrand() % 3 - 1;

    if(i > 1)
      i = 1;
    if(j > 1)
      j = 1;
    if(k > 1)
      k = 1;

    if(!i && !j && !k)
      continue;

    cube = map->getCube(coord[0] + i, coord[1] + j, coord[2] + k);
    qDebug() << "CUBE: " << cube << coord[0] + i << coord[1] + j << coord[2] + k;
    if(!cube)
      continue;

    if(!cube->isTransparent())
      cube = NULL;
  }

  plan = 0;
  if(k == -1)
    plan = plan | (1 << 7);
  if(k == 1)
    plan = plan | (1 << 6);

  if(i == -1)
    plan = plan | (1 << 5);
  if(i == 1)
    plan = plan | (1 << 4);

  if(j == -1)
    plan = plan | (1 << 3);
  if(j == 1)
    plan = plan | (1 << 2);

  setPlan(plan);

  return plan;
}