Loading

Paste #prohqfkhe

  1.     /* Public methods */
  2.  
  3.     /**
  4.      * Is this a Company Value GS game?
  5.      * @return true, if the game has a GS that respond to Company Value GS
  6.      * commands, otherwise false.
  7.      * @note If you call this method to early, it will return false even if
  8.      * the game has the Company Value GS with SCP activated because a round-trip
  9.      * has not yet been completed.
  10.      */
  11.     function IsCompanyValueGSGame();
  12.    
  13.     /**
  14.      * Is Company Value GS running in Goal mode?
  15.      * In this mode, companies are competing to become the first to reach a
  16.      * company value target. See GetCurrentTargetValue to get the value.
  17.      * @return true, if Company Value GS is running in Goal mode.
  18.      * @note When it returns false, it doesn't necessarily mean that Company Value GS
  19.      * is running in Ranking mode.
  20.      * @note When the target value is reached by one of the companies, Company Value GS
  21.      * pauses the game, and switches from Goal mode to Ranking mode after a user presses
  22.      * the "Continue" button. Note that AIs are unable to respond when the game is paused.
  23.      */
  24.     function IsCompanyValueGSInGoalMode();
  25.    
  26.     /**
  27.      * Is Company Value GS running in Ranking mode?
  28.      * In this mode, companies are competing between each other to be the most
  29.      * valuable company at all times. See GetBestCompanyValue to get the value.
  30.      * @return true, if Company Value GS is running in Ranking mode.
  31.      * @note When it returns false, it doesn't necessarily mean that Company Value GS
  32.      * is running in Goal mode.
  33.      */
  34.     function IsCompanyValueGSInRankingMode();
  35.    
  36.     /**
  37.      * Get the Company ID of the current most valuable company.
  38.      * @return CompanyID of the company with the highest value at the moment.
  39.      * @note Returns AICompany.COMPANY_INVALID when Company Value GS SCP isn't active,
  40.      * or when no companies are found (shouldn't happen, because we're a company too).
  41.      */
  42.     function GetBestCompanyID();
  43.    
  44.     /**
  45.      * Get the value of the current most valuable company.
  46.      * @return integer value of the company with the best value at the moment.
  47.      * @note Returns -1 when Company Value GS SCP isn't active, or when no companies
  48.      * are found (shouldn't happen, because we're a company too).
  49.      */
  50.     function GetBestCompanyValue();
  51.    
  52.     /**
  53.      * Get the current targetted value to be reached.
  54.      * In Goal mode, the value is defined in the Company Value GS settings.
  55.      * In Ranking mode, the value is that of the current most valuable company.
  56.      * @return integer value of the current target to be reached.
  57.      * @note Returns -1 when Company Value GS SCP isn't active, or when no companies
  58.      * are found (shouldn't happen, because we're a company too).
  59.      */
  60.     function GetCurrentTargetValue();
  61.    
  62.     /**
  63.      * Get the rank position of the provided Company ID from a list of running
  64.      * companies with their respective company values.
  65.      * @return integer position of provided company in relation to the
  66.      * others regarding their company value.
  67.      * @note The rank at the top has a value of 1. The rank at the bottom has a value
  68.      * dependant on the number of companies running in the game.
  69.      * @note Returns -1 when the provided Company ID is invalid, or when no companies
  70.      * are found (shouldn't happen, because we're a company too).
  71.      */
  72.     function GetCompanyIDRank(company_id);
  73. }
  74.  
  75. /**** Public API methods: ****/
  76.  
  77. function SCPClient_CompanyValueGS::IsCompanyValueGSGame()
  78. {
  79.     if (this._scp == null) return false;
  80.    
  81.     return this._company_value_gs_game == true;
  82. }
  83.  
  84. function SCPClient_CompanyValueGS::IsCompanyValueGSInGoalMode()
  85. {
  86.     if (this._scp == null) return false;
  87.    
  88.     return this._goal_mode == true;
  89. }
  90.  
  91. function SCPClient_CompanyValueGS::IsCompanyValueGSInRankingMode()
  92. {
  93.     if (this._scp == null) return false;
  94.  
  95.     return this._goal_mode == false;
  96. }
  97.  
  98. function SCPClient_CompanyValueGS::GetBestCompanyID()
  99. {
  100.     if (this._scp == null) return AICompany.COMPANY_INVALID;
  101.     if (this._company_value_gs_game != true) return AICompany.COMPANY_INVALID;
  102.  
  103.     local best_company_id = AICompany.COMPANY_INVALID;
  104.     local best_company_value = -1;
  105.     for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) {
  106.         if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) {
  107.             local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER);
  108.             if (c_value >= best_company_value) {
  109.                 best_company_id = c_id;
  110.                 best_company_value = c_value;
  111.             }
  112.         }
  113.     }
  114.     return best_company_id;
  115. }
  116.  
  117. function SCPClient_CompanyValueGS::GetBestCompanyValue()
  118. {
  119.     if (this._scp == null) return -1;
  120.     if (this._company_value_gs_game != true) return -1;
  121.  
  122.     local best_company_value = -1;
  123.     for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) {
  124.         if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) {
  125.             local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER);
  126.             if (c_value >= best_company_value) {
  127.                 best_company_value = c_value;
  128.             }
  129.         }
  130.     }
  131.     return best_company_value;
  132. }
  133.  
  134. function SCPClient_CompanyValueGS::GetCurrentTargetValue()
  135. {
  136.     if (this._scp == null) return -1;
  137.     if (this._company_value_gs_game != true) return -1;
  138.    
  139.     if (this._goal_mode == true) return this._goal_value;
  140.     return this.GetBestCompanyValue();
  141. }
  142.  
  143. function SCPClient_CompanyValueGS::GetCompanyIDRank(company_id)
  144. {
  145.     if (this._scp == null) return -1;
  146.     if (this._company_value_gs_game != true) return -1;
  147.    
  148.     if (AICompany.ResolveCompanyID(company_id) == AICompany.COMPANY_INVALID) return -1;
  149.    
  150.     local global_list = AIList();  
  151.     for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) {
  152.         if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) {
  153.             local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER);
  154.             global_list.AddItem(c_id, c_value);
  155.         }
  156.     }
  157.     global_list.Sort(AIList.SORT_BY_VALUE, AIList.SORT_DESCENDING);
  158.    
  159.     local rank = 0;
  160.     for (local c_id = global_list.Begin(); !global_list.IsEnd(); c_id = global_list.Next()) {
  161.         rank++;
  162.         if (c_id == company_id) {
  163.             return rank;
  164.         }
  165.     }
  166.     return -1;
  167. }

Comments

GetCompanyIDRank could be changed into a method that returns an AIList. Eg. your sorted global_list. Then the AI doesn't need to rebuild the list for each company ID if it wants to build a list itself.

Anonymous • 24 Dec 2018, 22:48:17 UTC

Looks understandable to me, just a few minor gramatical errors (Listed below)

7c7
< * @note If you call this method to early, it will return false even if
---
> * @note If you call this method too early, it will return false even if
53c53
< * Get the current targetted value to be reached.
---
> * Get the current targeted value to be reached.
68c68
< * dependant on the number of companies running in the game.
---
> * dependent on the number of companies running in the game.

Anonymous • 24 Dec 2018, 20:07:40 UTC