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
// Global function for checking if SCP is enabled at all function IsSCPEnabled() { return GSController.GetSetting("scp_support"); } // SCP Manager class class SCPManager { _main_ptr = null; _scp_enabled = null; static COMMAND_SET = "Company Value GS"; constructor(main_ptr) { this._scp_enabled = IsSCPEnabled(); this._main_ptr = main_ptr; this.SetupSCP(); } } function DataToStr(data) { if (data == null) { return "null"; } 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(); } } return s + "]"; } function SCPManager::SetupSCP() { if (!this._scp_enabled) return; SCPLib("CVGS", 4, null); SCPLib.SCPLogging_Info(this._main_ptr.debug_messages >= 2); SCPLib.SCPLogging_Error(this._main_ptr.debug_messages >= 3); // Register commands local self = this; // AI -> GS commands: SCPLib.AddCommand("CurrentGoal", COMMAND_SET, self, SCPManager.ReceivedCurrentGoalCommand); // GS -> AI commands: } function SCPManager::Check() { if (!this._scp_enabled) return; // Update SCP logging in case the log level was changed SCPLib.SCPLogging_Info(this._main_ptr.debug_messages >= 2); SCPLib.SCPLogging_Error(this._main_ptr.debug_messages >= 3); // Let SCP check for incoming messages if (this._main_ptr.debug_messages >= 3) GSLog.Info("SCP: Check for incoming messages"); return SCPLib.Check(); } /***************************************************************** * * * Outgoing Commands - commands that we can send to AIs * * * *****************************************************************/ // Call one of these methods to send a command to an AI. function SCPManager::SendGoalData() { if (!this._scp_enabled) return false; for (local to_company = GSCompany.COMPANY_FIRST; to_company < GSCompany.COMPANY_LAST; to_company++) { if (GSCompany.ResolveCompanyID(to_company) != GSCompany.COMPANY_INVALID) { if (!SCPLib.CanSpeakWith(to_company)) { continue; } this.SendCurrentGoal(to_company); } } } /* * @param to_company Which company to send the message to * @param answer_to_message if this command is sent in return to a query, pass the query message instance with this parameter * * See ReceivedCurrentGoalCommand for a detailed explanation of the transmitted data (or just read the code). */ function SCPManager::SendCurrentGoal(to_company, answer_to_message = null) { if (!this._scp_enabled) return false; if (answer_to_message == null && !SCPLib.CanSpeakWith(to_company)) return false; local goal_mode = this._main_ptr.goal_mode == null ? true : this._main_ptr.goal_mode; local response_value = (this._main_ptr.best_value / 1000).tostring(); local result = [to_company, this._main_ptr.goal_mode, response_value]; if (this._main_ptr.debug_messages >= 2) GSLog.Info("SCP: " + (answer_to_message != null ? "Sending response to message from " : "Telling company ") + GSCompany.GetName(to_company)); if (this._main_ptr.debug_messages >= 1) GSLog.Info("SCP: Sent CurrentGoal command with data: " + DataToStr(result)); if (answer_to_message != null) { SCPLib.Answer(answer_to_message, result); } else { SCPLib.TellCompany("CurrentGoal", COMMAND_SET, to_company, result); } return true; } /***************************************************************** * * * Incoming Commands - commands that we can get from AIs * * * *****************************************************************/ // These methods are called by the SCP library when we call SCPLib.Check() and there is // a received incoming message. /* * Input: * Data[0] => CompanyID to get goal of * * Output: * Data[0] => Company ID of the company that these values are valid for * Data[1] => Goal Mode boolean * Data[2] => Goal Value. The value is divided by 1000 and then sent as a string. */ function SCPManager::ReceivedCurrentGoalCommand(message, self) { if (!self._scp_enabled) return; if (self._main_ptr.debug_messages >= 1) GSLog.Info("SCP: Received CurrentGoal command with data: " + DataToStr(message.Data)); if (self._main_ptr.debug_messages >= 1) GSLog.Info("SCP: " + GSCompany.GetName(message.SenderID) + " asks for the current goal"); if (!self.SendCurrentGoal(message.SenderID, message)) { if (self._main_ptr.debug_messages >= 1) GSLog.Info("SCP: Unknown sender asks for its current goal"); // Can't find company - respond to the sender with null to tell // that we got the command, but couldn't find any result for the // company. SCPLib.Answer(message, null); } }
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever