Loading

Paste #puya3ikkl

  1.     /**
  2.      * Get the difference in company value between the value of the provided company
  3.      * and the next ahead or behind in the rank list.
  4.      * @param company_id The Company ID in which the difference is based of.
  5.      * @param next_ahead_in_rank boolean value (use 'true' to compare with the next
  6.      * ahead in rank or 'false' to compare with the next behind in rank).
  7.      * @note The difference is always equal or higher than zero.
  8.      * @note Returns -1 when Company Value GS SCP isn't active, or when the provided
  9.      * Company ID is invalid.
  10.      * @note Returns 0 when there is no company ahead or behind in rank.
  11.      */
  12.     function GetCompanyIDDiffToNext(company_id, next_ahead_in_rank);
  13.  
  14.  
  15.  
  16. function SCPClient_CompanyValueGS::GetCompanyIDDiffToNext(company_id, next_ahead_in_rank)
  17. {
  18.     if (this._scp == null) return -1;
  19.     if (this._company_value_gs_game != true) return -1;
  20.    
  21.     if (AICompany.ResolveCompanyID(company_id) == AICompany.COMPANY_INVALID) return -1;
  22.     if (typeof(next_ahead_in_rank) != "bool") return -1;
  23.    
  24.     local global_list = this.GetRankingList();
  25.     if (global_list.Count() == 0) return -1;
  26.    
  27.     local difference = 0;
  28.     if (global_list.Count() == 1) return difference;
  29.    
  30.     local company_id_rank = this.GetCompanyIDRank(company_id);
  31.     if (company_id_rank == 1 && next_ahead_in_rank || company_id_rank == global_list.Count() && !next_ahead_in_rank) return difference;
  32.    
  33.     local rank = 0;
  34.     local next_company_id = AICompany.COMPANY_INVALID;
  35.     for (local c_id = global_list.Begin(); !global_list.IsEnd(); c_id = global_list.Next()) {
  36.         rank++;
  37.         if (rank == (company_id_rank + (next_ahead_in_rank ? -1 : 1))) {
  38.             next_company_id = c_id;
  39.             break;
  40.         }
  41.     }
  42.  
  43.     if (next_ahead_in_rank) {
  44.         difference = this.GetCompanyIDValue(next_company_id) - this.GetCompanyIDValue(company_id);
  45.     } else {
  46.         difference = this.GetCompanyIDValue(company_id) - this.GetCompanyIDValue(next_company_id);
  47.     }
  48.     return difference;
  49. }

Comments