Exemplo n.º 1
0
void pge_init() {
  // Allocate
  for(int z = 0; z < GRID_DEPTH; z++) {
    for(int y = 0; y < GRID_HEIGHT; y++) {
      for(int x = 0; x < GRID_WIDTH; x++) {
        s_block_array[vec2i(Vec3(x, y, z))] = block_create(Vec3(x * BLOCK_SIZE, y * BLOCK_SIZE, z * BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), COLOR_INVISIBLE);
      }
    }
  }
  for(int i = 0; i < MAX_CLOUDS; i++) {
    s_cloud_array[i] = cloud_create(Vec3(0, 0, SKY_HEIGHT), GSize(BLOCK_SIZE, BLOCK_SIZE), Vec3(GRID_WIDTH * BLOCK_SIZE, GRID_HEIGHT * BLOCK_SIZE, SKY_HEIGHT));
  }

  // Set up world
  generate_world();

  // Set up engine
  pge_isometric_set_projection_offset(PBL_IF_ROUND_ELSE(GPoint(90, 110), GPoint(72, 80)));
  pge_isometric_set_enabled(true);
  pge_set_framerate(FRAME_RATE_IDLE);
  pge_begin(GColorBlack, logic, render, click);
  s_main_window = pge_get_window();

  s_status_layer = text_layer_create(grect_inset(
    layer_get_bounds((window_get_root_layer(s_main_window))),
    PBL_IF_ROUND_ELSE(GEdgeInsets(30, 0, 130, 0), GEdgeInsets(0, 0, 150, 0))));
  text_layer_set_background_color(s_status_layer, GColorBlack);
  text_layer_set_text_color(s_status_layer, GColorWhite);
  text_layer_set_text_alignment(s_status_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft));
  layer_add_child(window_get_root_layer(s_main_window), text_layer_get_layer(s_status_layer));
  update_status_text();

#ifdef BENCHMARK
  APP_LOG(APP_LOG_LEVEL_INFO, "Heap free: %dB after creating %d blocks (Size: %dB)", (int)heap_bytes_free(), (GRID_WIDTH * GRID_HEIGHT * GRID_DEPTH), get_world_size());
#endif
}
Exemplo n.º 2
0
bool Game::start_new_game()
{
  date = Date(1400, 5, 1);

  if (!world_ready) {

    if (file_exists(SAVE_DIR + "world.sav")) {
      if (!query_yn("Load world from save file?")) {
        return false;
      }
      world->load_from_file(SAVE_DIR + "world.sav");

    } else {
      if (!query_yn("We need to generate a world first, is that okay?") ||
          !generate_world()) {
        return false;
      }
      world->save_to_file("world.sav");
      save_kingdoms();
    }

  }

// Pick our race first, so we know where to start placement.
  city->pick_race();

// Let the city pick a location in the world
// Start from the center of the appropriate kingdom.
  Point start;
  Kingdom* city_kingdom = get_kingdom_for_race(city->get_race());
  if (city_kingdom) {
    start.x = (city_kingdom->most_west  + city_kingdom->most_east ) / 2;
    start.y = (city_kingdom->most_north + city_kingdom->most_south) / 2;
  } else {
    debugmsg("Kingdom not found for %s.  %d kingdoms.",
             Race_data[city->get_race()]->name.c_str(), kingdoms.size());
    start = Point(WORLD_MAP_SIZE / 2, WORLD_MAP_SIZE / 2);
  }

  city->set_starting_tiles_seen();

  Point p = world->draw(start, &(city->world_seen));

  if (p.x == -1) {  // We canceled
    return false;
  }

// Put our city there.
  bool placed = false;
  while (!placed) {
    if (!city->world_seen.is_seen(p)) {
      popup("That's unexplored territory!");
    } else if (!world->get_city(p)) {
      city->generate_map(p);
      placed = city->place_keep();
    } else {
      popup("There is already a city there!");
    }
    if (!placed) {
      p = world->draw(p, &(city->world_seen)); // Try again
      if (p.x == -1) {  // We canceled
        return false;
      }
    }
  }

  city->location = p;
// Let us see a little more.
  city->mark_nearby_tiles_seen(4);
  world->set_city(p, city);
// Crude race picker; TODO: replace this.
  city->set_name();
  city->start_new_city();
  city->setup_trade_routes();
  city->set_starting_tiles_seen();

  return true;
}