Example #1
0
EditableMap::EditableMap(Resources& resources, Subsystem& subsystem,
    const std::string& filename) throw (Exception)
    : Map(subsystem, filename), resources(resources), subsystem(subsystem)
{
    char buffer[256];

    set_background(get_background());
    set_tileset(get_tileset());
    untouch();

    /* grab objects */
    int num_objects = atoi(get_value("objects").c_str());
    for (int i = 0; i < num_objects; i++) {
        sprintf(buffer, "object_name%d", i);
        const std::string& object_name = get_value(buffer);
        sprintf(buffer, "object_x%d", i);
        int x = atoi(get_value(buffer).c_str());
        sprintf(buffer, "object_y%d", i);
        int y = atoi(get_value(buffer).c_str());
        try {
            Object *obj = resources.get_object(object_name);
            EditableObject *eobj = new EditableObject(obj, x, y);
            objects.push_back(eobj);
        } catch (const Exception& e) {
            subsystem << "WARNING: " << e.what() << std::endl;
        }
    }

    /* grab light sources */
    int num_lights = atoi(get_value("lights").c_str());
    for (int i = 0; i < num_lights; i++) {
        sprintf(buffer, "light_x%d", i);
        int x = atoi(get_value(buffer).c_str());
        sprintf(buffer, "light_y%d", i);
        int y = atoi(get_value(buffer).c_str());
        sprintf(buffer, "light_radius%d", i);
        int radius = atoi(get_value(buffer).c_str());
        lights.push_back(new EditableLight(x, y, radius));
    }

    create_lightmap();
}
Example #2
0
Tournament::Tournament(Resources& resources, Subsystem& subsystem, Gui *gui, ServerLogger *logger,
    const std::string& game_file, bool server, const std::string& map_name,
    Players& players, int duration, bool warmup)
    throw (TournamentException, ResourcesException)
      : resources(resources), subsystem(subsystem),
      properties(*resources.get_game_settings(game_file)),
      gui(gui), server(server),
      map(*resources.get_map(map_name)),
      tileset(resources.get_tileset(map.get_tileset())),
      map_array(map.get_map()), decoration_array(map.get_decoration()),
      lightmap(0), map_width(map.get_width()), map_height(map.get_height()),
      tile_width(tileset->get_tile_width()), tile_height(tileset->get_tile_height()),
      decoration_brightness(map.get_decoration_brightness()), players(players), following_id(0),
      background(resources.get_background(map.get_background())), top(0), left(0),
      spectator_x(map_width * tile_width / 2),
      spectator_y(map_height * tile_height / 2),
      spectator_accel_x(0), spectator_accel_y(0), parallax_shift(1), debug(false),
      game_state(duration), second_counter(0), ready(server),
      ping_time(0), animation_id(0), screen_shaker(0),
      player_afk(resources.get_animation("player_afk")), player_afk_counter(0),
      player_afk_index(0), player_configuration(0), show_statistics(false),
      screw1(resources.get_icon("screw1")), screw2(resources.get_icon("screw2")),
      screw3(resources.get_icon("screw1")), screw4(resources.get_icon("screw2")),
      last_button_a_state(false), warmup(warmup), tournament_icon(0),
      lives_full(resources.get_icon("lives")),
      lives_half(resources.get_icon("lives_half")),
      lives_empty(resources.get_icon("lives_empty")),
      shield_full(resources.get_icon("shield")),
      shield_half(resources.get_icon("shield_half")),
      shield_empty(resources.get_icon("shield_empty")),
      hud_ammo(resources.get_icon("ammo")),
      hud_grenades(resources.get_icon("grenade")),
      hud_bombs(resources.get_icon("bomb")),
      hud_frogs(resources.get_icon("frog")),
      enemy_indicator(resources.get_icon("enemy_indicator_neutral")),
      game_over(false), logger(logger), gui_is_destroyed(false),
      do_friendly_fire_alarm(true)
{
    /* init */
    char kvb[128];

    /* get parallax shift from map */
    int shift = map.get_parallax_shift();
    if (shift) {
        parallax_shift = shift;
    }

    /* create map objects */
    has_frogs = false;
    int objcount = atoi(map.get_value("objects").c_str());
    for (int i = 0; i < objcount; i++) {
        sprintf(kvb, "object_name%d", i);
        const std::string& objname = map.get_value(kvb);
        if (objname.length()) {
            Object *obj = resources.get_object(objname);
            GameObject *gobj = new GameObject;
            gobj->picked = !server;
            gobj->object = obj;
            gobj->state.id = static_cast<identifier_t>(i);
            sprintf(kvb, "object_x%d", i);
            gobj->state.x = atoi(map.get_value(kvb).c_str()) * tile_width;
            sprintf(kvb, "object_y%d", i);
            gobj->state.y = atoi(map.get_value(kvb).c_str()) * tile_height;
            gobj->state.accel_x = 0.0f;
            gobj->state.accel_y = 0.0f;
            gobj->origin_x = static_cast<int>(gobj->state.x);
            gobj->origin_y = static_cast<int>(gobj->state.y);
            game_objects.push_back(gobj);
            if (gobj->object->get_type() == Object::ObjectTypeSpawnPointFrog) {
                has_frogs = true;
                frog_spawn_points.push_back(gobj);
            }
        }
    }

    /* create lightmap */
    if (!server) {
        map.create_lightmap();
        lightmap = map.get_lightmap();
    }

    /* check if frog's spawn points are placed in map */
    if (has_frogs) {
        frog_spawn_init = map.get_frog_spawn_init();
        if (!frog_spawn_init) {
            frog_spawn_init = atoi(properties.get_value("frog_spawn_init").c_str());
        }
        if (frog_spawn_init < 1) {
            frog_spawn_init = 1200;
        }
        reset_frog_spawn_counter();
    }

    /* setup logger */
    if (logger) {
        logger->set_map(&map);
    }
}