Loading
#openttdcoop - Paste
Archives
Trending
Docs
Login
ABAP
ActionScript
ActionScript 3
Ada
AIMMS3
ALGOL 68
Apache configuration
AppleScript
Apt sources
ARM ASSEMBLER
ASM
ASP
asymptote
Autoconf
Autohotkey
AutoIt
AviSynth
awk
BASCOM AVR
Bash
Basic4GL
BibTeX
BlitzBasic
bnf
Boo
Brainfuck
C
C#
C (LoadRunner)
C (Mac)
C (WinAPI)
C++
C++ (Qt)
C++ (WinAPI)
CAD DCL
CAD Lisp
CFDG
ChaiScript
Chapel
CIL
Clojure
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
Dart
DCL
DCPU-16 Assembly
DCS
Delphi
Diff
DIV
DOS
dot
E
ECMAScript
Eiffel
eMail (mbox)
EPC
Erlang
Euphoria
EZT
F#
Falcon
FO (abas-ERP)
Formula One
Fortran
FreeBasic
FreeSWITCH
GADV 4CS
GAMBAS
GDB
genero
Genie
glSlang
GML
GNU/Octave
GNU Gettext
GNU make
Gnuplot
Go
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML
HTML5
Icon
INI
Inno
INTERCAL
Io
ISPF Panel
J
Java
Java(TM) 2 Platform Standard Edition 5.0
Javascript
JCL
jQuery
KiXtart
KLone C
KLone C++
LaTeX
LDIF
Liberty BASIC
Lisp
LLVM Intermediate Representation
Locomotive Basic
Logtalk
LOLcode
Lotus Notes @Formulas
LotusScript
LScript
LSL2
Lua
MagikSF
MapBasic
Matlab M
Microchip Assembler
Microsoft Registry
mIRC Scripting
MMIX
Modula-2
Modula-3
MOS 6502 (6510) ACME Cross Assembler format
MOS 6502 (6510) Kick Assembler format
MOS 6502 (6510) TASM/64TASS 1.46 Assembler format
Motorola 68000 - HiSoft Devpac ST 2 Assembler format
Motorola 68000 Assembler
MXML
MySQL
Nagios
NetRexx
newlisp
nginx
Nimrod
NML NewGRF Meta Language
NSIS
Oberon-2
Objeck Programming Language
Objective-C
OCaml
OCaml (brief)
ooRexx
OpenBSD Packet Filter
OpenOffice.org Basic
Oracle 8 SQL
Oracle 11 SQL
Oxygene
OZ
ParaSail
PARI/GP
Pascal
PCRE
per
Perl
Perl 6
PHP
PHP (brief)
PIC16
Pike
Pixel Bender 1.0
PL/I
PL/SQL
PostgreSQL
PostScript
POVRAY
PowerBuilder
PowerShell
ProFTPd configuration
Progress
Prolog
PROPERTIES
ProvideX
Puppet
PureBasic
Python
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
R / S+
Racket
Rails
RBScript
REBOL
rexx
robots.txt
RPM Specification File
Ruby
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty
SPARK
SPARQL
SQL
Squirrel Script
Squirrel Script with OpenTTD AI/GS
StandardML
StoneScript
SystemVerilog
T-SQL
TCL
Tera Term Macro
Text
thinBasic
TypoScript
Unicon (Unified Extended Dialect of Icon)
Uno Idl
Unreal Script
UPC
Urbi
Vala
vb.net
VBScript
Vedit macro language
Verilog
VHDL
Vim Script
Visual Basic
Visual Fox Pro
Visual Prolog
Whitespace
Whois (RPSL format)
Winbatch
X++
XBasic
XML
Xorg configuration
YAML
ZiLOG Z80 Assembler
ZXBasic
class SCPClient_CompanyValueGS { /* Private members variables */ static COMMAND_SET = "Company Value GS"; _scp = null; // SCPLib instance _goal_mode = null; _goal_value = null; _company_value_gs_game = null; // Is this a Company Value GS game? (true/null) /** * Library constructor * @param scp_ptr Instance of SCPLib. If null is passed, the library * will act as if no Company Value GS has been detected. */ constructor(scp_ptr) { this._goal_mode = null; this._goal_value = null; this._company_value_gs_game = null; this._scp = scp_ptr; this.RegisterCommands(); this.AskForGoals(); } /* Public methods */ /** * Is this a Company Value GS game? * @return true, if the game has a GS that respond to Company Value GS * commands, otherwise false. * @note If you call this method too early, it will return false even if * the game has the Company Value GS with SCP activated because a round-trip * has not yet been completed. */ function IsCompanyValueGSGame(); /** * Is Company Value GS running in Goal mode? * In this mode, companies are competing to become the first to reach a * company value target. See GetCurrentTargetValue to get the value. * @return true, if Company Value GS is running in Goal mode. * @note When it returns false, it doesn't necessarily mean that Company Value GS * is running in Ranking mode. * @note When the target value is reached by one of the companies, Company Value GS * pauses the game, and switches from Goal mode to Ranking mode after a user presses * the "Continue" button. Note that AIs are unable to respond when the game is paused. */ function IsCompanyValueGSInGoalMode(); /** * Is Company Value GS running in Ranking mode? * In this mode, companies are competing between each other to be the most * valuable company at all times. See GetBestCompanyValue to get the value. * @return true, if Company Value GS is running in Ranking mode. * @note When it returns false, it doesn't necessarily mean that Company Value GS * is running in Goal mode. */ function IsCompanyValueGSInRankingMode(); /** * Get the Company ID of the current most valuable company. * @return CompanyID of the company with the highest value at the moment. * @note Returns AICompany.COMPANY_INVALID when Company Value GS SCP isn't active, * or when no companies are found (shouldn't happen, because we're a company too). */ function GetBestCompanyID(); /** * Get the value of the current most valuable company. * @return integer value of the company with the best value at the moment. * @note Returns -1 when Company Value GS SCP isn't active, or when no companies * are found (shouldn't happen, because we're a company too). */ function GetBestCompanyValue(); /** * Get the current targeted value to be reached. * In Goal mode, the value is defined in the Company Value GS settings. * In Ranking mode, the value is that of the current most valuable company. * @return integer value of the current target to be reached. * @note Returns -1 when Company Value GS SCP isn't active, or when no companies * are found (shouldn't happen, because we're a company too). */ function GetCurrentTargetValue(); /** * Get a list of companies, sorted by their respective values in descending order. * @return AIList with Company ID as the item, and Company Value as the value * @note Returns an empty AIList when Company Value GS SCP isn't active, or when * no companies are found (shouldn't happen, because we're a company too). */ function GetRankingList(); /** * Get the rank position of the provided Company ID from a list of running * companies with their respective company values. * @param company_id The Company ID to get the rank of. * @return integer position of provided company in relation to the * others regarding their company value. * @note The rank at the top has a value of 1. The rank at the bottom has a value * dependent on the number of companies running in the game. * @note Returns -1 when the provided Company ID is invalid, or when no companies * are found (shouldn't happen, because we're a company too). */ function GetCompanyIDRank(company_id); /** * Get the company value of the provided Company ID. * @param company_id The Company ID to get the company value of. * @return integer value of the specified company. * @note Returns -1 when Company Value GS SCP isn't active, or when the provided * Company ID is invalid. */ function GetCompanyIDValue(company_id); /** * Get the difference in company value between the current targeted value and the * provided Company ID's value. * @param company_id The Company ID in which the difference is based of. * @return integer value of the difference in company value between the current * targeted value and the specified Company ID's value. * @note The difference is always equal or higher than zero. * @note Returns -1 when Company Value GS SCP isn't active, or when the provided * Company ID is invalid. */ function GetCompanyIDDiffToTarget(company_id); /** * Get the difference in company value between the value of the best company and * the provided Company ID's value. * @param company_id The Company ID in which the difference is based of. * @return integer value of the difference in company value between the best * company and the specified Company ID. * @note The difference is always equal or higher than zero. * @note Returns -1 when Company Value GS SCP isn't active, or when the provided * Company ID is invalid. */ function GetCompanyIDDiffToBest(company_id); } /**** Private methods: ****/ function SCPClient_CompanyValueGS::RegisterCommands() { if (this._scp == null) return; local self = this; // AI -> GS commands: this._scp.AddCommand("CurrentGoal", COMMAND_SET, self, SCPClient_CompanyValueGS.ReceivedCurrentGoalCommand); // GS -> AI commands: } function SCPClient_CompanyValueGS::AskForGoals() { if (this._scp == null) return; this._scp.QueryServer("CurrentGoal", COMMAND_SET, [AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)]); } /**** Public API methods: ****/ function SCPClient_CompanyValueGS::IsCompanyValueGSGame() { if (this._scp == null) return false; return this._company_value_gs_game == true; } function SCPClient_CompanyValueGS::IsCompanyValueGSInGoalMode() { if (this._scp == null) return false; return this._goal_mode == true; } function SCPClient_CompanyValueGS::IsCompanyValueGSInRankingMode() { if (this._scp == null) return false; return this._goal_mode == false; } function SCPClient_CompanyValueGS::GetBestCompanyID() { if (this._scp == null) return AICompany.COMPANY_INVALID; if (this._company_value_gs_game != true) return AICompany.COMPANY_INVALID; local best_company_id = AICompany.COMPANY_INVALID; local best_company_value = -1; for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) { if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) { local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER); if (c_value >= best_company_value) { best_company_id = c_id; best_company_value = c_value; } } } return best_company_id; } function SCPClient_CompanyValueGS::GetBestCompanyValue() { if (this._scp == null) return -1; if (this._company_value_gs_game != true) return -1; local best_company_value = -1; for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) { if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) { local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER); if (c_value >= best_company_value) { best_company_value = c_value; } } } return best_company_value; } function SCPClient_CompanyValueGS::GetCurrentTargetValue() { if (this._scp == null) return -1; if (this._company_value_gs_game != true) return -1; if (this._goal_mode == true) return this._goal_value; return this.GetBestCompanyValue(); } function SCPClient_CompanyValueGS::GetRankingList() { if (this._scp == null) return AIList(); if (this._company_value_gs_game != true) return AIList(); local global_list = AIList(); for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) { if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) { local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER); global_list.AddItem(c_id, c_value); } } global_list.Sort(AIList.SORT_BY_VALUE, AIList.SORT_DESCENDING); return global_list; } function SCPClient_CompanyValueGS::GetCompanyIDRank(company_id) { if (this._scp == null) return -1; if (this._company_value_gs_game != true) return -1; if (AICompany.ResolveCompanyID(company_id) == AICompany.COMPANY_INVALID) return -1; local global_list = this.GetRankingList(); local rank = 0; for (local c_id = global_list.Begin(); !global_list.IsEnd(); c_id = global_list.Next()) { rank++; if (c_id == company_id) { return rank; } } return -1; } function SCPClient_CompanyValueGS::GetCompanyIDValue(company_id) { if (this._scp == null) return -1; if (this._company_value_gs_game != true) return -1; if (AICompany.ResolveCompanyID(company_id) == AICompany.COMPANY_INVALID) return -1; return AICompany.GetQuarterlyCompanyValue(company_id, AICompany.CURRENT_QUARTER); } function SCPClient_CompanyValueGS::GetCompanyIDDiffToTarget(company_id) { if (this._scp == null) return -1; if (this._company_value_gs_game != true) return -1; if (AICompany.ResolveCompanyID(company_id) == AICompany.COMPANY_INVALID) return -1; local current_target = this.GetCurrentTargetValue(); local company_id_value = this.GetCompanyIDValue(company_id); local difference = -1; if (current_target != -1 && company_id_value != -1) { difference = current_target - company_id_value; } return difference; } function SCPClient_CompanyValueGS::GetCompanyIDDiffToBest(company_id) { if (this._scp == null) return -1; if (this._company_value_gs_game != true) return -1; if (AICompany.ResolveCompanyID(company_id) == AICompany.COMPANY_INVALID) return -1; local best_company_value = this.GetBestCompanyValue(); local company_id_value = this.GetCompanyIDValue(company_id); local difference = -1; if (best_company_value != -1 && company_id_value != -1) { difference = best_company_value - company_id_value; } return difference; } /** SCP in/out methods (private to the library) */ /***************************************************************** * * * Outgoing Commands - commands that we can send to GSes * * * *****************************************************************/ /***************************************************************** * * * Incoming Commands - commands that we can get from AIs * * * *****************************************************************/ // These methods are called by the SCP library when we call this._scp.Check() and there is // a received incoming message. // Use 'self' instead of 'this'. function SCPClient_CompanyValueGS::ReceivedCurrentGoalCommand(message, self) { self._company_value_gs_game = true; local data0 = message.GetIntData(0); // Company ID local data1 = message.GetBoolData(1); // Goal Mode local data2 = message.GetStringData(2); // Goal Value divided by 1000, received as a string local data = [data0, data1, data2]; local s = "["; foreach (d in data) { if (s != "[") { s += ", "; } if (d == null) { s += "null"; } else if (typeof(d) == "string") { s += "\"" + d + "\""; } else { s += d.tostring(); } } s += "]"; if (data0 != null && AICompany.IsMine(data0)) { self._goal_mode = data1; self._goal_value = data2.tointeger() * 1000; AILog.Info("SCP: Reveived CurrentGoal command with data: " + s); } }
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever