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
static CargoID cargo_type_comparator; static int CDECL CompareCargoRatings(Station * const *a, Station * const *b) { return (*b)->goods[cargo_type_comparator].rating - (*a)->goods[cargo_type_comparator].rating; } uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList *all_stations) { /* Return if nothing to do. Also the rounding below fails for 0. */ if (amount == 0) return 0; StationList used_stations; for (Station * const *st_iter = all_stations->Begin(); st_iter != all_stations->End(); ++st_iter) { Station *st = *st_iter; /* Is the station reserved exclusively for somebody else? */ if (st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue; if (st->goods[type].rating == 0) continue; // Lowest possible rating, better not to give cargo anymore if (_settings_game.order.selectgoods && !st->goods[type].HasVehicleEverTriedLoading()) continue; // Selectively servicing stations, and not this one if (IsCargoInClass(type, CC_PASSENGERS)) { if (st->facilities == FACIL_TRUCK_STOP) continue; // passengers are never served by just a truck stop } else { if (st->facilities == FACIL_BUS_STOP) continue; // non-passengers are never served by just a bus stop } /* This station can be used, add it to the list */ used_stations.Include(st); } const uint no_stations = used_stations.Length(); // total number of stations added /* no stations around at all? */ if (no_stations == 0) return 0; /* Sort the stations by cargo rating in descending order. */ cargo_type_comparator = type; QSortT<Station *>(used_stations.Begin(), no_stations, CompareCargoRatings); /* From now we'll calculate with fractal cargo amounts. * First determine how much cargo we really have. */ amount *= ((*used_stations.Begin())->goods[type].rating) + 1; /* several stations around */ uint ratings_sum = 0; for (Station * const *st_iter = used_stations.Begin(); st_iter != used_stations.End(); ++st_iter) { Station *st = *st_iter; ratings_sum += st->goods[type].rating; } uint moved = 0; for (Station * const *st_iter = used_stations.End(); st_iter != used_stations.Begin(); --st_iter) { Station *st = *(st_iter - 1); if (st != *used_stations.Begin()) { /* Determine the amount the worst station gets, which is the last one from the list. * Then determine the amount the next worst gets by iterating backwards, until the * best station remains. We do it this way as the best should get a bonus, which in * this case is the rounding difference from the last time this calculation is done. * In reality that will mean the bonus will be pretty low. Nevertheless, the best * station should always get the most cargo regardless of rounding issues. */ uint cur_worst = amount * st->goods[type].rating / ratings_sum; /* And then send the cargo to the stations! */ moved += UpdateStationWaiting(st, type, cur_worst, source_type, source_id); amount -= cur_worst; ratings_sum -= st->goods[type].rating; } else { /* These two UpdateStationWaiting's can't be in the statement as then the order * of execution would be undefined and that could cause desyncs with callbacks. */ return moved + UpdateStationWaiting(st, type, amount, source_type, source_id); } } }
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever