char GameMapRandomizer::GetPoint(const Position &pos) {
  Position section_pos(0, 0);
  Position tile_pos(pos);
  manager_->TranslatePosition(&section_pos, &tile_pos);

  GameMapSection *section =
    manager_->GetSectionFromPosition(section_pos);

  if (section == NULL) {
    return 0;
  }
  
  return section->terrain()[tile_pos.x() + tile_pos.y() * section_width_];
}
void GameMapRandomizer::DrawPoint(const Position &pos, char type) {
  Position section_pos(0, 0);
  Position tile_pos(pos);
  manager_->TranslatePosition(&section_pos, &tile_pos);

  GameMapSection *section =
    manager_->GetSectionFromPosition(section_pos);

  if (section == NULL) {
    return;
  }
  
  section->SetTerrain(tile_pos, type);
}
Exemple #3
0
Fichier : ai.cpp Projet : ejrh/hex
void Ai::update_unit_stack(UnitStack& stack) {
    UnitStack::pointer enemy = get_nearest_enemy(stack);
    Point tile_pos(stack.position);
    if (enemy) {
        BOOST_LOG_TRIVIAL(info) << "Saw enemy: " << enemy->id;
        tile_pos = enemy->position;
    } else {
        tile_pos.x += (rand() % 5) - (rand() % 5);
        tile_pos.y += (rand() % 5) - (rand() % 5);
    }

    MovementModel movement_model(&game);
    Pathfinder pathfinder(&game.level, &movement_model);
    pathfinder.start(stack, stack.position, tile_pos);
    pathfinder.complete();
    Path new_path;
    pathfinder.build_path(new_path);

    if (new_path.size() > 10)
        new_path.resize(10);

    if (new_path.empty())
        return;

    UnitStack::pointer target_stack = game.level.tiles[new_path.back()].stack;
    if (target_stack) {
        return;
    }

    IntSet selected_units;
    for (unsigned int i = 0; i < stack.units.size(); i++) {
        selected_units.insert(i);
    }

    dispatcher->receive(create_message(UnitMove, stack.id, selected_units, new_path, 0));
}