Пример #1
0
int _coberturaParcial(const std::vector<RayCell> v, int nivelDefensor, int nivelAtacante, const TMap & map){
  THex * infoDefensor = NULL, * infoAtacante = NULL;

  // Caso de Error 1 -> La posicion inicial es mala
  infoDefensor = map.getHex(v[0].p);
  if(infoDefensor == NULL)
    return 0;
  
  infoAtacante = map.getHex(v[v.size()-1].p);
  if(infoAtacante == NULL)
    return 0;

  // Caso de Error 2 -> Hay una sola casilla en el RayCell
  if(v.size() < 2)
    return 0;

  // Comprobamos si esta en agua -> Proporciona Cobertura Parcial
  if(infoDefensor->tipo == 2 && infoDefensor->nivel <= -1)
    return 1;

  // Si la altura del hexagono del atacante es mayor que la del defensor
  // Anula Cobertura Parcial del Defensor
  if(infoAtacante->nivel > infoDefensor->nivel)
    return 0;

  // Comprobamos los hexagonos intermedios entre el defensor y el atacante
  // Si hay un hexagono que tengo mi misma altura o superior -> Tengo Cobertura Parcial
  for(int i = 1; i < ((int) v.size() - 1); i++){
    if(ldvcellValidaCobertura(v[i], map, infoDefensor->nivel))
      return 1;
  }

  return 0;
}
Пример #2
0
/**
 * Devuelve true si c da Cobertura Parcial 
 * con una casilla adyacente de altura nivel de la casilla del Mech
 */
bool ldvcellValidaCobertura(RayCell c, const TMap & map, int nivel){
  THex * infoCell = NULL;
  THex * infoCellAlt = NULL;
  
  infoCell = map.getHex( c.p );
  if( infoCell != NULL ){
    if( infoCell->nivel > nivel){
      if( c.alt != NULL ){
	infoCellAlt = map.getHex( *c.alt );
	if( infoCellAlt != NULL ){
	  if( infoCellAlt->nivel > nivel){
	    return true;
	  }
	  else
	    return false;
	}
	else
	  return true;
      }
      else
	return true;
    }
    else
      return false;
  }
  else if( c.alt != NULL ){
    infoCellAlt = map.getHex( *c.alt );
    if( infoCellAlt != NULL ){
      if( infoCellAlt->nivel > nivel)
	return true;
      else
	return false;
    }
    else
      return false;
  }
  else
    return false;
}
Пример #3
0
/**
 * Devuelve true si c forma una linea de visión válida
 * con una casilla adyacente de altura nivelMech
 */
bool ldvcellValidaEle(RayCell c, const TMap & map, int nivel){
  THex * infoCell = NULL;
  THex * infoCellAlt = NULL;
  
  infoCell = map.getHex( c.p );
  if( infoCell != NULL )
    if( infoCell->nivel > nivel)
      return false;
  
  if( c.alt != NULL ){
    infoCellAlt = map.getHex( *c.alt );
    if( infoCellAlt != NULL ){
      if( infoCellAlt->nivel > nivel)
	return false;
    }
  }
  
  if( infoCell == NULL && infoCellAlt == NULL )
    return false;
  
  return true;
}
Пример #4
0
void ldvcellValidaObj(RayCell c, const TMap & map, Objetos_t & obj, int nivelMech){
  THex * infoCell = NULL;
  THex * infoCellAlt = NULL;
  Objetos_t objCell, objCellAlt;
  
  // Vemos los objetos en el hexagono
  infoCell = map.getHex( c.p );
  if( infoCell != NULL && (infoCell->nivel + 2) > nivelMech ){
    if( infoCell->objeto == 2 )
      objCell.bosqueDenso++;
    else if( infoCell->humo )
      objCell.humo++;
    else if( infoCell->objeto == 1 )
      objCell.bosqueDisperso++;
  }
  
  // Vemos los objetos en el Hexagono alternativo
  // En caso de existir
  if( c.alt != NULL ){
    infoCellAlt = map.getHex( *c.alt );
    if( infoCellAlt != NULL && (infoCellAlt->nivel + 2) > nivelMech){
      if( infoCellAlt->objeto == 2 )
	objCellAlt.bosqueDenso++;
      else if( infoCellAlt->humo )
	objCellAlt.humo++;
      else if( infoCellAlt->objeto == 1 )
	objCellAlt.bosqueDisperso++;
    }
  }

  // Comparamos a ver que Hexagono penaliza mas
  if(objCell.bosqueDenso > 0 || objCellAlt.bosqueDenso > 0)
    obj.bosqueDenso++;
  else if(objCell.humo > 0 || objCellAlt.humo > 0)
    obj.humo++;
  else if(objCell.bosqueDisperso > 0 || objCellAlt.bosqueDisperso > 0)
    obj.bosqueDisperso++;  
}
Пример #5
0
int _LdV(const std::vector<RayCell> v, int nivelOrig, int nivelDest, const TMap & map){
  THex * infoOrig = NULL, * infoDest = NULL;

  // Caso de Error 1 -> La posicion inicial es mala
  infoOrig = map.getHex(v[0].p);
  if(infoOrig == NULL)
    return 0;
  
  infoDest = map.getHex(v[v.size()-1].p);
  if(infoDest == NULL)
    return 0;

  // Caso de Error 2 -> Hay una sola casilla en el RayCell
  if(v.size() < 2)
    return 0;

  // Si alguno de los dos mechs estan completamente cubiertos por agua
  // NO HAY LDV
  if(cubiertoAgua(infoOrig, nivelOrig) ||
     cubiertoAgua(infoDest, nivelDest))
    return 0;

  // Si ha llegado aquí y son adyacentes -> SI hay LDV
  if((int)v.size() == 2)
    return 1;
  
  // Hay Hexagono intermedios entre el Origen y el Destino
  // Obtenemos las alturas relativas a las que estan los mechs
  // Sumamos a la altura del hexagono el nivel de los mechs (+0(tumbado) o +1(pie))
  int nivelHexOrigen = nivelOrig + infoOrig->nivel;
  int nivelHexDestino = nivelDest + infoDest->nivel;
  Objetos_t objetos;

  // Caso especial -> Haya un solo hexagono entre atacante y defensor
  if((int)v.size() == 3){
    if(!ldvcellValidaEle(v[1], map, nivelHexOrigen) ||
       !ldvcellValidaEle(v[1], map, nivelHexDestino))
      return 0;
    if(nivelHexOrigen >= nivelHexDestino)
      ldvcellValidaObj(v[1], map, objetos, nivelHexOrigen);
    else
      ldvcellValidaObj(v[1], map, objetos, nivelHexDestino);
  }
  else{
    // Casuisticas mas normales
    // Para cada hexagono de Ray Cast
    // Menos el 1º y el ultimo -> Donde estan los Mechs
    for(int i = 1; i < ((int)v.size() - 1); i++){
      // Si hexagono adyacente atacante tiene nivel mayor -> No LdV
      if(i == 1){
	if(!ldvcellValidaEle(v[i], map, nivelHexOrigen))
	  return 0;
	ldvcellValidaObj(v[i], map, objetos, nivelHexOrigen);
      }

      // Si hexagono adyacente defensor tiene nivel mayor -> No LdV
      if(i == ((int)v.size() - 2)){
	if(!ldvcellValidaEle(v[i], map, nivelHexDestino))
	  return 0;
	ldvcellValidaObj(v[i], map, objetos, nivelHexDestino);
      }

      // Para hexagono intermedios -> Si la altura es mayor a la de atacante y defensor
      // No LdV
      if(i != 1 && i != ((int)v.size() - 2)){
	if(!ldvcellValidaEle(v[i], map, nivelHexOrigen) &&
	   !ldvcellValidaEle(v[i], map, nivelHexDestino))
	  return 0;
	if(nivelHexOrigen >= nivelHexDestino)
	  ldvcellValidaObj(v[i], map, objetos, nivelHexOrigen);
	else
	  ldvcellValidaObj(v[i], map, objetos, nivelHexDestino);
      }
    }
  }

  // Comprobamos las posibles combinaciones de edificios, bosques y humos
  if(objetos.bosqueDisperso >= 3)
    return 0;
  else if(objetos.bosqueDisperso >= 1 && objetos.bosqueDenso >= 1)
    return 0;
  else if(objetos.bosqueDenso >= 2)
    return 0;
  else if(objetos.humo >= 2)
    return 0;
  else if(objetos.humo >= 1 && objetos.bosqueDisperso >= 1)
    return 0;

  return 1;
}