Exemplo n.º 1
0
bool KillCalculator::verticalKillSearch(int x, int y) const
{
	for(int baseY = 0; baseY <= 2; ++baseY)
	{
		if((getBlockType(x, y + baseY - 2) == getBlockType(x, y + baseY - 1)) &&
			(getBlockType(x, y + baseY - 1) == getBlockType(x, y + baseY)))
		{
			return true;
		}
	}
	return false;
}
Exemplo n.º 2
0
bool KillCalculator::horizontalKillSearch(int x, int y) const
{
	for(int baseX = 0; baseX <= 2; ++baseX)
	{
		if((getBlockType(x + baseX - 2, y) == getBlockType(x + baseX - 1, y)) &&
			(getBlockType(x + baseX - 1, y) == getBlockType(x + baseX, y)))
		{
			return true;
		}
	}
	return false;
}
Exemplo n.º 3
0
bool WorldMap::updateFluid( int columnIndex ) {
  // need four neighbors?

  bool changesMade = false;

  v3di_t worldPosition;

  int highestBlockHeight = mColumns[columnIndex].getHighestBlockHeight ();
  int lowestBlockHeight = mColumns[columnIndex].getLowestBlockHeight ();

  char blockType;

  for (worldPosition.y = highestBlockHeight; worldPosition.y >= lowestBlockHeight; worldPosition.y--) {
    for (int z = 0; z < WORLD_CHUNK_SIDE; z++) {
      worldPosition.z = mColumns[columnIndex].mWorldPosition.z + z;

      for (int x = 0; x < WORLD_CHUNK_SIDE; x++) {
        worldPosition.x = mColumns[columnIndex].mWorldPosition.x + x;

        blockType = getBlockType (worldPosition);

        if (gBlockData.get(blockType)->solidityType == BLOCK_SOLIDITY_TYPE_LIQUID) {
          changesMade |= updateLiquidBlock (blockType, columnIndex, worldPosition);
        }
      }
    }
  }

  if (changesMade) {
    // clean up the placeholders
    for (worldPosition.y = lowestBlockHeight; worldPosition.y <= highestBlockHeight; worldPosition.y++) {
      for (int z = -1; z <= WORLD_CHUNK_SIDE; z++) {
        worldPosition.z = mColumns[columnIndex].mWorldPosition.z + z;

        for (int x = -1; x <= WORLD_CHUNK_SIDE; x++) {
          worldPosition.x = mColumns[columnIndex].mWorldPosition.x + x;

          blockType = getBlockType (worldPosition);

          if (blockType >= BLOCK_TYPE_PLACEHOLDER) {
            setBlockType (worldPosition, blockType - BLOCK_TYPE_PLACEHOLDER);
          }
        }
      }
    }
  }

  return changesMade;
}
Exemplo n.º 4
0
vector<int> GridGenerator::getInfoOfBlock(int x, int y) { // 입력된 좌표와 연결되어 있는 블록의 정보 획득
												   // 빈칸의 정보: x좌표, y좌표, 길이, 방향(수평, 수직), 교차점의 개수
	int xCoordinate = -1;
	int yCoordinate = -1;
	int length = -1;
	int type = getBlockType(x, y);
	int intersection = -1;

	if (type == horizontal) { // 연결된 블록이 수평인 경우
		xCoordinate = x;
		yCoordinate = horizontalCoordinateFinder(x, y);
		length = horizontalSquareCounter(x, y);
		int count = 0;
		for (int i = yCoordinate; i < length + yCoordinate; i++) {
			if (verticalSquareCounter(xCoordinate, i) > 1) {
				count++;
			}
		}
		intersection = count;
	}
	else if (type == vertical) { // 연결된 블록이 수직인 경우
		xCoordinate = verticalCoordinateFinder(x, y);
		yCoordinate = y;
		length = verticalSquareCounter(x, y);
		int count = 0;
		for (int i = xCoordinate; i < length + xCoordinate; i++) {
			if (horizontalSquareCounter(i, yCoordinate) > 1) {
				count++;
			}
		}
		intersection = count;
	}
	else if (type == crossing) {  // 좌표가 교차점인 경우는, 정보가 중복되므로 닫힌 칸인 경우와 동일하게 처리
		xCoordinate = 0;
		yCoordinate = 0;
		length = 0;
		type = 0;
		intersection = 0;
	}
	else if (type == closed) { // 닫힌 칸, 즉 "X"인 경우
		xCoordinate = 0;
		yCoordinate = 0;
		length = 0;
		type = 0;
		intersection = 0;
	}

	vector<int> blockInfo; // 교차점, 길이, x 좌표, y 좌표, 유형 순으로 vector에 삽입
	// 이 vector들을 set 자료구조에 저장하기 때문에, 먼저 교차점의 개수에 따라 오름차순으로 정렬, 
	// 그 다음에는 길이의 크기에 따라 오름차순으로 정렬됨.
	// 따라서, 나중에 블록에 낱말을 삽입할 때, 교차점이 많고 길이가 긴 블록부터 낱말을 채우는 것이 유리하기 때문에,
	// 꼬리에서부터 머리 방향으로 set을 순회
	blockInfo.push_back(intersection);
	blockInfo.push_back(length);
	blockInfo.push_back(xCoordinate);
	blockInfo.push_back(yCoordinate);
	blockInfo.push_back(type);
	
	return blockInfo;  // vector 반환
}
Exemplo n.º 5
0
/*
 *Removes DEADENDS from list
 */
void cleanList(MazeMap maze, PathList list) {

    list->current = list->start;
    while(list->current->next != NULL)  {
        if(getBlockType(maze, list->start->row, list->start->col) == DEADEND)   {
            PathNode startTemp = list->start;
            list->current = list->start = list->start->next;
            free(startTemp);
			list->nItems--;
        } if(getBlockType(maze,list->current->next->row, list->current->next->col) == DEADEND)  {
                PathNode nextTemp = list->current->next->next;
                free(list->current->next);
                list->current->next = nextTemp;
				list->nItems--;
        } else {
            list->current = list->current->next;
        }
    }
}
Exemplo n.º 6
0
void ActorComponent::setPosition(Entity &entity, const Point &p)
{
    // Update blockmap
    if (MapComposite *mapComposite = entity.getMap())
    {
        Map *map = mapComposite->getMap();
        int tileWidth = map->getTileWidth();
        int tileHeight = map->getTileHeight();
        if ((mPos.x / tileWidth != p.x / tileWidth
            || mPos.y / tileHeight != p.y / tileHeight))
        {
            map->freeTile(mPos.x / tileWidth, mPos.y / tileHeight,
                          getBlockType());
            map->blockTile(p.x / tileWidth, p.y / tileHeight, getBlockType());
        }
    }

    mPos = p;
}
Exemplo n.º 7
0
void ActorComponent::removed(Entity *entity)
{
    // Free the map position
    if (MapComposite *mapComposite = entity->getMap())
    {
        Map *map = mapComposite->getMap();
        int tileWidth = map->getTileWidth();
        int tileHeight = map->getTileHeight();
        Point oldP = getPosition();
        map->freeTile(oldP.x / tileWidth, oldP.y / tileHeight, getBlockType());
    }
}
Exemplo n.º 8
0
bool WorldMap::isBoundingBoxInLiquid(const BoundingBox& boundingBox) const {
  for (int z = (int)(floor(boundingBox.mNearCorner.z)); z <= (int)(floor(boundingBox.mFarCorner.z)); z++) {
    for (int y = (int)(floor(boundingBox.mNearCorner.y)); y <= (int)(floor(boundingBox.mFarCorner.y)); y++) {
      for (int x = (int)(floor(boundingBox.mNearCorner.x)); x <= (int)(floor(boundingBox.mFarCorner.x)); x++) {
        if (gBlockData.get(getBlockType(v3di_v(x, y, z)))->solidityType == BLOCK_SOLIDITY_TYPE_LIQUID) {
          return true;
        }
      }
    }
  }

  return false;
}
Exemplo n.º 9
0
void ActorComponent::mapChanged(Entity *entity)
{
    const Point p = getPosition();

    Map *map = entity->getMap()->getMap();
    int tileWidth = map->getTileWidth();
    int tileHeight = map->getTileHeight();
    map->blockTile(p.x / tileWidth, p.y / tileHeight, getBlockType());
    /* the last line might look illogical because the current position is
     * invalid on the new map, but it is necessary to block the old position
     * because the next call of setPosition() will automatically free the old
     * position. When we don't block the position now the occupation counting
     * will be off.
     */
}
Exemplo n.º 10
0
Stmt lowerTranspose(Var target, const IndexExpr* iexpr,
                    Environment* env, Storage* storage) {
  simit_iassert(isa<IndexedTensor>(iexpr->value));
  simit_iassert(isa<VarExpr>(to<IndexedTensor>(iexpr->value)->tensor));

  Var source = to<VarExpr>(to<IndexedTensor>(iexpr->value)->tensor)->var;
  auto sourceIndex = storage->getStorage(source).getTensorIndex();
  auto targetIndex = storage->getStorage(target).getTensorIndex();

  auto sourceType = source.getType().toTensor();
  auto iRange   = sourceType->getOuterDimensions()[0];

  Var  i("i",  Int);
  Var ij("ij", Int);
  Var  j("j",  Int);

  Var locVar(INTERNAL_PREFIX("locVar"), Int);
  Stmt locStmt = CallStmt::make({locVar}, intrinsics::loc(),
                                {Load::make(sourceIndex.getColidxArray(),ij), i,
                                 targetIndex.getRowptrArray(),
                                 targetIndex.getColidxArray()});
  Stmt body;
  auto blockType = *sourceType->getBlockType().toTensor();
  if (blockType.order() == 0) {  // Not blocked
    body = Store::make(target, locVar, Load::make(source, ij));
  }
  else {  // Blocked
    simit_iassert(blockType.order() == 2);
    Var ii("ii", Int);
    Var jj("jj", Int);
    auto d1 = blockType.getOuterDimensions()[0];
    auto d2 = blockType.getOuterDimensions()[1];
    Expr l1 = Length::make(d1);
    Expr l2 = Length::make(d2);

    body = Store::make(target, locVar*l1*l2 + ii*l2 + jj,
                       Load::make(source, ij*l1*l2 + ii*l2 + jj));

    body = For::make(jj, ForDomain(d2), body);
    body = For::make(ii, ForDomain(d1), body);
  }
  simit_iassert(body.defined());

  Expr start = Load::make(sourceIndex.getRowptrArray(), i);
  Expr stop  = Load::make(sourceIndex.getRowptrArray(), i+1);
  Stmt innerLoop  = ForRange::make(ij, start, stop, Block::make(locStmt, body));
  return For::make(i, iRange, innerLoop);
}
Exemplo n.º 11
0
void KillCalculator::calculateKills()
{
	for(int i = 0; i < NUM_BLOCK_ROWS; ++i)
	{
		for(int j = 0; j < NUM_BLOCK_COLUMNS; ++j)
		{
			blockKills[i][j] = false;
			if(getBlockType(j, i) == -1)
			{
				continue;
			}
			if(horizontalKillSearch(j, i) || verticalKillSearch(j, i))
			{
				blockKills[i][j] = true;
			}
		}
	}
}
Exemplo n.º 12
0
void drawPiece(int x, int y, int thePiece, int pRot)
{
    color_t pColor;
    int newX, newY;
    getPiecePosition( x, y,  &newX, &newY );

    for (int i = 0; i < PIECE_BLOCKS; i++){
        for (int j = 0; j < PIECE_BLOCKS; j++){
            int cTest = getBlockType(thePiece, pRot, j, i);
            if (cTest == 1) pColor = color_from_name("orange");
            else if (cTest == 2) pColor = color_from_name("blue");

            if (cTest != 0){
                terminal_color(pColor);
                terminal_put(newX + i, newY + j, 0x2588);
            }
        }
    }
}
Exemplo n.º 13
0
double WorldMap::getViscosity(const BoundingBox& boundingBox) const {
  double maxViscosity = 0.0;

  int startX = (int)(floor(boundingBox.mNearCorner.x));
  int endX = (int)(floor(boundingBox.mFarCorner.x));

  int startY = (int)(floor(boundingBox.mNearCorner.y));
  int endY = (int)(floor(boundingBox.mFarCorner.y));

  int startZ = (int)(floor(boundingBox.mNearCorner.z));
  int endZ = (int)(floor(boundingBox.mFarCorner.z));

  for (int z = startZ; z <= endZ; z++) {
    for (int y = startY; y <= endY; y++) {
      for (int x = startX; x <= endX; x++) {
        maxViscosity = max(maxViscosity, gBlockData.get(getBlockType(v3di_v(x, y, z)))->viscosity);
      }
    }
  }

  return maxViscosity;
}
Exemplo n.º 14
0
// if boundingBox intersects any blocks with health altering properties
// (e.g. lava, poison, fairy water...) return the sum of damage/healing
double WorldMap::getHealthEffects(const BoundingBox& boundingBox) const {
  double totalHealthEffect = 0.0;

  int startX = (int)(floor(boundingBox.mNearCorner.x));
  int endX = (int)(floor(boundingBox.mFarCorner.x));

  int startY = (int)(floor(boundingBox.mNearCorner.y));
  int endY = (int)(floor(boundingBox.mFarCorner.y));

  int startZ = (int)(floor(boundingBox.mNearCorner.z));
  int endZ = (int)(floor(boundingBox.mFarCorner.z));

  for (int z = startZ; z <= endZ; z++) {
    for (int y = startY; y <= endY; y++) {
      for (int x = startX; x <= endX; x++) {
        totalHealthEffect += gBlockData.get(getBlockType(v3di_v(x, y, z)))->healthEffect;
      }
    }
  }

  return totalHealthEffect;
}
Exemplo n.º 15
0
int detectExit(MazeMap maze, int row, int col)	{
	if((row == maze->width -1 || col == maze->height - 1 || row == 0 || col == 0)  && (getBlock(maze,row,col) == ' ') && (getBlockType(maze,row,col) != ENTRANCE) )	{
		return 1;
	}
	return 0;
}
Exemplo n.º 16
0
int WorldMap::countLiquidNeighbors( int blockType, const v3di_t& worldPosition ) const {
  int numWaterNeighbors = 0;

  // -x
  v3di_t neighborPosition = v3di_add (worldPosition, v3di_v (-1, 0, 0));
  char neighborType = getBlockType (neighborPosition);
  if (neighborType == blockType) {
    numWaterNeighbors++;

    neighborPosition = v3di_add (worldPosition, v3di_v (-2, 0, 0));
    char neighborType = getBlockType (neighborPosition);
    if (neighborType == blockType) {
      numWaterNeighbors++;
    }
  }

  // +x
  neighborPosition = v3di_add (worldPosition, v3di_v (+1, 0, 0));
  neighborType = getBlockType (neighborPosition);
  if (neighborType == blockType) {
    numWaterNeighbors++;

    neighborPosition = v3di_add (worldPosition, v3di_v (+2, 0, 0));
    char neighborType = getBlockType (neighborPosition);
    if (neighborType == blockType) {
      numWaterNeighbors++;
    }
  }

  // -y
//  neighborPosition = v3di_add (worldPosition, v3di_v (0, -1, 0));
//  neighborType = getBlockType (neighborPosition);
//  if (neighborType == blockType) {
//    numWaterNeighbors++;
//  }

  // +y
  neighborPosition = v3di_add (worldPosition, v3di_v (0, +1, 0));
  neighborType = getBlockType (neighborPosition);
  if (neighborType == blockType) {
    numWaterNeighbors += 2;

    neighborPosition = v3di_add (worldPosition, v3di_v (0, +2, 0));
    char neighborType = getBlockType (neighborPosition);
    if (neighborType == blockType) {
      numWaterNeighbors++;
    }
  }

  // -z
  neighborPosition = v3di_add (worldPosition, v3di_v (0, 0, -1));
  neighborType = getBlockType (neighborPosition);
  if (neighborType == blockType) {
    numWaterNeighbors += 1;

    neighborPosition = v3di_add (worldPosition, v3di_v (0, 0, -2));
    char neighborType = getBlockType (neighborPosition);
    if (neighborType == blockType) {
      numWaterNeighbors++;
    }
  }

  // +z
  neighborPosition = v3di_add (worldPosition, v3di_v (0, 0, +1));
  neighborType = getBlockType (neighborPosition);
  if (neighborType == blockType) {
    numWaterNeighbors++;

    neighborPosition = v3di_add (worldPosition, v3di_v (0, 0, +2));
    char neighborType = getBlockType (neighborPosition);
    if (neighborType == blockType) {
      numWaterNeighbors++;
    }
  }

  return numWaterNeighbors;
}
Exemplo n.º 17
0
bool WorldMap::updateLiquidBlock( int blockType, int columnIndex, const v3di_t& worldPosition ) {
  char neighborType;

  char air = BLOCK_TYPE_AIR;
  char liquid = blockType + BLOCK_TYPE_PLACEHOLDER;

  // check relevant neigh-bros
  v3di_t neighborPosition;

  // down first
  neighborPosition = v3di_add (worldPosition, v3di_v (0, -1, 0));
  neighborType = getBlockType (neighborPosition);
  if (neighborType == BLOCK_TYPE_AIR ||
    neighborType == BLOCK_TYPE_INVALID) {
    setBlockType (worldPosition, air);
    setBlockType (neighborPosition, liquid);

    // all done for this time slice
    return true;
  }

  bool changesMade = false;

  int numWaterNeighbors = countLiquidNeighbors( blockType, worldPosition );

  if (numWaterNeighbors < 2) {
    setBlockType (worldPosition, air);

    // all done for this time slice
    return true;
  }
  else {
    // -x
    neighborPosition = v3di_add (worldPosition, v3di_v (-1, 0, 0));
    neighborType = getBlockType (neighborPosition);
    if (neighborType == BLOCK_TYPE_AIR) {
      setBlockType (neighborPosition, liquid);
      changesMade = true;
    }

    // +x
    neighborPosition = v3di_add (worldPosition, v3di_v (+1, 0, 0));
    neighborType = getBlockType (neighborPosition);
    if (neighborType == BLOCK_TYPE_AIR) {
      setBlockType (neighborPosition, liquid);
      changesMade = true;
    }

    // -z
    neighborPosition = v3di_add (worldPosition, v3di_v (0, 0, -1));
    neighborType = getBlockType (neighborPosition);
    if (neighborType == BLOCK_TYPE_AIR) {
      setBlockType (neighborPosition, liquid);
      changesMade = true;
    }

    // +z
    neighborPosition = v3di_add (worldPosition, v3di_v (0, 0, +1));
    neighborType = getBlockType (neighborPosition);
    if (neighborType == BLOCK_TYPE_AIR) {
      setBlockType (neighborPosition, liquid);
      changesMade = true;
    }
  }

  return changesMade;
}
Exemplo n.º 18
0
void WorldMap::updateBlockVisibility(int columnIndex) {
  v3di_t relativePosition;
  v3di_t worldPosition;
  v3di_t chunkPosition;
  v3di_t neighborPosition;
  v3di_t neighborAdd;

  BYTE type;
  BYTE faceVisibility;
  double blockAlpha;
  int solidityType;
  int neighborType;
  double neighborAlpha;

  for (size_t chunkIndex = 0; chunkIndex < mColumns[columnIndex].mWorldChunks.size(); chunkIndex++) {
    chunkPosition = mColumns[columnIndex].mWorldChunks[chunkIndex]->mWorldPosition;

    for (relativePosition.z = 0; relativePosition.z < WORLD_CHUNK_SIDE; relativePosition.z++) {
      for (relativePosition.y = 0; relativePosition.y < WORLD_CHUNK_SIDE; relativePosition.y++) {
        for (relativePosition.x = 0; relativePosition.x < WORLD_CHUNK_SIDE; relativePosition.x++) {
          worldPosition = v3di_add(chunkPosition, relativePosition);

          type = mColumns[columnIndex].getBlockType(worldPosition);
          blockAlpha = gBlockData.get(type)->alpha;
          solidityType = gBlockData.get(type)->solidityType;

          faceVisibility = 0;

          if (solidityType == BLOCK_SOLIDITY_TYPE_PLANT) {
            faceVisibility = 0xff;
            setBlockVisibility(worldPosition, faceVisibility);
          }
          // BLOCK_SOLIDITY_TYPE_GLASS
          else if (solidityType == BLOCK_SOLIDITY_TYPE_GLASS)
          {
            for (int i = 0; i < NUM_BLOCK_SIDES; i++) {
              neighborAdd = gBlockNeighborAddLookup[i];
              neighborPosition = v3di_add(worldPosition, neighborAdd);
              neighborType = getBlockType(neighborPosition);
              neighborAlpha = gBlockData.get(neighborType)->alpha;

              if (neighborType != type &&
                neighborAlpha < 1.0)
              {
                faceVisibility |= gBlockSideBitmaskLookup[i];
              }
            }

            setBlockVisibility (worldPosition, faceVisibility);
          }
          // TRANSLUCENT
          else if (blockAlpha > 0.0 &&
            blockAlpha < 1.0)
          {
            for (int i = 0; i < NUM_BLOCK_SIDES; i++) {
              neighborAdd = gBlockNeighborAddLookup[i];
              neighborPosition = v3di_add(worldPosition, neighborAdd);
              neighborType = getBlockType(neighborPosition);
              neighborAlpha = gBlockData.get(neighborType)->alpha;

              if (neighborType != type &&
                neighborAlpha < 1.0)
              {
                faceVisibility |= gBlockSideBitmaskLookup[i];
              }
            }

            setBlockVisibility(worldPosition, faceVisibility);
          }
          // NON-TRANSLUCENT
          else if (blockAlpha == 1.0) {
            for (int i = 0; i < NUM_BLOCK_SIDES; i++) {
              neighborAdd = gBlockNeighborAddLookup[i];
              neighborPosition = v3di_add (worldPosition, neighborAdd);
              neighborType = getBlockType (neighborPosition);
              neighborAlpha = gBlockData.get(neighborType)->alpha;

              // ha ha...
//              if (neighborType == BLOCK_TYPE_INVALID) {
//                neighborAlpha = 1.0;
//              }

              if (neighborAlpha < 1.0 ||
                gBlockData.get(neighborType)->solidityType == BLOCK_SOLIDITY_TYPE_PLANT ||
                gBlockData.get(neighborType)->solidityType == BLOCK_SOLIDITY_TYPE_GLASS)
              {
                faceVisibility |= gBlockSideBitmaskLookup[i];
              }
            }

            setBlockVisibility (worldPosition, faceVisibility);
          }

          if (faceVisibility == 0) {
            //            mNumHiddenBlocks++;
          }
        }
      }
    }
  }

  mColumns[columnIndex].mNeedShadowVolume = false;
  mColumns[columnIndex].mNeedVisibility = false;
  mColumns[columnIndex].mNeedLightingApplied = true;
  mColumns[columnIndex].mNeedDisplayList = false;
}