/* ----------------------------------------------------------------------------
 * Loads parameters from a data file.
 */
void converter_type::load_parameters(data_node* file) {
    reader_setter rs(file);
    
    string pikmin_types_str;
    string type_animation_suffixes_str;
    
    rs.set("available_pikmin_types", pikmin_types_str);
    rs.set("type_animation_suffixes", type_animation_suffixes_str);
    rs.set("type_change_interval", type_change_interval);
    rs.set("total_input_pikmin", total_input_pikmin);
    rs.set("pikmin_per_conversion", pikmin_per_conversion);
    rs.set("same_type_counts_for_output", same_type_counts_for_output);
    rs.set("buffer_size", buffer_size);
    rs.set("auto_conversion_timeout", auto_conversion_timeout);
    
    mob_category* pik_cat = mob_categories.get(MOB_CATEGORY_PIKMIN);
    vector<string> pikmin_types_strs =
        semicolon_list_to_vector(pikmin_types_str);
        
    for(size_t t = 0; t < pikmin_types_strs.size(); ++t) {
        mob_type* type_ptr = pik_cat->get_type(pikmin_types_strs[t]);
        
        if(type_ptr) {
            available_pikmin_types.push_back((pikmin_type*) type_ptr);
        } else {
            log_error(
                "Unknown Pikmin type \"" + pikmin_types_strs[t] + "\"!",
                file
            );
        }
    }
    
    animation_group_suffixes =
        semicolon_list_to_vector(type_animation_suffixes_str);
        
    if(available_pikmin_types.size() == 1 && animation_group_suffixes.empty()) {
        //Let's make life easier. This is a one-type converter,
        //so no need to involve suffixes.
        animation_group_suffixes.push_back("");
    }
    
    if(available_pikmin_types.empty()) {
        log_error(
            "A converter needs to have at least one available Pikmin type!",
            file
        );
    }
    
    if(animation_group_suffixes.size() != available_pikmin_types.size()) {
        log_error(
            "The number of animation type suffixes needs to match the "
            "number of available Pikmin types!", file
        );
    }
}
示例#2
0
interval::interval(const string &s) {
    vector<string> subinterval_strs = semicolon_list_to_vector(s);
    size_t n_subintervals = subinterval_strs.size();
    
    for(size_t si = 0; si < n_subintervals; ++si) {
        float lower = FLT_MIN;
        float upper = FLT_MAX;
        float divisor = 0;
        
        if(!subinterval_strs[si].empty()) {
            vector<string> divisor_parts =
                split(subinterval_strs[si], "every", false, true);
            if(divisor_parts.size() >= 2) {
                divisor = s2f(divisor_parts.back());
            }
            
            if(divisor_parts[0] != "every") {
                vector<string> range_parts =
                    split(divisor_parts[0], "to", false, true);
                if(range_parts.size() == 1 && range_parts[0] != "to") {
                    //No "to".
                    lower = upper = s2f(range_parts[0]);
                } else {
                    if(range_parts.size() >= 2) {
                        if(trim_spaces(range_parts[0]) != "any") {
                            lower = s2f(range_parts[0]);
                        }
                    }
                    if(range_parts.size() >= 3) {
                        if(trim_spaces(range_parts[2]) != "any") {
                            upper = s2f(range_parts[2]);
                        }
                    }
                }
            }
        }
        
        subintervals.push_back(subinterval(lower, upper, divisor));
    }
}
示例#3
0
/* ----------------------------------------------------------------------------
 * Loads data about the Pikmin type from a data file.
 */
void pikmin_type::load_from_file(
    data_node* file, const bool load_resources,
    vector<pair<size_t, string> >* anim_conversions
) {
    attack_power = s2f(file->get_child_by_name("attack_power")->value);
    attack_interval =
        s2f(
            file->get_child_by_name(
                "attack_interval"
            )->get_value_or_default("0.8")
        );
    throw_height_mult =
        s2f(
            file->get_child_by_name(
                "throw_height_mult"
            )->get_value_or_default("1")
        );
    can_carry_bomb_rocks =
        s2b(
            file->get_child_by_name("can_carry_bomb_rocks")->value
        );
    can_dig = s2b(file->get_child_by_name("can_dig")->value);
    can_latch = s2b(file->get_child_by_name("can_latch")->value);
    can_swim = s2b(file->get_child_by_name("can_swim")->value);
    carry_speed = s2f(file->get_child_by_name("carry_speed")->value);
    carry_strength = s2f(file->get_child_by_name("carry_strength")->value);
    has_onion = s2b(file->get_child_by_name("has_onion")->value);
    
    data_node* hazards_node = file->get_child_by_name("resistances");
    vector<string> hazards_strs = semicolon_list_to_vector(hazards_node->value);
    for(size_t h = 0; h < hazards_strs.size(); ++h) {
        string hazard_name = hazards_strs[h];
        if(hazards.find(hazard_name) == hazards.end()) {
            log_error("Unknown hazard \"" + hazard_name + "\"!", hazards_node);
        } else {
            resistances.push_back(&(hazards[hazard_name]));
        }
    }
    
    if(load_resources) {
        bmp_top[0] =
            bitmaps.get(file->get_child_by_name("top_leaf")->value, file);
        bmp_top[1] =
            bitmaps.get(file->get_child_by_name("top_bud")->value, file);
        bmp_top[2] =
            bitmaps.get(file->get_child_by_name("top_flower")->value, file);
        bmp_icon =
            bitmaps.get(file->get_child_by_name("icon")->value, file);
        bmp_maturity_icon[0] =
            bitmaps.get(file->get_child_by_name("icon_leaf")->value, file);
        bmp_maturity_icon[1] =
            bitmaps.get(file->get_child_by_name("icon_bud")->value, file);
        bmp_maturity_icon[2] =
            bitmaps.get(file->get_child_by_name("icon_flower")->value, file);
    }
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_IDLING,    "idling"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_WALKING,   "walking"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_THROWN,    "thrown"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_ATTACKING, "attacking"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_GRABBING,  "grabbing"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_SIGHING,   "sighing"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_CARRYING,  "carrying"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_BURIED,    "buried"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_PLUCKING,  "plucking"));
    anim_conversions->push_back(make_pair(PIKMIN_ANIM_LYING,     "lying"));
    
    pikmin_in_onions[this] =
        s2i(file->get_child_by_name("onion_starting_number")->value);
}