Difficulty scaling/zh: Difference between revisions

Created page with "<source lang="c++"> bool Ecosystem::LevelSensor::scaleWeapon(const sead::SafeString& weapon_to_look_up, // 基礎武器                                    ..."
(Created page with "如果函數找半天找不到滿足給定的條件武器、加成,遊戲就會用預設的武器、預設的加成。(程式碼裡最後的 return false 會處理所有...")
(Created page with "<source lang="c++"> bool Ecosystem::LevelSensor::scaleWeapon(const sead::SafeString& weapon_to_look_up, // 基礎武器                                    ...")
Line 235: Line 235:


<source lang="c++">
<source lang="c++">
bool Ecosystem::LevelSensor::scaleWeapon(const sead::SafeString& weapon_to_look_up,
bool Ecosystem::LevelSensor::scaleWeapon(const sead::SafeString& weapon_to_look_up, // 基礎武器
                                        WeaponModifier required_modifier,
                                        WeaponModifier required_modifier, // 預設至少加這麼多
                                        const char** weapon_to_use_name,
                                        const char** weapon_to_use_name, // 回傳的武器寫在這裡
                                        WeaponModifier* modifier_to_use,
                                        WeaponModifier* modifier_to_use, // 回傳的加成寫在這裡
                                         void* unknown)
                                         void* unknown)
{
{
   // some checks using 'unknown' here which seems to be a pointer to the actor
   // some checks using 'unknown' here which seems to be a pointer to the actor
  //
 
   for (weapon_table : this->byml["weapon"]) {
   for (weapon_table : this->byml["weapon"]) {
     // find the first weapon entry for which the player has enough points
     // find the first weapon entry for which the player has enough points
     // with the specified name and modifier
     // with the specified name and modifier
    i = -1;
   // 不同的武器系列儲存在不同的 table 裡,要枚舉 table 再枚舉 table 裡的細項
    for (j = 0; j < weapon_table["actors"].size; ++j) {
   i = -1; // 應該是 index,但是 -1 代表尚未找到
      entry = weapon_table["actors"][j];
   for (j = 0; j < weapon_table["actors"].size; ++j) { // 枚舉含有加成訊息的武器
      float points_for_next_transition = entry["value"];
     entry = weapon_table["actors"][j];
      //
     float points_for_next_transition = entry["value"]; // 這個加成過的武器所需的經驗值
      if (this->weapon_points > points_for_next_transition &&
 
          weapon_to_look_up == entry["name"] &&
     if (this->weapon_points > points_for_next_transition && // 你的經驗值夠
          convert_to_modifier(entry["plus"]) == required_modifier) {
         weapon_to_look_up == entry["name"] && // 武器的名字是對的
        i = j;
         convert_to_modifier(entry["plus"]) == required_modifier) { // 加成的方向跟程度是對的
        break;
       i = j;
      }
       break; // 找到一個了(但是可能還有更多)
     }
     }
     }
    //
 
     if (i == -1)
     if (i == -1)
      continue;
     continue; // 找不到就試下一個
    //
 
    do {
   do { // 已知找到一個的情況下,試圖找更多
      entry = weapon_table["actors"][i];
     entry = weapon_table["actors"][i];
      //
 
       // not_rank_up means there is no link between weapons;
       // not_rank_up means there is no link between weapons;
       // this table is just used to look up modifiers.
       // this table is just used to look up modifiers.
Line 270: Line 271:
       // or until we reach a modifier that requires more points.
       // or until we reach a modifier that requires more points.
       if (weapon_table["not_rank_up"] && entry["name"] != weapon_to_look_up)
       if (weapon_table["not_rank_up"] && entry["name"] != weapon_to_look_up)
        break;
       break; // ???這個 table 裡的武器不能升級,或是 entry 是 null (boundary check)
      //
 
       // otherwise, just go down the list until we reach the end or a weapon which
       // otherwise, just go down the list until we reach the end or a weapon which
       // requires more points. this will possibly upgrade the weapon (e.g. Knight -> Royal).
       // requires more points. this will possibly upgrade the weapon (e.g. Knight -> Royal).
       if (this->weapon_points <= entry["value"])
       if (this->weapon_points <= entry["value"])
        break;
       break; // 枚舉到經驗值最高又符合條件的才停
      //
 
       ++i;
       ++i;
     } while (i < weapon_table["actors"].size);
     } while (i < weapon_table["actors"].size);
    //
 
     *weapon_to_use_name = entry["name"];
     *weapon_to_use_name = entry["name"];
     *modifier_to_use = convert_to_modifier(entry["plus"]);
     *modifier_to_use = convert_to_modifier(entry["plus"]);
    return true;
   return true; // 有找到
   }
   }
   return false;  // cannot scale up
   return false;  // cannot scale up // 沒找到
}
}
</source>
</source>