From 9f93af2558386c22c5e43a03ef710a750ef52023 Mon Sep 17 00:00:00 2001
From: edvin <edvbe696@student.liu.se>
Date: Wed, 5 Aug 2020 12:29:26 +0200
Subject: [PATCH] Added Library and Coordinator to the Navigation. Also moved
 text from ExtendAPI.md to docs/contributiong.rst

---
 docs/_templates/layout.html |  6 ++++++
 docs/constants.rst          |  3 +++
 docs/contributing.rst       | 23 +++++++++++++++++++++++
 docs/coordinates.rst        |  1 +
 docs/gettingstarted.rst     |  1 +
 docs/helpers.rst            |  2 ++
 docs/idabot.rst             |  1 +
 docs/idareplayobserver.rst  |  3 ++-
 docs/index.rst              |  4 +++-
 docs/replays.rst            |  6 +++++-
 docs/replayunit.rst         |  9 ++++-----
 docs/types.rst              |  1 +
 docs/unit.rst               |  2 ++
 13 files changed, 54 insertions(+), 8 deletions(-)
 create mode 100644 docs/_templates/layout.html

diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html
new file mode 100644
index 0000000..eca68a0
--- /dev/null
+++ b/docs/_templates/layout.html
@@ -0,0 +1,6 @@
+{% extends "!layout.html" %}
+
+  {% block menu %}
+    {{ super() }}
+    <a href="py-modindex.html">modindex</a>
+  {% endblock %}
\ No newline at end of file
diff --git a/docs/constants.rst b/docs/constants.rst
index f75b853..a4e6275 100644
--- a/docs/constants.rst
+++ b/docs/constants.rst
@@ -46,3 +46,6 @@ Race
    The following attribute means a randomly selected race from the three above:
 
    .. attribute:: Race.Random
+
+
+.. toctree::
\ No newline at end of file
diff --git a/docs/contributing.rst b/docs/contributing.rst
index 853063d..3aa8a82 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -38,6 +38,27 @@ The source code for all additional dependencies (including pybind11) are registe
 
 The system is built using cmake, see the file `CMakeLists.txt <https://gitlab.liu.se/starcraft-ai-course/pycommandcenter/blob/master/CMakeLists.txt>`_ in the project root.
 
+If a function already exist but you can't use it in python, check and see if it's exist in the library files (pybind).
+
+#. Create a declaration of your function in the header file.
+#. Create a definition of your function in the source file.
+#. Depending on which object you decided to extend, you should also add this function to the library file. The library is the pybind, making it possible to use your function in python.
+#. Update the documentation. There are instructions on how you build and test the documentation.
+
+Example:
+We want to add function to unit, returning a bool depending on if it's holding a mineral. We have discovered a function in the SC2 API containing this information (sc2_client.ccp). This is a helper function, it doesn't belong to any object.
+
+#. In unit.h: bool isCarryingMinerals() const;
+#. In unit.cpp: bool Unit::isCarryingMinerals() const { return sc2::IsCarryingMinerals(\*m_unit); }
+#. We can access m_unit in the unit file and with sc2::Function() we can access any function in the blizzard API that doesn't belong to any object. The same goes for any object, for example sc2::Point3D makes us able to access the Point3D object.
+#. In lib_unit.cpp: .def_property_readonly("is_carrying_minerals", &Unit::isCarryingMinerals)
+#. In the folder named docs we update the documentation. In this case, we update the file unit.rst.
+
+Common problems:
+
+#. The return in python is a memory address: Make sure that it returns a correct type.
+#. The compiler complains about files I have not even touched: Make sure that the startUp is library and you have release x64. If you just added a new function in pybind, check it.
+#. The bot crashes whit a exit code -1073741819 (0xC0000005): Make sure that you dont read null values.
 
 Document the new features / changes you have made
 -------------------------------------------------
@@ -61,3 +82,5 @@ Read the comments on your merge request and make the necessary changes
 In this step someone will review your changes and make comments. These comments might ask you to make changes to the code or documentation. These changes must be done before the merge request is accepted. Therefore it is important to make merge requests several days before eventual deadlines.
 
 Once the merge request has been accepted the code is now part of PyCommandCenter. Congratulations and thank you for your contribution to the project!
+
+.. toctree::
\ No newline at end of file
diff --git a/docs/coordinates.rst b/docs/coordinates.rst
index 294d8ee..fb74871 100644
--- a/docs/coordinates.rst
+++ b/docs/coordinates.rst
@@ -81,3 +81,4 @@ below:
 
    print(p1.distance(p2))  # prints: 2.8284...
 
+.. toctree::
\ No newline at end of file
diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst
index 037793e..c68a473 100644
--- a/docs/gettingstarted.rst
+++ b/docs/gettingstarted.rst
@@ -150,3 +150,4 @@ to:
 
 where ``SomeOtherBot`` is a bot defined in the same way as ``MyAgent``.
 
+.. toctree::
\ No newline at end of file
diff --git a/docs/helpers.rst b/docs/helpers.rst
index 15cc665..68802b4 100644
--- a/docs/helpers.rst
+++ b/docs/helpers.rst
@@ -188,3 +188,5 @@ BuildingPlacer
    If you want to place a town hall, take a look at attribute `depot_location` of :class:`library.BaseLocation`.
 
    If you want to place a refinery, take a look at attribute `geysers` of :class:`library.BaseLocation` and the method build_target of :class:`library.Unit`.
+
+.. toctree::
\ No newline at end of file
diff --git a/docs/idabot.rst b/docs/idabot.rst
index ad95df7..6a4c6be 100644
--- a/docs/idabot.rst
+++ b/docs/idabot.rst
@@ -191,3 +191,4 @@ The debug-methods are a great tool for speeding up the process.
 
       Set the amount (Float) of shield to the unit
 
+.. toctree::
\ No newline at end of file
diff --git a/docs/idareplayobserver.rst b/docs/idareplayobserver.rst
index 8d34f27..d2379ae 100644
--- a/docs/idareplayobserver.rst
+++ b/docs/idareplayobserver.rst
@@ -27,7 +27,7 @@ IDAReplayObserver
 
    .. method:: IDAReplayObserver.on_unit_created(self)
 
-      This method is called when the an unit is created, that includes when an unit leaves a refinery.
+      This method is called when the an unit is created, that includes when an unit leaves a refinery. This only works if replay perspective is not set to 0.
 
    .. method:: IDAReplayObserver.on_unit_destroyed(self)
 
@@ -45,3 +45,4 @@ IDAReplayObserver
 
 
 
+.. toctree::
\ No newline at end of file
diff --git a/docs/index.rst b/docs/index.rst
index 73c52df..da345da 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -22,6 +22,8 @@ Table of contents
    :maxdepth: 3
 
    gettingstarted
+   Library<_autosummary/library>
+   Coordinator<_autosummary/library.Coordinator>
    helpers
    idabot
    unit
@@ -31,7 +33,7 @@ Table of contents
    replays
    idareplayobserver
    replayunit
-   
+
 .. autosummary::
    :toctree: _autosummary
    :hidden:
diff --git a/docs/replays.rst b/docs/replays.rst
index 0ca0179..af33078 100644
--- a/docs/replays.rst
+++ b/docs/replays.rst
@@ -1,3 +1,5 @@
+.. _replays:
+
 Replays
 =======
 This page will describe two different techniques for handling replays. The
@@ -101,4 +103,6 @@ that no action can be preform just observations.
 
 
     if __name__ == "__main__":
-        main()
\ No newline at end of file
+        main()
+
+.. toctree::
\ No newline at end of file
diff --git a/docs/replayunit.rst b/docs/replayunit.rst
index 57dd6de..7d27a67 100644
--- a/docs/replayunit.rst
+++ b/docs/replayunit.rst
@@ -64,13 +64,12 @@ ReplayUnit
    .. autoattribute:: tile_position
    .. autoattribute:: unit_type
 
-      Returns the id of the unit_type
-
-   .. autoattribute:: unit_type_name
-
-      Returns the name of the unit_type
+      Returns the :class:`library.UnitType` of the unit
 
    .. autoattribute:: weapon_cooldown
    .. autoattribute:: is_carrying_minerals
 
       Returns if this unit is currently holding minerals
+
+
+.. toctree::
\ No newline at end of file
diff --git a/docs/types.rst b/docs/types.rst
index dd9986f..1227e4b 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -53,3 +53,4 @@ EffectID is for things like ravager bile, or fungal or even a scan.
    :members:
    :undoc-members:
 
+.. toctree::
\ No newline at end of file
diff --git a/docs/unit.rst b/docs/unit.rst
index 16aa1d4..55a65d7 100644
--- a/docs/unit.rst
+++ b/docs/unit.rst
@@ -133,3 +133,5 @@ Unit
    .. automethod:: stop_dance
 
       Stop and dance
+
+.. toctree::
\ No newline at end of file
-- 
GitLab