Exemple #1
0
void generateDirectMove(dungeon_t* dungeonPtr, monster* monsterPtr, int PCX, int PCY, int* dstX, int* dstY) {
    int targetX = monsterPtr->x;
    int targetY = monsterPtr->y;
    direction_t direction = calculateDirection(targetX, targetY, PCX, PCY);
    if (direction & north) {
        targetY--;
    }
    if (direction & east) {
        targetX++;
    }
    if (direction & south) {
        targetY++;
    }
    if (direction & west) {
        targetX--;
    }
    if (!(monsterPtr->abilities & MONSTER_TUNNELING)) {
        // Nontuneling
        if (isRock(dungeonPtr->grid, targetX, targetY)) {
            // Direct path is blocked, try orthogonal
            targetX = monsterPtr->x;
            targetY = monsterPtr->y;
            if (direction & north) {
                if (!isRock(dungeonPtr->grid, targetX, targetY - 1)) {
                    targetY--;
                }
            }
            if (direction & east) {
                if (!isRock(dungeonPtr->grid, targetX + 1, targetY)) {
                    targetX++;
                }
            }
            if (direction & south) {
                if (!isRock(dungeonPtr->grid, targetX, targetY + 1)) {
                    targetY++;
                }
            }
            if (direction & west) {
                if (!isRock(dungeonPtr->grid, targetX - 1, targetY)) {
                    targetX--;
                }
            }
        }
    }
    *dstX = targetX;
    *dstY = targetY;
}
Exemple #2
0
void Tile::setType(int newType) {
    type = newType;
    destroyedStructureTile = DestroyedStructure_None;

    if (type == Terrain_Spice) {
        spice = currentGame->randomGen.rand(RANDOMSPICEMIN, RANDOMSPICEMAX);
    } else if (type == Terrain_ThickSpice) {
        spice = currentGame->randomGen.rand(RANDOMTHICKSPICEMIN, RANDOMTHICKSPICEMAX);
    } else if (type == Terrain_Dunes) {
    } else {
        spice = 0;
        if (isRock()) {
            sandRegion = NONE;
            if (hasAnUndergroundUnit())	{
                ObjectBase* current;
                std::list<Uint32>::const_iterator iter;
                iter = assignedUndergroundUnitList.begin();

                do {
                    current = currentGame->getObjectManager().getObject(*iter);
                    ++iter;

                    if(current == NULL)
                        continue;

                    unassignUndergroundUnit(current->getObjectID());
                    current->destroy();
                } while(iter != assignedUndergroundUnitList.end());
            }

            if(type == Terrain_Mountain) {
                if(hasANonInfantryGroundObject()) {
                    ObjectBase* current;
                    std::list<Uint32>::const_iterator iter;
                    iter = assignedNonInfantryGroundObjectList.begin();

                    do {
                        current = currentGame->getObjectManager().getObject(*iter);
                        ++iter;

                        if(current == NULL)
                            continue;

                        unassignNonInfantryGroundObject(current->getObjectID());
                        current->destroy();
                    } while(iter != assignedNonInfantryGroundObjectList.end());
                }
            }
        }
    }

    for (int i=location.x; i <= location.x+3; i++) {
        for (int j=location.y; j <= location.y+3; j++) {
            if (currentGameMap->tileExists(i, j)) {
                currentGameMap->getTile(i, j)->clearTerrain();
            }
        }
    }
}
Exemple #3
0
int TerrainTile::encode() const
{
  int res = 0;
  if (isTree())
  {
    res += 0x1;
    res += 0x10;
  }
  if (isRock())     { res +=  0x2; }
  if (isWater())    { res +=  0x4; }
  if (isBuilding()) { res +=  0x8; }
  if (isRoad())     { res += 0x40; }

  return res;
}
Exemple #4
0
void generateRandMove(dungeon_t* dungeonPtr, monster* monsterPtr, int* dstX, int* dstY) {
    direction_t movementDir;
    int tunneling = monsterPtr->abilities & MONSTER_TUNNELING;
    int targetX, targetY;
    do {
        movementDir = utilRandDir();
        targetX = monsterPtr->x;
        targetY = monsterPtr->y;
        if (movementDir & north) {
            targetY--;
        } else if (movementDir & south) {
            targetY++;
        }
        if (movementDir & west) {
            targetX--;
        } else if (movementDir & east) {
            targetX++;
        }
    } while (tunneling ? isImmutable(dungeonPtr->grid, targetX, targetY) : isRock(dungeonPtr->grid, targetX, targetY));
    *dstX = targetX;
    *dstY = targetY;
}