You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sphinx/source/bots/programOverview.rst
+37-14Lines changed: 37 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,6 @@ Program Overview
2
2
================
3
3
High-level look at basic bot program.
4
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
5
Program Lifecycle
15
6
-----------------
16
7
At start, you are in full control of the program.
@@ -24,7 +15,7 @@ Initialization
24
15
.. warning::
25
16
Do *not* change current working directory once configured.
26
17
27
-
- Next you load the shared library.
18
+
- Next, you load the shared library.
28
19
29
20
.. tab-set::
30
21
:sync-group: language
@@ -45,7 +36,7 @@ Initialization
45
36
46
37
Connect
47
38
^^^^^^^
48
-
There are multiple ways to connect to a server.
39
+
There are multiple ways to connect to a game server.
49
40
The usual approach is to first try reconnecting, in case the game has crashed previously.
50
41
Second, you connect to an existing server using the parameters provided in the environment variables, if any.
51
42
Third, you spin up your own server.
@@ -54,7 +45,7 @@ Alternatively, you may implement your own logic to determine how to connect to a
54
45
55
46
No matter the method, the game will now take control over the program.
56
47
Your program is blocked until the network connection closes.
57
-
All your further actions will happen inside callbacks only.
48
+
*All your further actions will happen inside callbacks only.*
58
49
59
50
Game Loop
60
51
^^^^^^^^^
@@ -63,7 +54,7 @@ Notably, the ``Update`` callback is periodically called, no matter the game stat
63
54
This is where you keep track of the state of the game, and perform any of your actions.
64
55
65
56
.. warning::
66
-
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``.
57
+
The ``Update`` callback, and some others, may be called before the game has actually started (eg. in ``Session``), or when the map is not yet ``Loaded``.
67
58
Be mindful of what operations are valid in these circumstances.
68
59
69
60
You may prematurely close the connection with the ``Disconnect`` function.
@@ -76,4 +67,36 @@ When the connection function returns, the network connection has already been cl
76
67
You may do any cleanup operations, for example you may save some statistics from the game.
77
68
Ultimately, you should unload the shared library, and exit the program.
78
69
79
-
It may be tempting to just loop and connect again to next server, however this is strongly discouraged.
70
+
It may be tempting to just loop over and connect to next server, however this is strongly discouraged.
71
+
72
+
Network
73
+
-------
74
+
The game is designed for multiplayer, and always plays over network, even in single-player scenarios.
75
+
76
+
Any actions that you do in your program are first send to the game server, then processed, and then the results are send back to your client.
77
+
78
+
Example: you call a function to place a construction.
79
+
After that you look through all the entities and the construction is not there, as expected.
80
+
You will not know the id of the entity either.
81
+
The construction will appear only after the game server has processed the request.
82
+
It is recommended to wait several ticks between these kinds of actions, to avoid placing same construction multiple times in different places.
83
+
84
+
.. note::
85
+
Test your program over a real network, not just localhost.
86
+
87
+
Client-only State
88
+
^^^^^^^^^^^^^^^^^
89
+
Some state is stored on client only, notably:
90
+
91
+
- Units orders
92
+
- Pathfinding
93
+
- Logistics planning
94
+
95
+
Environment Variables
96
+
---------------------
97
+
Some variables that may alter the behavior of your bot program.
98
+
99
+
- ``UNNATURAL_ROOT`` - path to the ``bin`` folder that contains the shared library.
100
+
- ``UNNATURAL_CONNECT_LOBBY`` - id of Steam lobby to connect to.
101
+
- ``UNNATURAL_CONNECT_ADDR`` - IP address or domain name to connect to.
102
+
- ``UNNATURAL_CONNECT_PORT`` - port of the game server to connect to.
0 commit comments