Updated HTML docs

This commit is contained in:
Griatch 2021-10-26 21:41:11 +02:00
parent 66d0ad0bc9
commit 7900aad365
2073 changed files with 32986 additions and 41197 deletions

View file

@ -14,6 +14,8 @@
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "tex2jax_process|mathjax_process|math|output_area"}})</script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
@ -38,7 +40,7 @@
<div class="bodywrapper">
<div class="body" role="main">
<section id="gametime-tutorial">
<section class="tex2jax_ignore mathjax_ignore" id="gametime-tutorial">
<h1>Gametime Tutorial<a class="headerlink" href="#gametime-tutorial" title="Permalink to this headline"></a></h1>
<p>A lot of games use a separate time system we refer to as <em>game time</em>. This runs in parallel to what
we usually think of as <em>real time</em>. The game time might run at a different speed, use different
@ -62,16 +64,7 @@ calendar).</p>
<h3>Setting up game time for a standard calendar<a class="headerlink" href="#setting-up-game-time-for-a-standard-calendar" title="Permalink to this headline"></a></h3>
<p>All is done through the settings. Here are the settings you should use if you want a game time with
a standard calendar:</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<span class="c1"># The time factor dictates if the game world runs faster (timefactor&gt;1)</span>
<span class="c1"># or slower (timefactor&lt;1) than the real world.</span>
<span class="n">TIME_FACTOR</span> <span class="o">=</span> <span class="mf">2.0</span>
@ -82,7 +75,7 @@ a standard calendar:</p>
<span class="c1"># module.</span>
<span class="n">TIME_GAME_EPOCH</span> <span class="o">=</span> <span class="kc">None</span>
</pre></div>
</td></tr></table></div>
</div>
<p>By default, the game time runs twice as fast as the real time. You can set the time factor to be 1
(the game time would run exactly at the same speed than the real time) or lower (the game time will
be slower than the real time). Most games choose to have the game time spinning faster (you will
@ -92,26 +85,20 @@ real time, a minute in real time would be an hour in game time).</p>
indicate the time your game started. As indicated, an epoch of 0 would mean January 1st, 1970. If
you want to set your time in the future, you just need to find the starting point in seconds. There
are several ways to do this in Python, this method will show you how to do it in local time:</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span>
<span class="normal">6</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># We&#39;re looking for the number of seconds representing</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># We&#39;re looking for the number of seconds representing</span>
<span class="c1"># January 1st, 2020</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2020</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">mktime</span><span class="p">(</span><span class="n">start</span><span class="o">.</span><span class="n">timetuple</span><span class="p">())</span>
</pre></div>
</td></tr></table></div>
</div>
<p>This should return a huge number - the number of seconds since Jan 1 1970. Copy that directly into
your settings (editing <code class="docutils literal notranslate"><span class="pre">server/conf/settings.py</span></code>):</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<span class="n">TIME_GAME_EPOCH</span> <span class="o">=</span> <span class="mi">1577865600</span>
</pre></div>
</td></tr></table></div>
</div>
<p>Reload the game with <code class="docutils literal notranslate"><span class="pre">&#64;reload</span></code>, and then use the <code class="docutils literal notranslate"><span class="pre">&#64;time</span></code> command. You should see something like
this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+----------------------------+-------------------------------------+</span>
@ -140,7 +127,7 @@ time updated correctly… and going (by default) twice as fast as the real time.
time, and assuming a standard calendar (see below for the same feature with a custom calendar). For
instance, it can be used to have a specific message every (in-game) day at 6:00 AM showing how the
sun rises.</p>
<p>The function <code class="docutils literal notranslate"><span class="pre">schedule()</span></code> should be used here. It will create a <a class="reference internal" href="../Components/Scripts.html"><span class="doc">script</span></a> with some
<p>The function <code class="docutils literal notranslate"><span class="pre">schedule()</span></code> should be used here. It will create a <a class="reference internal" href="../Components/Scripts.html"><span class="doc std std-doc">script</span></a> with some
additional features to make sure the script is always executed when the game time matches the given
parameters.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">schedule</span></code> function takes the following arguments:</p>
@ -152,23 +139,9 @@ repeatedly.</p></li>
to schedule. If the parameter isnt given, it assumes the current time value of this specific unit.</p></li>
</ul>
<p>Here is a short example for making the sun rise every day:</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file ingame_time.py in mygame/world/</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in a file ingame_time.py in mygame/world/</span>
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">gametime</span>
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">gametime</span>
<span class="kn">from</span> <span class="nn">typeclasses.rooms</span> <span class="kn">import</span> <span class="n">Room</span>
<span class="k">def</span> <span class="nf">at_sunrise</span><span class="p">():</span>
@ -182,7 +155,7 @@ to schedule. If the parameter isnt given, it assumes the current time value
<span class="n">script</span> <span class="o">=</span> <span class="n">gametime</span><span class="o">.</span><span class="n">schedule</span><span class="p">(</span><span class="n">at_sunrise</span><span class="p">,</span> <span class="n">repeat</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">hour</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="nb">min</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">sec</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">script</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;at sunrise&quot;</span>
</pre></div>
</td></tr></table></div>
</div>
<p>If you want to test this function, you can easily do something like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@py</span> <span class="kn">from</span> <span class="nn">world</span> <span class="kn">import</span> <span class="n">ingame_time</span><span class="p">;</span> <span class="n">ingame_time</span><span class="o">.</span><span class="n">start_sunrise_event</span><span class="p">()</span>
</pre></div>
@ -204,9 +177,8 @@ For example, if you set a script to run every month on the 31st it will run in J
such day in February, April etc. Similarly, leap years may change the number of days in the year.</p>
</div></blockquote>
</section>
</section>
<section id="a-game-time-with-a-custom-calendar">
<h2>A game time with a custom calendar<a class="headerlink" href="#a-game-time-with-a-custom-calendar" title="Permalink to this headline"></a></h2>
<h3>A game time with a custom calendar<a class="headerlink" href="#a-game-time-with-a-custom-calendar" title="Permalink to this headline"></a></h3>
<p>Using a custom calendar to handle game time is sometimes needed if you want to place your game in a
fictional universe. For instance you may want to create the Shire calendar which Tolkien described
having 12 months, each which 30 days. That would give only 360 days per year (presumably hobbits
@ -215,6 +187,7 @@ creating a planet in a different solar system with, say, days 29 hours long and
days.</p>
<p>Evennia handles custom calendars through an optional <em>contrib</em> module, called <code class="docutils literal notranslate"><span class="pre">custom_gametime</span></code>.
Contrary to the normal <code class="docutils literal notranslate"><span class="pre">gametime</span></code> module described above it is not active by default.</p>
</section>
<section id="setting-up-the-custom-calendar">
<h3>Setting up the custom calendar<a class="headerlink" href="#setting-up-the-custom-calendar" title="Permalink to this headline"></a></h3>
<p>In our first example of the Shire calendar, used by hobbits in books by Tolkien, we dont really
@ -224,13 +197,7 @@ dictionary containing as keys the name of the units, and as value the number of
smallest unit for us) in this unit. Its keys must be picked among the following: “sec”, “min”,
“hour”, “day”, “week”, “month” and “year” but you dont have to include them all. Here is the
configuration for the Shire calendar:</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span>
<span class="normal">6</span>
<span class="normal">7</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<span class="n">TIME_UNITS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;sec&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s2">&quot;min&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
<span class="s2">&quot;hour&quot;</span><span class="p">:</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span><span class="p">,</span>
@ -238,29 +205,14 @@ configuration for the Shire calendar:</p>
<span class="s2">&quot;month&quot;</span><span class="p">:</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span><span class="p">,</span>
<span class="s2">&quot;year&quot;</span><span class="p">:</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span> <span class="o">*</span> <span class="mi">12</span> <span class="p">}</span>
</pre></div>
</td></tr></table></div>
</div>
<p>We give each unit we want as keys. Values represent the number of seconds in that unit. Hour is
set to 60 * 60 (that is, 3600 seconds per hour). Notice that we dont specify the week unit in this
configuration: instead, we skip from days to months directly.</p>
<p>In order for this setting to work properly, remember all units have to be multiples of the previous
units. If you create “day”, it needs to be multiple of hours, for instance.</p>
<p>So for our example, our settings may look like this:</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span>
<span class="normal">16</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in a file settings.py in mygame/server/conf</span>
<span class="c1"># Time factor</span>
<span class="n">TIME_FACTOR</span> <span class="o">=</span> <span class="mi">4</span>
@ -277,45 +229,19 @@ units. If you create “day”, it needs to be multiple of hours, for instance.
<span class="s2">&quot;year&quot;</span><span class="p">:</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span> <span class="o">*</span> <span class="mi">12</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</td></tr></table></div>
</div>
<p>Notice we have set a time epoch of 0. Using a custom calendar, we will come up with a nice display
of time on our own. In our case the game time starts at year 0, month 0, day 0, and at midnight.</p>
<p>Note that while we use “month”, “week” etc in the settings, your game may not use those terms in-
game, instead referring to them as “cycles”, “moons”, “sand falls” etc. This is just a matter of you
displaying them differently. See next section.</p>
</section>
<section id="a-command-to-display-the-current-game-time">
<h3>A command to display the current game time<a class="headerlink" href="#a-command-to-display-the-current-game-time" title="Permalink to this headline"></a></h3>
<h4>A command to display the current game time<a class="headerlink" href="#a-command-to-display-the-current-game-time" title="Permalink to this headline"></a></h4>
<p>As pointed out earlier, the <code class="docutils literal notranslate"><span class="pre">&#64;time</span></code> command is meant to be used with a standard calendar, not a
custom one. We can easily create a new command though. Well call it <code class="docutils literal notranslate"><span class="pre">time</span></code>, as is often the case
on other MU*. Heres an example of how we could write it (for the example, you can create a file
<code class="docutils literal notranslate"><span class="pre">showtime.py</span></code> in your <code class="docutils literal notranslate"><span class="pre">commands</span></code> directory and paste this code in it):</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span>
<span class="normal">16</span>
<span class="normal">17</span>
<span class="normal">18</span>
<span class="normal">19</span>
<span class="normal">20</span>
<span class="normal">21</span>
<span class="normal">22</span>
<span class="normal">23</span>
<span class="normal">24</span>
<span class="normal">25</span>
<span class="normal">26</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in a file mygame/commands/gametime.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in a file mygame/commands/gametime.py</span>
<span class="kn">from</span> <span class="nn">evennia.contrib</span> <span class="kn">import</span> <span class="n">custom_gametime</span>
@ -342,31 +268,11 @@ on other MU*. Heres an example of how we could write it (for the example, yo
<span class="n">time_string</span> <span class="o">+=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">It&#39;s </span><span class="si">{</span><span class="n">hour</span><span class="si">:</span><span class="s2">02</span><span class="si">}</span><span class="s2">:</span><span class="si">{</span><span class="n">mins</span><span class="si">:</span><span class="s2">02</span><span class="si">}</span><span class="s2">:</span><span class="si">{</span><span class="n">secs</span><span class="si">:</span><span class="s2">02</span><span class="si">}</span><span class="s2">.&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">time_string</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
<p>Dont forget to add it in your CharacterCmdSet to see this command:</p>
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span>
<span class="normal">16</span>
<span class="normal">17</span>
<span class="normal">18</span>
<span class="normal">19</span>
<span class="normal">20</span>
<span class="normal">21</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdset.py</span>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdset.py</span>
<span class="kn">from</span> <span class="nn">commands.gametime</span> <span class="kn">import</span> <span class="n">CmdTime</span> <span class="c1"># &lt;-- Add </span>
<span class="kn">from</span> <span class="nn">commands.gametime</span> <span class="kn">import</span> <span class="n">CmdTime</span> <span class="c1"># &lt;-- Add</span>
<span class="c1"># ...</span>
@ -383,27 +289,28 @@ on other MU*. Heres an example of how we could write it (for the example, yo
<span class="sd"> Populates the cmdset</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">at_cmdset_creation</span><span class="p">()</span>
<span class="c1"># ... </span>
<span class="c1"># ...</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">CmdTime</span><span class="p">())</span> <span class="c1"># &lt;- Add</span>
</pre></div>
</td></tr></table></div>
</div>
<p>Reload your game with the <code class="docutils literal notranslate"><span class="pre">&#64;reload</span></code> command. You should now see the <code class="docutils literal notranslate"><span class="pre">time</span></code> command. If you enter
it, you might see something like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">We</span> <span class="n">are</span> <span class="ow">in</span> <span class="n">year</span> <span class="mi">0</span><span class="p">,</span> <span class="n">day</span> <span class="mi">0</span><span class="p">,</span> <span class="n">month</span> <span class="mf">0.</span>
<span class="n">It</span><span class="s1">&#39;s 00:52:17.</span>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>We are in year 0, day 0, month 0.
It&#39;s 00:52:17.
</pre></div>
</div>
<p>You could display it a bit more prettily with names for months and perhaps even days, if you want.
And if “months” are called “moons” in your game, this is where youd add that.</p>
</section>
</section>
</section>
<section id="time-related-events-in-custom-gametime">
<h3>Time-related events in custom gametime<a class="headerlink" href="#time-related-events-in-custom-gametime" title="Permalink to this headline"></a></h3>
<h2>Time-related events in custom gametime<a class="headerlink" href="#time-related-events-in-custom-gametime" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">custom_gametime</span></code> module also has a way to schedule game-related events, taking into account
your game time (and your custom calendar). It can be used to have a specific message every day at
6:00 AM, to show the sun rises, for instance. The <code class="docutils literal notranslate"><span class="pre">custom_gametime.schedule</span></code> function works in the
same way as described for the default one above.</p>
</section>
</section>
</section>
@ -432,16 +339,16 @@ same way as described for the default one above.</p>
<li><a class="reference internal" href="#a-game-time-with-a-standard-calendar">A game time with a standard calendar</a><ul>
<li><a class="reference internal" href="#setting-up-game-time-for-a-standard-calendar">Setting up game time for a standard calendar</a></li>
<li><a class="reference internal" href="#time-related-events">Time-related events</a></li>
</ul>
</li>
<li><a class="reference internal" href="#a-game-time-with-a-custom-calendar">A game time with a custom calendar</a><ul>
<li><a class="reference internal" href="#setting-up-the-custom-calendar">Setting up the custom calendar</a></li>
<li><a class="reference internal" href="#a-game-time-with-a-custom-calendar">A game time with a custom calendar</a></li>
<li><a class="reference internal" href="#setting-up-the-custom-calendar">Setting up the custom calendar</a><ul>
<li><a class="reference internal" href="#a-command-to-display-the-current-game-time">A command to display the current game time</a></li>
<li><a class="reference internal" href="#time-related-events-in-custom-gametime">Time-related events in custom gametime</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#time-related-events-in-custom-gametime">Time-related events in custom gametime</a></li>
</ul>
</li>
</ul>
<div role="note" aria-label="source link">
@ -464,7 +371,7 @@ same way as described for the default one above.</p>
<h3>Versions</h3>
<ul>
<li><a href="Gametime-Tutorial.html">1.0-dev (develop branch)</a></li>
<li><a href="../../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
<li><a href="../../0.95/index.html">0.95 (v0.9.5 branch)</a></li>
</ul>
</div>