示例#1
0
 void processCat(std::string& lop, std::string& rop)
 {
   std::string *lopv, *ropv;
   lopv = getIdent(lop);
   ropv = getIdent(rop);
   std::ostringstream os;
   os << *lopv << *ropv;
   lopv->assign(os.str());
   eraseCommand();
 }
示例#2
0
 void processAppend(std::string& lop, std::string& rop)
 {
   std::string *plop, *prop;
   FILE* f;
   plop = getIdent(lop);
   prop = getIdent(rop);
   f = fopen(prop->c_str(), "a");
   BNB_ASSERT(f);
   fprintf(f, "%s", plop->c_str());
   fclose(f);
   eraseCommand();
 }
示例#3
0
 void processInc(std::string& lop, std::string& rop)
 {
   std::string *lopv, *ropv;
   int ilop, irop;
   lopv = getIdent(lop);
   ropv = getIdent(rop);
   ilop = atoi(lopv->c_str());
   irop = atoi(ropv->c_str());
   std::ostringstream os;
   os << ilop + irop;
   lopv->assign(os.str());
   eraseCommand();
 }
示例#4
0
 void processEcho(std::vector< std::string> & args)
 {
   for(int i = 1; i < args.size(); i ++)
     printf("%s ", getIdent(args[i])->c_str());
   printf("\n");
   eraseCommand();
 }
示例#5
0
文件: mangle.c 项目: HatsuneMiku/dmd
const char *TemplateInstance::mangle(bool isv)
{
    OutBuffer buf;

#if 0
    printf("TemplateInstance::mangle() %p %s", this, toChars());
    if (parent)
        printf("  parent = %s %s", parent->kind(), parent->toChars());
    printf("\n");
#endif
    getIdent();
    const char *id = ident ? ident->toChars() : toChars();
    if (!tempdecl)
        error("is not defined");
    else
    {
        Dsymbol *par = enclosing || isTemplateMixin() ? parent : tempdecl->parent;
        if (par)
        {
            const char *p = par->mangle();
            if (p[0] == '_' && p[1] == 'D')
                p += 2;
            buf.writestring(p);
        }
    }
    buf.printf("%llu%s", (ulonglong)strlen(id), id);
    id = buf.toChars();
    buf.data = NULL;
    //printf("TemplateInstance::mangle() %s = %s\n", toChars(), id);
    return id;
}
示例#6
0
 void processWait(std::string& lop, std::string& sign, std::string &rop)
 {
   std::string *lopv, *ropv;
   int ilop, irop;
   lopv = getIdent(lop);
   ropv = getIdent(rop);
   ilop = atoi(lopv->c_str());
   irop = atoi(ropv->c_str());
   if(sign == "<") {
     if(ilop < irop) {
       eraseCommand();
     } else {
       *mAction = BNBActions::SKIP;
     }
   } else {
     BNB_ERROR_REPORT("Unsupported comparison");
   }
 }
示例#7
0
 void processExec(std::string& evar) 
 {
   std::string cmd;
   std::vector< std::string > args;
   cmd = *getIdent(evar);
   eraseCommand();
   cmd.append(";");
   mCurCommand->mCode.insert(0, cmd);
   
 }
示例#8
0
StyleImage* CSSImageValue::cachedOrPendingImage()
{
    if (getIdent() == CSSValueNone)
        return 0;

    if (!m_image)
        m_image = StylePendingImage::create(this);

    return m_image.get();
}
示例#9
0
 void processMkdir(std::string& dir)
 {
   int rc;
   std::string* dname;      
   mode_t mod;
   dname = getIdent(dir);
   mod = 0777;
   rc = mkdir(dname->c_str(), mod);
   BNB_ASSERT(rc == 0);
   eraseCommand();
 }
示例#10
0
// ----------------------------------------------------------------------------
bool KartProperties::operator<(const KartProperties &other) const
{
    PlayerProfile *p = PlayerManager::getCurrentPlayer();
    bool this_is_locked = p->isLocked(getIdent());
    bool other_is_locked = p->isLocked(other.getIdent());
    if (this_is_locked == other_is_locked)
    {
        return getName() < other.getName();
    }
    else
        return other_is_locked;

    return true;
}  // operator<
示例#11
0
/* Cree un identificateur */
IdentP makeIdent(int line, char *id) {
  IdentP ident = getIdent(id);
  if (!ident) {
    ident = &idents[nbIdent++];
    ident->line = line;
    /* Si on a duplique la chaine dans la partie Flex, il n'y a pas de raison
     * de le faire a nouveau ici.
     * Comme ca risque de dependre de ce que les uns et les autres font dans
     * tp.l, je prefere le (re-)faire ici ourb etre sur qu'elle ne soit pas ecrasee.
     */
    ident->id = strdup(id);
  }
  return(ident);
}
示例#12
0
 void processLoad(std::string& lop, std::string& rop)
 {
   std::string *plop, *prop;
   FILE* f;
   plop = getIdent(lop);
   prop = getIdent(rop);
   plop->clear();
   f = fopen(prop->c_str(), "r");
   BNB_ASSERT(f);
   while(true) {
     int rc;
     unsigned char c;
     rc = fgetc(f);
     if(rc == EOF)
       break;
     else {
       c = (unsigned char) rc;
       *plop += c;
     }
   }
   fclose(f);
   eraseCommand();
 }
示例#13
0
 std::string* getIdent(std::string& ident)
 {
   BNB_ASSERT(ident.size());
   if(ident[0] == '$') {
     std::string nident, *var;
     nident.assign(ident, 1, ident.size() - 1);
     var = getIdent(nident);
     return getMem(var);
   } else if(ident[0] == '@') {
     std::string nident;
     nident.assign(ident, 1, ident.size() - 1);
     return getSpecVar(&nident);
   } else 
     return &ident;
 }
示例#14
0
Highscores* World::getHighscores() const
{
    if(!m_use_highscores) return NULL;

    const Highscores::HighscoreType type = "HST_" + getIdent();

    Highscores * highscores =
        highscore_manager->getHighscores(type,
                                         getNumKarts(),
                                         race_manager->getDifficulty(),
                                         race_manager->getTrackName(),
                                         race_manager->getNumLaps(),
                                         race_manager->getReverseTrack());

    return highscores;
}   // getHighscores
示例#15
0
/** Called at the end of a race. Updates highscores, pauses the game, and
 *  informs the unlock manager about the finished race. This function must
 *  be called after all other stats were updated from the different game
 *  modes.
 */
void World::terminateRace()
{
    m_schedule_pause = false;
    m_schedule_unpause = false;

    // Update the estimated finishing time for all karts that haven't
    // finished yet.
    const unsigned int kart_amount = getNumKarts();
    for(unsigned int i = 0; i < kart_amount ; i++)
    {
        if(!m_karts[i]->hasFinishedRace() && !m_karts[i]->isEliminated())
        {
            m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i]));

        }
    }   // i<kart_amount

    // Update highscores, and retrieve the best highscore if relevant
    // to show it in the GUI
    int best_highscore_rank = -1;
    int best_finish_time = -1;
    std::string highscore_who = "";
    StateManager::ActivePlayer* best_player = NULL;
    if (!this->isNetworkWorld())
    {
        updateHighscores(&best_highscore_rank, &best_finish_time, &highscore_who,
                     &best_player);
    }

    // Check achievements
    PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_COLUMBUS,
                                       getTrack()->getIdent(), 1);
    if (raceHasLaps())
    {
        PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_MARATHONER,
                                           "laps", race_manager->getNumLaps());
    }

    Achievement *achiev = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER);
    if (achiev)
    {
        std::string mode_name = getIdent(); // Get the race mode name
        int winner_position = 1;
        unsigned int opponents = achiev->getInfo()->getGoalValue("opponents"); // Get the required opponents number
        if (mode_name == IDENT_FTL)
        {
            winner_position = 2;
            opponents++;
        }
        for(unsigned int i = 0; i < kart_amount; i++)
        {
            // Retrieve the current player
            StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
            if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer())
            {
                // Check if the player has won
                if (m_karts[i]->getPosition() == winner_position && kart_amount > opponents )
                {
                    // Update the achievement
                    mode_name = StringUtils::toLowerCase(mode_name);
                    if (achiev->getValue("opponents") <= 0)
                        PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER,
                                                            "opponents", opponents);
                    PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER,
                                                        mode_name, 1);
                }
            }
        } // for i < kart_amount
    } // if (achiev)

    Achievement *win = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_UNSTOPPABLE);
    //if achivement has been unlocked
    if (win->getValue("wins") < 5 )
    {
        for(unsigned int i = 0; i < kart_amount; i++)
        {
            // Retrieve the current player
            StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
            if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer())
            {
                // Check if the player has won
                if (m_karts[i]->getPosition() == 1 )
                {
                    // Increase number of consecutive wins
                       PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_UNSTOPPABLE,
                                                            "wins", 1);
                }
                else
                {
                      //Set number of consecutive wins to 0
                      win->reset();
                }
            }
         }
    }
    PlayerManager::getCurrentPlayer()->raceFinished();

    if (m_race_gui) m_race_gui->clearAllMessages();
    // we can't delete the race gui here, since it is needed in case of
    // a restart: the constructor of it creates some textures which assume
    // that no scene nodes exist. In case of a restart there are scene nodes,
    // so we can't create the race gui again, so we keep it around
    // and save the pointer.
    assert(m_saved_race_gui==NULL);
    m_saved_race_gui = m_race_gui;

    RaceResultGUI* results = RaceResultGUI::getInstance();
    m_race_gui       = results;

    if (best_highscore_rank > 0)
    {
        results->setHighscore(highscore_who, best_player, best_highscore_rank,
                              best_finish_time);
    }
    else
    {
        results->clearHighscores();
    }

    results->push();
    WorldStatus::terminateRace();
}   // terminateRace
/** Actually reads in the data from the xml file.
 *  \param root Root of the xml tree.
 */
void KartProperties::getAllData(const XMLNode * root)
{
    root->get("version", &m_version);
    
    root->get("name",              &m_name             );
    
    root->get("icon-file",         &m_icon_file        );
    
    root->get("minimap-icon-file", &m_minimap_icon_file);

    root->get("shadow-file",       &m_shadow_file      );
    Vec3 c;
    root->get("rgb",               &c                  );
    m_color.set(255, (int)(255*c.getX()), (int)(255*c.getY()), (int)(255*c.getZ()));

    root->get("groups",            &m_groups           );

    root->get("random-wheel-rot",  &m_has_rand_wheels  );

    root->get("shadow-scale",      &m_shadow_scale     );
    root->get("shadow-x-offset",   &m_shadow_x_offset  );
    root->get("shadow-y-offset",   &m_shadow_y_offset  );

    if(const XMLNode *dimensions_node = root->getNode("center"))
        dimensions_node->get("gravity-shift", &m_gravity_center_shift);

    if(const XMLNode *nitro_node = root->getNode("nitro"))
    {
        nitro_node->get("consumption",        &m_nitro_consumption       );
        nitro_node->get("small-container",    &m_nitro_small_container   );
        nitro_node->get("big-container",      &m_nitro_big_container     );
        nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase);
        nitro_node->get("engine-force",       &m_nitro_engine_force      );
        nitro_node->get("duration",           &m_nitro_duration          );
        nitro_node->get("fade-out-time",      &m_nitro_fade_out_time     );
        nitro_node->get("max",                &m_nitro_max               );
    }

    if(const XMLNode *rescue_node = root->getNode("rescue"))
    {
        rescue_node->get("vert-offset", &m_rescue_vert_offset);
        rescue_node->get("time",        &m_rescue_time       );
        rescue_node->get("height",      &m_rescue_height     );
    }

    if(const XMLNode *explosion_node = root->getNode("explosion"))
    {
        explosion_node->get("time",   &m_explosion_time  );
        explosion_node->get("radius", &m_explosion_radius);
        explosion_node->get("invulnerability-time", 
                        &m_explosion_invulnerability_time);
    }

    if(const XMLNode *skid_node = root->getNode("skid"))
    {
        m_skidding_properties->load(skid_node);
    }

    if(const XMLNode *ai_node = root->getNode("ai"))
    {
        const XMLNode *easy = ai_node->getNode("easy");
        m_ai_properties[RaceManager::DIFFICULTY_EASY]->load(easy);
        const XMLNode *medium = ai_node->getNode("medium");
        m_ai_properties[RaceManager::DIFFICULTY_MEDIUM]->load(medium);
        const XMLNode *hard = ai_node->getNode("hard");
        m_ai_properties[RaceManager::DIFFICULTY_HARD]->load(hard);
    }

    if(const XMLNode *slipstream_node = root->getNode("slipstream"))
    {
        slipstream_node->get("length",       &m_slipstream_length            );
        slipstream_node->get("width",        &m_slipstream_width             );
        slipstream_node->get("collect-time", &m_slipstream_collect_time      );
        slipstream_node->get("use-time",     &m_slipstream_use_time          );
        slipstream_node->get("add-power",    &m_slipstream_add_power         );
        slipstream_node->get("min-speed",    &m_slipstream_min_speed         );
        slipstream_node->get("max-speed-increase", 
                                             &m_slipstream_max_speed_increase);
        slipstream_node->get("duration",     &m_slipstream_duration          );
        slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time     );
    }

    if(const XMLNode *turn_node = root->getNode("turn"))
    {
        turn_node->get("time-full-steer",      &m_time_full_steer     );
        turn_node->get("turn-radius",          &m_turn_angle_at_speed );
        // For now store the turn radius in turn angle, the correct
        // value can only be determined later in ::load
    }

    if(const XMLNode *engine_node = root->getNode("engine"))
    {
        engine_node->get("brake-factor", &m_brake_factor);
        engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio);
        std::vector<float> v;
        if( engine_node->get("power", &v))
        {
            if(v.size()!=3)
                printf("Incorrect engine-power specifications for kart '%s'\n",
                getIdent().c_str());
            else
            {
                m_engine_power[0] = v[0];
                m_engine_power[1] = v[1];
                m_engine_power[2] = v[2];
            }
        }   // if engine-power
        v.clear();
        if( engine_node->get("max-speed", &v))
        {
            if(v.size()!=3)
                printf("Incorrect max-speed specifications for kart '%s'\n",
                getIdent().c_str());
            else
            {
                m_max_speed[0] = v[0];
                m_max_speed[1] = v[1];
                m_max_speed[2] = v[2];
            }
        }   // if max-speed
    }   // if getNode("engine")

    if(const XMLNode *gear_node = root->getNode("gear"))
    {
        gear_node->get("switch-ratio",   &m_gear_switch_ratio  );
        gear_node->get("power-increase", &m_gear_power_increase);
    }

    if(const XMLNode *mass_node = root->getNode("mass"))
        mass_node->get("value", &m_mass);


    if(const XMLNode *suspension_node = root->getNode("suspension"))
    {
        suspension_node->get("stiffness",            &m_suspension_stiffness);
        suspension_node->get("rest",                 &m_suspension_rest     );
        suspension_node->get("travel-cm",            &m_suspension_travel_cm);
        suspension_node->get("exp-spring-response",  &m_exp_spring_response );
        suspension_node->get("max-force",            &m_max_suspension_force);
    }

    if(const XMLNode *wheels_node = root->getNode("wheels"))
    {
        wheels_node->get("damping-relaxation",  &m_wheel_damping_relaxation );
        wheels_node->get("damping-compression", &m_wheel_damping_compression);
        wheels_node->get("radius",              &m_wheel_radius             );
    }

    if(const XMLNode *friction_node = root->getNode("friction"))
        friction_node->get("slip", &m_friction_slip);

    if(const XMLNode *stability_node = root->getNode("stability"))
    {
        stability_node->get("roll-influence",          
                                                   &m_roll_influence         );
        stability_node->get("chassis-linear-damping",
                                                   &m_chassis_linear_damping );
        stability_node->get("chassis-angular-damping", 
                                                   &m_chassis_angular_damping);
        stability_node->get("downward-impulse-factor", 
                                                   &m_downward_impulse_factor);
        stability_node->get("track-connection-accel", 
                                                   &m_track_connection_accel );
    }

    if(const XMLNode *upright_node = root->getNode("upright"))
    {
        upright_node->get("tolerance", &m_upright_tolerance);
        upright_node->get("max-force", &m_upright_max_force);
    }

    if(const XMLNode *collision_node = root->getNode("collision"))
    {
        collision_node->get("impulse",         &m_collision_impulse        );
        collision_node->get("impulse-time",    &m_collision_impulse_time   );
        collision_node->get("terrain-impulse", &m_collision_terrain_impulse);
        collision_node->get("restitution",     &m_restitution              );
        collision_node->get("bevel-factor",    &m_bevel_factor             );
    }

    //TODO: wheel front right and wheel front left is not loaded, yet is 
    //TODO: listed as an attribute in the xml file after wheel-radius
    //TODO: same goes for their rear equivalents

    if(const XMLNode *plunger_node= root->getNode("plunger"))
    {
        plunger_node->get("band-max-length",    &m_rubber_band_max_length    );
        plunger_node->get("band-force",         &m_rubber_band_force         );
        plunger_node->get("band-duration",      &m_rubber_band_duration      );
        plunger_node->get("band-speed-increase",&m_rubber_band_speed_increase);
        plunger_node->get("band-fade-out-time", &m_rubber_band_fade_out_time );
        std::vector<float> v;
        plunger_node->get("in-face-time",    &v);
        if(v.size()!=3)
        {
            fprintf(stderr, "[KartProperties] ERROR: Invalid plunger in-face-time specification.");
        }
        else
        {
            m_plunger_in_face_duration[0] = v[0];
            m_plunger_in_face_duration[1] = v[1];
            m_plunger_in_face_duration[2] = v[2];
        }
    }

    if(const XMLNode *zipper_node= root->getNode("zipper"))
    {
        zipper_node->get("time",               &m_zipper_time              );
        zipper_node->get("fade-out-time",      &m_zipper_fade_out_time     );
        zipper_node->get("force",              &m_zipper_force             );
        zipper_node->get("speed-gain",         &m_zipper_speed_gain        );
        zipper_node->get("max-speed-increase", &m_zipper_max_speed_increase);
    }

    if(const XMLNode *swatter_node= root->getNode("swatter"))
    {
        swatter_node->get("duration",        &m_swatter_duration      );
        swatter_node->get("squash-duration", &m_squash_duration       );
        swatter_node->get("squash-slowdown", &m_squash_slowdown       );
        if(swatter_node->get("distance",     &m_swatter_distance2) )
        {
            // Avoid squaring if distance is not defined, so that
            // distance2 remains UNDEFINED (which is a negative value)
            m_swatter_distance2 *= m_swatter_distance2;
        }
    }

    if(const XMLNode *camera_node= root->getNode("camera"))
    {
        camera_node->get("distance", &m_camera_distance);
        camera_node->get("forward-up-angle", &m_camera_forward_up_angle);
        m_camera_forward_up_angle *= DEGREE_TO_RAD;
        camera_node->get("backward-up-angle", &m_camera_backward_up_angle);
        m_camera_backward_up_angle *= DEGREE_TO_RAD;
    }

    if(const XMLNode *startup_node= root->getNode("startup"))
    {
        startup_node->get("time", &m_startup_times);
        startup_node->get("boost", &m_startup_boost);
    }

    if(const XMLNode *sounds_node= root->getNode("sounds"))
    {
        std::string s;
        sounds_node->get("engine", &s);
        if      (s == "large") m_engine_sfx_type = "engine_large";
        else if (s == "small") m_engine_sfx_type = "engine_small";
        else
        {
            std::cerr << "[KartProperties::getAllData()] WARNING : Kart " << m_name.c_str()
                      << " has invalid engine : " << s << "\n";
            m_engine_sfx_type = "engine_small";
        }

#ifdef WILL_BE_ENABLED_ONCE_DONE_PROPERLY
        // Load custom kart SFX files (TODO: enable back when it's implemented properly)
        for (int i = 0; i < SFXManager::NUM_CUSTOMS; i++)
        {
            std::string tempFile;
            // Get filename associated with each custom sfx tag in sfx config
            if (sounds_node->get(sfx_manager->getCustomTagName(i), tempFile))
            {
                // determine absolute filename
                // FIXME: will not work with add-on packs (is data dir the same)?
                tempFile = file_manager->getKartFile(tempFile, getIdent());

                // Create sfx in sfx manager and store id
                m_custom_sfx_id[i] = sfx_manager->addSingleSfx(tempFile, 1, 0.2f,1.0f);
            }
            else
            {
                // if there is no filename associated with a given tag
                m_custom_sfx_id[i] = -1;
            }   // if custom sound
        }   // for i<SFXManager::NUM_CUSTOMS
#endif
    }   // if sounds-node exist

    if(m_kart_model)
        m_kart_model->loadInfo(*root);
}   // getAllData
示例#17
0
/** Actually reads in the data from the xml file.
 *  \param root Root of the xml tree.
 */
void KartProperties::getAllData(const XMLNode * root)
{
    root->get("version",           &m_version);

    root->get("name",              &m_name             );

    root->get("icon-file",         &m_icon_file        );

    root->get("minimap-icon-file", &m_minimap_icon_file);

    root->get("shadow-file",       &m_shadow_file      );
    Vec3 c;
    root->get("rgb",               &c                  );
    m_color.set(255, (int)(255*c.getX()), (int)(255*c.getY()), (int)(255*c.getZ()));

    root->get("groups",            &m_groups           );
    root->get("type",              &m_kart_type        );

    if(const XMLNode *dimensions_node = root->getNode("center"))
        dimensions_node->get("gravity-shift", &m_gravity_center_shift);

    if(const XMLNode *ai_node = root->getNode("ai"))
    {
        const XMLNode *easy = ai_node->getNode("easy");
        m_ai_properties[RaceManager::DIFFICULTY_EASY]->load(easy);
        const XMLNode *medium = ai_node->getNode("medium");
        m_ai_properties[RaceManager::DIFFICULTY_MEDIUM]->load(medium);
        const XMLNode *hard = ai_node->getNode("hard");
        m_ai_properties[RaceManager::DIFFICULTY_HARD]->load(hard);
        const XMLNode *best = ai_node->getNode("best");
        m_ai_properties[RaceManager::DIFFICULTY_BEST]->load(best);
    }

    if(const XMLNode *friction_node = root->getNode("friction"))
        friction_node->get("slip", &m_friction_slip);

    if(const XMLNode *collision_node = root->getNode("collision"))
    {
        collision_node->get("impulse",         &m_collision_impulse        );
        collision_node->get("impulse-time",    &m_collision_impulse_time   );
        collision_node->get("terrain-impulse", &m_collision_terrain_impulse);
        collision_node->get("restitution",     &m_restitution              );
        collision_node->get("bevel-factor",    &m_bevel_factor             );
        collision_node->get("physical-wheel-position",&m_physical_wheel_position);
        std::string s;
        collision_node->get("impulse-type",    &s                          );
        s = StringUtils::toLowerCase(s);
        if(s=="none")
            m_terrain_impulse_type = IMPULSE_NONE;
        else if(s=="normal")
            m_terrain_impulse_type = IMPULSE_NORMAL;
        else if(s=="driveline")
            m_terrain_impulse_type = IMPULSE_TO_DRIVELINE;
        else
        {
            Log::fatal("[KartProperties]",
                       "Missing or incorrect value for impulse-type: '%s'.",
                       s.c_str());
        }
    }

    //TODO: wheel front right and wheel front left is not loaded, yet is
    //TODO: listed as an attribute in the xml file after wheel-radius
    //TODO: same goes for their rear equivalents


    if(const XMLNode *sounds_node= root->getNode("sounds"))
    {
        std::string s;
        sounds_node->get("engine", &s);
        if      (s == "large") m_engine_sfx_type = "engine_large";
        else if (s == "small") m_engine_sfx_type = "engine_small";
        else
        {
            if (SFXManager::get()->soundExist(s))
            {
                m_engine_sfx_type = s;
            }
            else
            {
                Log::error("[KartProperties]",
                           "Kart '%s' has an invalid engine '%s'.",
                           m_name.c_str(), s.c_str());
                m_engine_sfx_type = "engine_small";
            }
        }

#ifdef WILL_BE_ENABLED_ONCE_DONE_PROPERLY
        // Load custom kart SFX files (TODO: enable back when it's implemented properly)
        for (int i = 0; i < SFXManager::NUM_CUSTOMS; i++)
        {
            std::string tempFile;
            // Get filename associated with each custom sfx tag in sfx config
            if (sounds_node->get(SFXManager::get()->getCustomTagName(i), tempFile))
            {
                // determine absolute filename
                // FIXME: will not work with add-on packs (is data dir the same)?
                tempFile = file_manager->getKartFile(tempFile, getIdent());

                // Create sfx in sfx manager and store id
                m_custom_sfx_id[i] = SFXManager::get()->addSingleSfx(tempFile, 1, 0.2f,1.0f);
            }
            else
            {
                // if there is no filename associated with a given tag
                m_custom_sfx_id[i] = -1;
            }   // if custom sound
        }   // for i<SFXManager::NUM_CUSTOMS
#endif
    }   // if sounds-node exist

    if(m_kart_model)
        m_kart_model->loadInfo(*root);
}   // getAllData
示例#18
0
/** Loads the kart properties from a file.
 *  \param filename Filename to load.
 *  \param node Name of the xml node to load the data from
 */
void KartProperties::load(const std::string &filename, const std::string &node)
{
    // Get the default values from STKConfig:
    *this = stk_config->getDefaultKartProperties();
    // m_kart_model must be initialised after assigning the default
    // values from stk_config (otherwise all kart_properties will
    // share the same KartModel
    m_kart_model  = new KartModel(/*is_master*/true);

    const XMLNode * root = 0;
    m_root  = StringUtils::getPath(filename);
    m_ident = StringUtils::getBasename(StringUtils::removeExtension(filename));
    m_ident = StringUtils::getBasename(StringUtils::getPath(filename));
    try
    {
        root = new XMLNode(filename);
        if(!root || root->getName()!="kart")
        {
            std::ostringstream msg;
            msg << "Couldn't load kart properties '" << filename <<
                "': no kart node.";
            
            delete m_kart_model;
            throw std::runtime_error(msg.str());
        }
        getAllData(root);
    }
    catch(std::exception& err)
    {
        fprintf(stderr, "Error while parsing KartProperties '%s':\n",
                filename.c_str());
        fprintf(stderr, "%s\n", err.what());
    }
    if(root) delete root;

    // Set a default group (that has to happen after init_default and load)
    if(m_groups.size()==0)
        m_groups.push_back(DEFAULT_GROUP_NAME);


    // Load material
    std::string materials_file = file_manager->getKartFile("materials.xml",getIdent());
    file_manager->pushModelSearchPath(file_manager->getKartFile("", getIdent()));
    file_manager->pushTextureSearchPath(file_manager->getKartFile("", getIdent()));

    // addShared makes sure that these textures/material infos stay in memory
    material_manager->addSharedMaterial(materials_file);
    // Make permanent is important, since otherwise icons can get deleted
    // (e.g. when freeing temp. materials from a track, the last icon
    //  would get deleted, too.
    m_icon_material = material_manager->getMaterial(m_icon_file,
                                                    /*is_full+path*/false, 
                             
                                                    /*make_permanent*/true);
    if(m_minimap_icon_file!="")
        m_minimap_icon = irr_driver->getTexture(m_minimap_icon_file);
    else
        m_minimap_icon = NULL;

    // Only load the model if the .kart file has the appropriate version,
    // otherwise warnings are printed.
    if (m_version >= 1)
    {
        const bool success = m_kart_model->loadModels(*this);
        if (!success)
        {
            delete m_kart_model;
            file_manager->popTextureSearchPath();
            file_manager->popModelSearchPath();
            throw std::runtime_error("Cannot load kart models");
        }
    }
    
    if(m_gravity_center_shift.getX()==UNDEFINED)
    {
        m_gravity_center_shift.setX(0);
        // Default: center at the very bottom of the kart.
        m_gravity_center_shift.setY(m_kart_model->getHeight()*0.5f);
        m_gravity_center_shift.setZ(0);
    }
    m_kart_model->setDefaultPhysicsPosition(m_gravity_center_shift,
                                           m_wheel_radius           );
    m_wheel_base = fabsf( m_kart_model->getWheelPhysicsPosition(0).getZ()
                         -m_kart_model->getWheelPhysicsPosition(2).getZ());
    m_angle_at_min = asinf(m_wheel_base/m_min_radius);
    m_angle_at_max = asinf(m_wheel_base/m_max_radius);
    if(m_max_speed_turn == m_min_speed_turn)
        m_speed_angle_increase = 0.0;
    else
        m_speed_angle_increase = (m_angle_at_min   - m_angle_at_max)
                               / (m_max_speed_turn - m_min_speed_turn);


    m_shadow_texture = irr_driver->getTexture(m_shadow_file);
    file_manager->popTextureSearchPath();
    file_manager->popModelSearchPath();

}   // load
示例#19
0
/** Actually reads in the data from the xml file.
 *  \param root Root of the xml tree.
 */
void KartProperties::getAllData(const XMLNode * root)
{
    root->get("version", &m_version);
    
    std::string temp_name;
    root->get("name",              &temp_name          );
    m_name = _(temp_name.c_str());
    
    root->get("icon-file",         &m_icon_file        );
    
    root->get("minimap-icon-file", &m_minimap_icon_file);

    root->get("shadow-file",       &m_shadow_file      );
    Vec3 c;
    root->get("rgb",               &c                  );
    m_color.set(255, (int)(255*c.getX()), (int)(255*c.getY()), (int)(255*c.getZ()));

    root->get("groups",            &m_groups           );

    if(const XMLNode *dimensions_node = root->getNode("center"))
        dimensions_node->get("gravity-shift", &m_gravity_center_shift);

    if(const XMLNode *nitro_node = root->getNode("nitro"))
    {
        nitro_node->get("power-boost",        &m_nitro_power_boost       );
        nitro_node->get("consumption",        &m_nitro_consumption       );
        nitro_node->get("small-container",    &m_nitro_small_container   );
        nitro_node->get("big-container",      &m_nitro_big_container     );
        nitro_node->get("max-speed-increase", &m_nitro_max_speed_increase);
        nitro_node->get("duration",           &m_nitro_duration          );
        nitro_node->get("fade-out-time",      &m_nitro_fade_out_time     );

    }

    if(const XMLNode *rescue_node = root->getNode("rescue"))
    {
        rescue_node->get("vert-offset", &m_rescue_vert_offset);
        rescue_node->get("time",        &m_rescue_time       );
        rescue_node->get("height",      &m_rescue_height     );
    }

    if(const XMLNode *explosion_node = root->getNode("explosion"))
    {
        explosion_node->get("time",   &m_explosion_time  );
        explosion_node->get("radius", &m_explosion_radius);
    }

    if(const XMLNode *ai_node = root->getNode("ai"))
    {
        ai_node->get("steering-variation",   &m_ai_steering_variation  );
    }
    if(const XMLNode *skid_node = root->getNode("skid"))
    {
        skid_node->get("increase",      &m_skid_increase     );
        skid_node->get("decrease",      &m_skid_decrease     );
        skid_node->get("max",           &m_skid_max          );
        skid_node->get("time-till-max", &m_time_till_max_skid);
        skid_node->get("visual",        &m_skid_visual       );
        skid_node->get("enable",        &m_has_skidmarks     );
    }

    if(const XMLNode *slipstream_node = root->getNode("slipstream"))
    {
        slipstream_node->get("length",       &m_slipstream_length            );
        slipstream_node->get("collect-time", &m_slipstream_collect_time      );
        slipstream_node->get("use-time",     &m_slipstream_use_time          );
        slipstream_node->get("add-power",    &m_slipstream_add_power         );
        slipstream_node->get("min-speed",    &m_slipstream_min_speed         );
        slipstream_node->get("max-speed-increase", 
                                             &m_slipstream_max_speed_increase);
        slipstream_node->get("duration",     &m_slipstream_duration          );
        slipstream_node->get("fade-out-time",&m_slipstream_fade_out_time     );
    }

    if(const XMLNode *turn_node = root->getNode("turn"))
    {
        turn_node->get("time-full-steer",      &m_time_full_steer   );
        turn_node->get("time-full-steer-ai",   &m_time_full_steer_ai);
        std::vector<float> v;
        if(turn_node->get("min-speed-radius", &v))
        {
            if(v.size()!=2)
                printf("Incorrect min-speed-radius specifications for kart '%s'\n",
                getIdent().c_str());
            else
            {
                m_min_speed_turn = v[0];
                m_min_radius     = v[1];
            }
        }

        v.clear();
        if(turn_node->get("max-speed-radius", &v))
        {
            if(v.size()!=2)
                printf("Incorrect max-speed-radius specifications for kart '%s'\n",
                getIdent().c_str());
            else
            {
                m_max_speed_turn = v[0];
                m_max_radius     = v[1];
            }
        }
    }   // if turn_node

    if(const XMLNode *engine_node = root->getNode("engine"))
    {
        engine_node->get("brake-factor", &m_brake_factor);
        engine_node->get("max-speed-reverse-ratio", &m_max_speed_reverse_ratio);
        std::vector<float> v;
        if( engine_node->get("power", &v))
        {
            if(v.size()!=3)
                printf("Incorrect engine-power specifications for kart '%s'\n",
                getIdent().c_str());
            else
            {
                m_engine_power[0] = v[0];
                m_engine_power[1] = v[1];
                m_engine_power[2] = v[2];
            }
        }   // if engine-power
        v.clear();
        if( engine_node->get("max-speed", &v))
        {
            if(v.size()!=3)
                printf("Incorrect max-speed specifications for kart '%s'\n",
                getIdent().c_str());
            else
            {
                m_max_speed[0] = v[0];
                m_max_speed[1] = v[1];
                m_max_speed[2] = v[2];
            }
        }   // if max-speed
    }   // if getNode("engine")

    if(const XMLNode *gear_node = root->getNode("gear"))
    {
        gear_node->get("switch-ratio",   &m_gear_switch_ratio  );
        gear_node->get("power-increase", &m_gear_power_increase);
    }

    if(const XMLNode *mass_node = root->getNode("mass"))
        mass_node->get("value", &m_mass);


    if(const XMLNode *suspension_node = root->getNode("suspension"))
    {
        suspension_node->get("stiffness", &m_suspension_stiffness);
        suspension_node->get("rest",      &m_suspension_rest     );
        suspension_node->get("travel-cm", &m_suspension_travel_cm);
    }

    if(const XMLNode *wheels_node = root->getNode("wheels"))
    {
        wheels_node->get("damping-relaxation",  &m_wheel_damping_relaxation );
        wheels_node->get("damping-compression", &m_wheel_damping_compression);
        wheels_node->get("radius",              &m_wheel_radius             );
    }

    if(const XMLNode *friction_node = root->getNode("friction"))
        friction_node->get("slip", &m_friction_slip);

    if(const XMLNode *stability_node = root->getNode("stability"))
    {
        stability_node->get("roll-influence",          &m_roll_influence);
        stability_node->get("chassis-linear-damping",  &m_chassis_linear_damping);
        stability_node->get("chassis-angular-damping", &m_chassis_angular_damping);
    }

    if(const XMLNode *upright_node = root->getNode("upright"))
    {
        upright_node->get("tolerance", &m_upright_tolerance);
        upright_node->get("max-force", &m_upright_max_force);
    }

    if(const XMLNode *track_connection_node = root->getNode("track-connection-accel"))
        track_connection_node->get("value", &m_track_connection_accel);

    if(const XMLNode *jump_node = root->getNode("jump"))
        jump_node->get("velocity", &m_jump_velocity);

    if(const XMLNode *collision_node = root->getNode("collision"))
        collision_node->get("side-impulse",  &m_collision_side_impulse);

    //TODO: wheel front right and wheel front left is not loaded, yet is listed as an attribute in the xml file after wheel-radius
    //TODO: same goes for their rear equivalents

    if(const XMLNode *plunger_node= root->getNode("plunger"))
    {
        plunger_node->get("band-max-length", &m_rubber_band_max_length  );
        plunger_node->get("band-force",      &m_rubber_band_force       );
        plunger_node->get("band-duration",   &m_rubber_band_duration    );
        std::vector<float> v;
        plunger_node->get("in-face-time",    &v);
        if(v.size()!=3)
        {
            printf("Invalid plunger in-face-time specification.");
        }
        m_plunger_in_face_duration[0] = v[0];
        m_plunger_in_face_duration[1] = v[1];
        m_plunger_in_face_duration[2] = v[2];
    }

    if(const XMLNode *zipper_node= root->getNode("zipper"))
    {
        zipper_node->get("time",               &m_zipper_time              );
        zipper_node->get("fade-out-time",      &m_zipper_fade_out_time     );
        zipper_node->get("force",              &m_zipper_force             );
        zipper_node->get("speed-gain",         &m_zipper_speed_gain        );
        zipper_node->get("max-speed-increase", &m_zipper_max_speed_increase);
    }

    if(const XMLNode *camera_node= root->getNode("camera"))
    {
        camera_node->get("distance", &m_camera_distance);
        camera_node->get("forward-up-angle", &m_camera_forward_up_angle);
        m_camera_forward_up_angle *= DEGREE_TO_RAD;
        camera_node->get("backward-up-angle", &m_camera_backward_up_angle);
        m_camera_backward_up_angle *= DEGREE_TO_RAD;
    }

    if(const XMLNode *startup_node= root->getNode("startup"))
    {
        startup_node->get("time", &m_startup_times);
        startup_node->get("boost", &m_startup_boost);
    }

    if(const XMLNode *sounds_node= root->getNode("sounds"))
    {
        std::string s;
        sounds_node->get("engine", &s);
        if      (s == "large") m_engine_sfx_type = "engine_large";
        else if (s== "small")  m_engine_sfx_type = "engine_small";

#ifdef WILL_BE_ENABLED_ONCE_DONE_PROPERLY
        // Load custom kart SFX files (TODO: enable back when it's implemented properly)
        for (int i = 0; i < SFXManager::NUM_CUSTOMS; i++)
        {
            std::string tempFile;
            // Get filename associated with each custom sfx tag in sfx config
            if (sounds_node->get(sfx_manager->getCustomTagName(i), tempFile))
            {
                // determine absolute filename
                // FIXME: will not work with add-on packs (is data dir the same)?
                tempFile = file_manager->getKartFile(tempFile, getIdent());

                // Create sfx in sfx manager and store id
                m_custom_sfx_id[i] = sfx_manager->addSingleSfx(tempFile, 1, 0.2f,1.0f);
            }
            else
            {
                // if there is no filename associated with a given tag
                m_custom_sfx_id[i] = -1;
            }   // if custom sound
        }   // for i<SFXManager::NUM_CUSTOMS
#endif
    }   // if sounds-node exist

    if(m_kart_model)
        m_kart_model->loadInfo(*root);
}   // getAllData
示例#20
0
 void processAssign(std::string& lop, std::string& rop)
 {
   *getIdent(lop) = *getIdent(rop);
   eraseCommand();
 }