Skip to content

Commit 156d496

Browse files
committed
docs: examples for accessing components
1 parent 4520e5b commit 156d496

File tree

3 files changed

+172
-6
lines changed

3 files changed

+172
-6
lines changed

sphinx/source/bots/setup.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ Steam Appid Txt
1313
---------------
1414

1515
.. important::
16-
Copy ``steam_appid.txt`` into the ``bin`` folder.
16+
Copy ``steam_appid.txt`` into ``Unnatural Worlds/bin`` folder.
1717

18-
The file ``steam_appid.txt`` tells Steam that this is developer copy of the game.
18+
You will find the ``steam_appid.txt`` in the uwapi repository.
19+
Copy it into ``bin`` folder, next to the game executable.
20+
21+
This file tells Steam that this is a developer copy of the game.
1922
It allows running multiple processes of the game simultaneously, and to start the programs directly from outside the Steam.
2023
This allows you to start and debug your bot program from inside your IDE.
2124
You may also start the game client, game server, built-in AI, or any other associated programs from your terminal.
22-
You will find the ``steam_appid.txt`` in the uwapi repository.
23-
Copy it into the ``bin`` folder, next to the game executable.
2425

2526
It is recommended to remove the ``steam_appid.txt`` when you are done with your AI/bot program.
2627
Presence of the file may cause corruption of some files when the game is updated.
@@ -29,7 +30,7 @@ Game Install Path
2930
-----------------
3031

3132
.. important::
32-
If you installed Unnatural World in non-default location, define environment variable ``UNNATURAL_ROOT`` pointing to the ``bin`` directory containing the library.
33+
If you have installed Unnatural World in non-default location, define environment variable ``UNNATURAL_ROOT`` pointing to the ``bin`` directory containing the library.
3334

3435
.. tab-set::
3536
:sync-group: platform

sphinx/source/concepts/callbacks.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Make sure to carefully decode them, as shown in the example below.
9898
}
9999
}
100100
101-
102101
Task Completed Callback
103102
-----------------------
104103
Some functions, such as pathfinding and clusters distances, need more time to compute the results.

sphinx/source/concepts/entities.rst

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,133 @@ These ids are assigned by the server, and client cannot predict the values.
2525
.. note::
2626
Some entities and/or components are synchronized only with the owner of the entity.
2727

28+
.. tab-set::
29+
:sync-group: language
30+
31+
.. tab-item:: Python
32+
:sync: python
33+
34+
.. code-block:: python
35+
36+
# get list of all entities:
37+
uw_world.entities().values()
38+
39+
# find entity by id:
40+
uw_world.entity(id) # raises KeyError if not found
41+
42+
.. tab-item:: C#
43+
:sync: csharp
44+
45+
.. code-block:: csharp
46+
47+
// get list of all entities:
48+
World.Entities().Values
49+
50+
// find entity by id:
51+
World.Entity(id) // throws KeyNotFoundException if not found
52+
53+
.. tab-item:: C++
54+
:sync: cpp
55+
56+
.. code-block:: cpp
57+
58+
// todo
59+
2860
Proto Component
2961
---------------
3062
Defines the prototype of the entity.
3163

3264
It is allowed to change from construction to unit, or from unit to another unit.
3365
It is forbidden to change eg. from unit to resource.
3466

67+
.. tab-set::
68+
:sync-group: language
69+
70+
.. tab-item:: Python
71+
:sync: python
72+
73+
.. code-block:: python
74+
75+
x = uw_world.entity(id)
76+
77+
# find type (unit, resource, construction, ...) of the entity:
78+
x.type()
79+
80+
# check if entity has Proto component:
81+
x.Proto is not None
82+
83+
# find id of the prototype of an entity:
84+
x.Proto.proto # assumes that the entity actually has Proto component
85+
86+
# access a value from the prototype:
87+
x.proto().data.get("dps", 0)
88+
89+
.. tab-item:: C#
90+
:sync: csharp
91+
92+
.. code-block:: csharp
93+
94+
Entity x = World.Entity(id);
95+
96+
// find type (unit, resource, construction, ...) of the entity:
97+
x.type
98+
99+
// check if entity has Proto component:
100+
x.Proto.HasValue
101+
102+
// find id of the prototype of an entity:
103+
x.Proto.Value.proto // assumes that the entity actually has Proto component
104+
105+
// access a value from the prototype:
106+
x.ProtoUnit.dps // assumes that the entity is a unit
107+
108+
.. tab-item:: C++
109+
:sync: cpp
110+
111+
.. code-block:: cpp
112+
113+
// todo
114+
35115
Owner Component
36116
---------------
37117
Defines which force owns this entity.
38118

39119
Immutable.
40120

121+
.. tab-set::
122+
:sync-group: language
123+
124+
.. tab-item:: Python
125+
:sync: python
126+
127+
.. code-block:: python
128+
129+
# id of the force that owns this entity:
130+
x.Owner.force
131+
132+
# check if entity is own or enemy:
133+
x.own()
134+
x.enemy()
135+
136+
.. tab-item:: C#
137+
:sync: csharp
138+
139+
.. code-block:: csharp
140+
141+
// id of the force that owns this entity:
142+
x.Owner.Value.force
143+
144+
// check if entity is own or enemy:
145+
x.Own()
146+
x.Enemy()
147+
148+
.. tab-item:: C++
149+
:sync: cpp
150+
151+
.. code-block:: cpp
152+
153+
// todo
154+
41155
Controller Component
42156
--------------------
43157
In case that multiple players belong to the same force, the last player to give any orders to this entity will become the controller of the entity.
@@ -53,6 +167,32 @@ In case the entity has large radius, this component defines the center tile.
53167
The yaw defines the orientation (a rotation along the local vertical axis) of this entity on the tile.
54168
The actual facing of 0 degrees yaw is different for each tile.
55169

170+
.. tab-set::
171+
:sync-group: language
172+
173+
.. tab-item:: Python
174+
:sync: python
175+
176+
.. code-block:: python
177+
178+
# shortcut to get tile index:
179+
x.pos()
180+
181+
.. tab-item:: C#
182+
:sync: csharp
183+
184+
.. code-block:: csharp
185+
186+
// shortcut to get tile index:
187+
x.Pos
188+
189+
.. tab-item:: C++
190+
:sync: cpp
191+
192+
.. code-block:: cpp
193+
194+
// todo
195+
56196
Unit Component
57197
--------------
58198
Contains additional state for a unit (or building).
@@ -63,6 +203,32 @@ Contains additional state for a unit (or building).
63203
- ``Stalling`` - the unit's recipe cannot be executed, usually because a limit for the outputs has been reached.
64204
- ``Damaged`` - the unit has less than half life.
65205

206+
.. tab-set::
207+
:sync-group: language
208+
209+
.. tab-item:: Python
210+
:sync: python
211+
212+
.. code-block:: python
213+
214+
# check if unit is Processing:
215+
(x.Unit.state & UwUnitStateFlags.Processing) != 0
216+
217+
.. tab-item:: C#
218+
:sync: csharp
219+
220+
.. code-block:: csharp
221+
222+
// check if unit is Processing:
223+
(x.Unit.Value.state & UwUnitStateFlags::Processing) != 0
224+
225+
.. tab-item:: C++
226+
:sync: cpp
227+
228+
.. code-block:: cpp
229+
230+
// todo
231+
66232
Life Component
67233
--------------
68234
Amount of life of the unit (or building).

0 commit comments

Comments
 (0)