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
diff --git a/src/person.cpp b/src/person.cpp --- a/src/person.cpp +++ b/src/person.cpp @@ -784,15 +784,13 @@ void Person::DeActivate(AnimateResult ar } /** - * Update the animation of the guest. + * Update the animation of a person. * @param delay Amount of milliseconds since the last update. - * @return If \c false, de-activate the person. - * @todo Merge things common to all persons to Person::OnAnimate. + * @return Whether to keep the person active or how to deactivate him/her. + * @return Result code of the visit. */ -AnimateResult Guest::OnAnimate(int delay) +AnimateResult Person::OnAnimate(int delay) { - if (this->activity == GA_ON_RIDE) return OAR_OK; // Guest is not animated while on ride. - this->frame_time -= delay; if (this->frame_time > 0) return OAR_OK; @@ -885,16 +883,8 @@ AnimateResult Guest::OnAnimate(int delay assert(this->x_pos >= 0 && this->x_pos < 256); assert(this->y_pos >= 0 && this->y_pos < 256); - /* If the guest ended up off-world, quit. */ - if (this->x_vox < 0 || this->x_vox >= _world.GetXSize() * 256 || - this->y_vox < 0 || this->y_vox >= _world.GetYSize() * 256) { - return OAR_DEACTIVATE; - } - - /* If the guest arrived at the 'go home' tile while going home, quit. */ - if (this->activity == GA_GO_HOME && this->x_vox == _guests.start_voxel.x && this->y_vox == _guests.start_voxel.y) { - return OAR_DEACTIVATE; - } + AnimateResult ar = this->EdgeOfWorldOnAnimate(); + if (ar != OAR_CONTINUE) return ar; /* Handle raising of z position. */ if (this->z_pos > 128) { @@ -909,22 +899,10 @@ AnimateResult Guest::OnAnimate(int delay if (instance >= SRI_FULL_RIDES) { assert(exit_edge != INVALID_EDGE); RideInstance *ri = _rides_manager.GetRideInstance(instance); - if (ri->CanBeVisited(this->x_vox, this->y_vox, this->z_vox, exit_edge) && this->SelectItem(ri) != ITP_NOTHING) { - /* All lights are green, let's try to enter the ride. */ - this->activity = GA_ON_RIDE; - this->ride = ri; - RideEntryResult rer = ri->EnterRide(this->id, exit_edge); - if (rer != RER_REFUSED) { - this->BuyItem(ri); - /* Either the guest is already back at a path or he will be (through ExitRide). */ - return OAR_OK; - } + AnimateResult ar = this->VisitRideOnAnimate(ri, exit_edge); + if (ar != OAR_CONTINUE) return ar; - /* Could not enter, find another ride. */ - this->ride = nullptr; - this->activity = GA_WANDER; - } - /* Ride is closed, fall-through to reversing movement. */ + /* Ride is could not be visited, fall-through to reversing movement. */ } else if (HasValidPath(v)) { this->AddSelf(v); @@ -978,13 +956,6 @@ RideVisitDesire Person::WantToVisit(cons } /** - * @fn AnimateResult Person::OnAnimate(int delay) - * Update the animation of the person. - * @param delay Amount of milliseconds since the last update. - * @return Whether to keep the person active or how to deactivate him/her. - */ - -/** * @fn bool Person::DailyUpdate() * Daily ponderings of a person. * @return If \c false, de-activate the person. @@ -1038,6 +1009,58 @@ void Guest::DeActivate(AnimateResult ar) this->Person::DeActivate(ar); } +AnimateResult Guest::OnAnimate(int delay) +{ + if (this->activity == GA_ON_RIDE) return OAR_OK; // Guest is not animated while on ride. + return this->Person::OnAnimate(delay); +} + +/** + * Handle the case of a guest reaching the end of the game world. + * @return Result code of the visit. + */ +AnimateResult Guest::EdgeOfWorldOnAnimate() +{ + /* If the guest ended up off-world, quit. */ + if (this->x_vox < 0 || this->x_vox >= _world.GetXSize() * 256 || + this->y_vox < 0 || this->y_vox >= _world.GetYSize() * 256) { + return OAR_DEACTIVATE; + } + + /* If the guest arrived at the 'go home' tile while going home, quit. */ + if (this->activity == GA_GO_HOME && this->x_vox == _guests.start_voxel.x && this->y_vox == _guests.start_voxel.y) { + return OAR_DEACTIVATE; + } + + return OAR_CONTINUE; +} + +/** + * Handle guest ride visiting. + * @param ri Ride that can be visited. + * @param exit_edge Exit edge being examined. + * @return Result code of the visit. + */ +AnimateResult Guest::VisitRideOnAnimate(RideInstance *ri, TileEdge exit_edge) +{ + if (ri->CanBeVisited(this->x_vox, this->y_vox, this->z_vox, exit_edge) && this->SelectItem(ri) != ITP_NOTHING) { + /* All lights are green, let's try to enter the ride. */ + this->activity = GA_ON_RIDE; + this->ride = ri; + RideEntryResult rer = ri->EnterRide(this->id, exit_edge); + if (rer != RER_REFUSED) { + this->BuyItem(ri); + /* Either the guest is already back at a path or he will be (through ExitRide). */ + return OAR_OK; + } + + /* Could not enter, find another ride. */ + this->ride = nullptr; + this->activity = GA_WANDER; + } + return OAR_CONTINUE; +} + /** * Update the happiness of the guest. * @param amount Amount of change. diff --git a/src/person.h b/src/person.h --- a/src/person.h +++ b/src/person.h @@ -73,6 +73,7 @@ struct WalkInformation { /** Exit codes of the Person::OnAnimate call. */ enum AnimateResult { + OAR_CONTINUE, ///< No result yet, continue the routine. OAR_OK, ///< All OK, keep running. OAR_REMOVE, ///< Remove person from the person-list, and de-activate. OAR_DEACTIVATE, ///< Person is already removed from the person-list, only de-activate. @@ -99,7 +100,7 @@ public: const ImageData *GetSprite(const SpriteStorage *sprites, ViewOrientation orient, const Recolouring **recolour) const override; - virtual AnimateResult OnAnimate(int delay) = 0; + virtual AnimateResult OnAnimate(int delay); virtual bool DailyUpdate() = 0; virtual void Activate(const Point16 &start, PersonType person_type); @@ -138,6 +139,8 @@ protected: void StartAnimation(const WalkInformation *walk); virtual RideVisitDesire WantToVisit(const RideInstance *ri); + virtual AnimateResult EdgeOfWorldOnAnimate() = 0; + virtual AnimateResult VisitRideOnAnimate(RideInstance *ri, TileEdge exit_edge) = 0; }; /** Activities of the guest. */ @@ -193,6 +196,8 @@ protected: RideVisitDesire ComputeExitDesire(TileEdge current_edge, int x, int y, int z, TileEdge exit_edge, bool *seen_wanted_ride); uint8 GetExitDirections(const Voxel *v, TileEdge start_edge, bool *seen_wanted_ride, bool *queue_mode); RideVisitDesire WantToVisit(const RideInstance *ri) override; + AnimateResult EdgeOfWorldOnAnimate() override; + AnimateResult VisitRideOnAnimate(RideInstance *ri, TileEdge exit_edge) override; RideVisitDesire NeedForItem(enum ItemType it, bool use_random); void AddItem(ItemType it);
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever