|
| 1 | +Program Overview |
| 2 | +================ |
| 3 | +High-level look at basic bot program. |
| 4 | + |
| 5 | +Environment Variables |
| 6 | +--------------------- |
| 7 | +Some variables that may alter the behavior of your bot program. |
| 8 | + |
| 9 | +- ``UNNATURAL_ROOT`` - path to the ``bin`` folder that contains the shared library. |
| 10 | +- ``UNNATURAL_CONNECT_LOBBY`` - id of Steam lobby to connect to. |
| 11 | +- ``UNNATURAL_CONNECT_ADDR`` - IP address or domain name to connect to. |
| 12 | +- ``UNNATURAL_CONNECT_PORT`` - port of the game server to connect to. |
| 13 | + |
| 14 | +Program Lifecycle |
| 15 | +----------------- |
| 16 | +At start, you are in full control of the program. |
| 17 | + |
| 18 | +Initialization |
| 19 | +^^^^^^^^^^^^^^ |
| 20 | + |
| 21 | +- You need to change current working directory to the ``bin`` directory in the game installation. |
| 22 | + Without it, the game will be unable to load maps and assets, even if it might load the shared library. |
| 23 | + |
| 24 | +.. warning:: |
| 25 | + Do *not* change current working directory once configured. |
| 26 | + |
| 27 | +- Next you load the shared library. |
| 28 | + |
| 29 | +.. tab-set:: |
| 30 | + |
| 31 | + .. tab-item:: Python |
| 32 | + :sync: python |
| 33 | + |
| 34 | + TODO |
| 35 | + |
| 36 | + .. tab-item:: C# |
| 37 | + :sync: csharp |
| 38 | + |
| 39 | + The library is automatically loaded when you first access the global ``Game`` object. |
| 40 | + This happens inside the ``Bot`` constructor. |
| 41 | + |
| 42 | +- Setup all your callbacks now. |
| 43 | + You may also set some parameters for the connection. |
| 44 | + |
| 45 | +Connect |
| 46 | +^^^^^^^ |
| 47 | +There are multiple ways to connect to a server. |
| 48 | +The usual approach is to first try reconnecting, in case the game has crashed previously. |
| 49 | +Second, you connect to an existing server using the parameters provided in the environment variables, if any. |
| 50 | +Third, you spin up your own server. |
| 51 | + |
| 52 | +Alternatively, you may implement your own logic to determine how to connect to a server. |
| 53 | + |
| 54 | +No matter the method, the game will now take control over the program. |
| 55 | +Your program is blocked until the network connection closes. |
| 56 | +All your further actions will happen inside callbacks only. |
| 57 | + |
| 58 | +Game Loop |
| 59 | +^^^^^^^^^ |
| 60 | +All your registered callbacks are now called, when appropriate. |
| 61 | +Notably, the ``Update`` callback is periodically called, no matter the game state. |
| 62 | +This is where you keep track of the state of the game, and perform any of your actions. |
| 63 | + |
| 64 | +.. warning:: |
| 65 | + The ``Update`` callback, and some other, may be called before the game has actually started (eg. in ``Session``), or when the map is not yet ``Loaded``. |
| 66 | + Be mindful of what operations are valid in these circumstances. |
| 67 | + |
| 68 | +You may prematurely close the connection with the ``Disconnect`` function. |
| 69 | +This will do a graceful closing of the connection, that is, you will get some additional callbacks called. |
| 70 | +After that the connect function will return. |
| 71 | + |
| 72 | +Finalization |
| 73 | +^^^^^^^^^^^^ |
| 74 | +When the connection function returns, the network connection has already been closed, and you take back control over the program. |
| 75 | +You may do any cleanup operations, for example you may save some statistics from the game. |
| 76 | +Ultimately, you should unload the shared library, and exit the program. |
| 77 | + |
| 78 | +It may be tempting to just loop and connect again to next server, however this is strongly discouraged. |
0 commit comments