Skip to main content

Interact with OpenRCT2 from python!

Project description

pyrct2

Python client for OpenRCT2. Launch headless games, read state, execute actions, all in Python!

Connects to the openrct2-bridge plugin over TCP. Every game action, state query, and enum is auto-generated from OpenRCT2 C++ source by openrct2-codegen.

Install

pip install pyrct2
pyrct2 setup        # finds OpenRCT2, installs the bridge plugin

Quick start

from pyrct2.client import RCT2
from pyrct2.scenarios import Scenario

# Launch a built-in scenario
with RCT2.launch(Scenario.CRAZY_CASTLE) as game:
    print(f"{game.park.name}: rating {game.park.rating}, cash ${game.park.finance.cash}")

# Or load a scenario/save by path
with RCT2.launch("/path/to/my_park.park") as game:
    print(game.park.name)

# Or connect to an already-running instance
with RCT2.connect() as game:
    print(game.park.name)

Building a park

from pyrct2.client import RCT2
from pyrct2.enums import Direction, StaffType
from pyrct2.objects import RideObjects, FootpathAdditions, FootpathSurfaces, FootpathRailings
from pyrct2.scenarios import Scenario
from pyrct2.world import Tile

with RCT2.launch(Scenario.TEST_PARK, headless=False) as game:
    game.park.cheats.build_in_pause_mode()
    game.park.finance.set_entrance_fee(10)

    # -- Match the scenario's path style --
    game.paths.set_default_surface(FootpathSurfaces.TARMAC)

    # -- Place a flat ride south of the main path --
    ride = game.rides.place_flat_ride(
        obj=RideObjects.gentle.MERRY_GO_ROUND,
        tile=Tile(44, 34),
        entrance=Tile(44, 32),
        exit=Tile(46, 34),
        direction=Direction.NORTH,
    )
    ride.set_price(30)
    ride.open()

    # -- Place some stalls along the main path --
    burger = game.rides.place_stall(RideObjects.stall.BURGER_BAR, Tile(42, 29))
    burger.open()
    drink = game.rides.place_stall(RideObjects.stall.DRINKS_STALL, Tile(46, 29))
    drink.open()

    # -- Paths --
    game.paths.place_line(Tile(44, 30), Tile(44, 31))           # branch to ride
    game.paths.place(Tile(44, 31), queue=True)                   # queue to entrance
    game.paths.place_line(Tile(46, 30), Tile(46, 34))            # exit path back

    # path additions
    game.paths.place_addition(Tile(43, 30), FootpathAdditions.LAMP1)
    game.paths.place_addition(Tile(45, 30), FootpathAdditions.BENCH1)
    game.paths.place_addition(Tile(47, 30), FootpathAdditions.LITTER1)

    # verify connectivity from entrance to ride
    assert game.paths.is_connected(Tile(48, 30), Tile(44, 31))

    # -- Staff --
    handyman = game.park.staff.hire(StaffType.HANDYMAN)
    handyman.set_patrol_area(Tile(40, 28), Tile(50, 36))
    game.park.staff.hire(StaffType.MECHANIC)

    # -- Open the park and let it run --
    game.park.open()
    game.park.cheats.generate_guests(50)
    game.advance_ticks(100)

    # -- Read state --
    print(f"Rating: {game.park.rating}, Guests: {game.park.guests.count()}")
    print(f"Cash: {game.state.park().cash}")
    for r in game.state.rides():
        print(f"  {r.name}: {r.status}, excitement {r.excitement}")

Raw API

All 82 game actions and state queries are available directly if you need something the high-level API doesn't wrap yet:

# Actions (raw ints, less friendly)
game.actions.staff_hire_new(auto_position=True, staff_type=0, costume_index=0, staff_orders=0)
game.actions.ride_set_price(ride=0, price=50, is_primary_price=True)

# State queries (full Pydantic models)
game.state.date()                          # GameDate — ticks, day, month, year
game.state.scenario()                      # Scenario — objectives, completion status
game.state.climate()                       # Climate — current/future weather
game.state.park_messages()                 # list[ParkMessage] — guest complaints, awards
game.state.park_awards()                   # list[Award]
game.state.park_research()                 # Research — invented/uninvented items
game.state.guests()                        # list[Guest] — every guest in the park

Requirements

  • Python 3.11+
  • OpenRCT2 installed with RCT2 game data

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrct2-0.9.1.tar.gz (187.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrct2-0.9.1-py3-none-any.whl (96.8 kB view details)

Uploaded Python 3

File details

Details for the file pyrct2-0.9.1.tar.gz.

File metadata

  • Download URL: pyrct2-0.9.1.tar.gz
  • Upload date:
  • Size: 187.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrct2-0.9.1.tar.gz
Algorithm Hash digest
SHA256 2482ef9a34d554a0053382fda9adf78e454e7053cd825f1fb8680c486c543fdd
MD5 b9f9b8f3876ee0eee8dab6b7730d82d2
BLAKE2b-256 437e7921e64cd9ead6ec213a1c3a72455295db99d82fe0b097fa06753ad9c3e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrct2-0.9.1.tar.gz:

Publisher: publish.yml on MaukWM/pyrct2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrct2-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: pyrct2-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrct2-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4da3e49b8cd8948f4f954c9ed869356b5c2d554375678ab1a36beb45d4c9338b
MD5 290fabd555678e453070f94b88068530
BLAKE2b-256 537e9b4e0a0e73c0dba7bf7c876131cb925b839982e0c6c312875133e68a7422

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrct2-0.9.1-py3-none-any.whl:

Publisher: publish.yml on MaukWM/pyrct2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page