Updated HTML docs

This commit is contained in:
Griatch 2020-06-16 22:49:43 +02:00
parent f505351730
commit a551188691
1002 changed files with 30387 additions and 9820 deletions

View file

@ -7,11 +7,13 @@
<title>Gametime Tutorial &#8212; Evennia 1.0-dev documentation</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></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" />
@ -25,7 +27,10 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> &#187;</li>
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> &#187;</li>
<li class="nav-item nav-item-last"><a href="#">Gametime Tutorial</a></li>
</ul>
</div>
@ -36,18 +41,28 @@
<div class="section" 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 names for its time units or might even use a completely custom calendar. You dont need to rely on a game time system at all. But if you do, Evennia offers basic tools to handle these various situations. This tutorial will walk you through these features.</p>
<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
names for its time units or might even use a completely custom calendar. You dont need to rely on a
game time system at all. But if you do, Evennia offers basic tools to handle these various
situations. This tutorial will walk you through these features.</p>
<div class="section" id="a-game-time-with-a-standard-calendar">
<h2>A game time with a standard calendar<a class="headerlink" href="#a-game-time-with-a-standard-calendar" title="Permalink to this headline"></a></h2>
<p>Many games let their in-game time run faster or slower than real time, but still use our normal real-world calendar. This is common both for games set in present day as well as for games in historical or futuristic settings. Using a standard calendar has some advantages:</p>
<p>Many games let their in-game time run faster or slower than real time, but still use our normal
real-world calendar. This is common both for games set in present day as well as for games in
historical or futuristic settings. Using a standard calendar has some advantages:</p>
<ul class="simple">
<li><p>Handling repetitive actions is much easier, since converting from the real time experience to the in-game perceived one is easy.</p></li>
<li><p>The intricacies of the real world calendar, with leap years and months of different length etc are automatically handled by the system.</p></li>
<li><p>Handling repetitive actions is much easier, since converting from the real time experience to the
in-game perceived one is easy.</p></li>
<li><p>The intricacies of the real world calendar, with leap years and months of different length etc are
automatically handled by the system.</p></li>
</ul>
<p>Evennias game time features assume a standard calendar (see the relevant section below for a custom calendar).</p>
<p>Evennias game time features assume a standard calendar (see the relevant section below for a custom
calendar).</p>
<div class="section" id="setting-up-game-time-for-a-standard-calendar">
<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>
<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> 1
2
3
@ -69,8 +84,15 @@
<span class="n">TIME_GAME_EPOCH</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div>
</td></tr></table></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 find some games that have a time factor of 60, meaning the game time runs sixty times as fast as the real time, a minute in real time would be an hour in game time).</p>
<p>The epoch is a slightly more complex setting. It should contain a number of seconds that would 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>
<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
find some games that have a time factor of 60, meaning the game time runs sixty times as fast as the
real time, a minute in real time would be an hour in game time).</p>
<p>The epoch is a slightly more complex setting. It should contain a number of seconds that would
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>1
2
3
@ -84,13 +106,15 @@
<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>
<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>
<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>1
2</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>
<span class="n">TIME_GAME_EPOCH</span> <span class="o">=</span> <span class="mi">1577865600</span>
</pre></div>
</td></tr></table></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>
<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>
<span class="o">|</span> <span class="n">Server</span> <span class="n">time</span> <span class="o">|</span> <span class="o">|</span>
<span class="o">+~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+</span>
@ -107,17 +131,26 @@
<span class="o">+----------------------------+-------------------------------------+</span>
</pre></div>
</div>
<p>The line that is most relevant here is the game time epoch. You see it shown at 2020-01-01. From this point forward, the game time keeps increasing. If you keep typing <code class="docutils literal notranslate"><span class="pre">&#64;time</span></code>, youll see the game time updated correctly… and going (by default) twice as fast as the real time.</p>
<p>The line that is most relevant here is the game time epoch. You see it shown at 2020-01-01. From
this point forward, the game time keeps increasing. If you keep typing <code class="docutils literal notranslate"><span class="pre">&#64;time</span></code>, youll see the game
time updated correctly… and going (by default) twice as fast as the real time.</p>
</div>
<div class="section" id="time-related-events">
<h3>Time-related events<a class="headerlink" href="#time-related-events" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">gametime</span></code> utility also has a way to schedule game-related events, taking into account your game 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="Scripts.html"><span class="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">gametime</span></code> utility also has a way to schedule game-related events, taking into account your game
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="Scripts.html"><span class="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>
<ul class="simple">
<li><p>The <em>callback</em>, a function to be called when time is up.</p></li>
<li><p>The keyword <code class="docutils literal notranslate"><span class="pre">repeat</span></code> (<code class="docutils literal notranslate"><span class="pre">False</span></code> by default) to indicate whether this function should be called repeatedly.</p></li>
<li><p>Additional keyword arguments <code class="docutils literal notranslate"><span class="pre">sec</span></code>, <code class="docutils literal notranslate"><span class="pre">min</span></code>, <code class="docutils literal notranslate"><span class="pre">hour</span></code>, <code class="docutils literal notranslate"><span class="pre">day</span></code>, <code class="docutils literal notranslate"><span class="pre">month</span></code> and <code class="docutils literal notranslate"><span class="pre">year</span></code> to describe the time to schedule. If the parameter isnt given, it assumes the current time value of this specific unit.</p></li>
<li><p>The keyword <code class="docutils literal notranslate"><span class="pre">repeat</span></code> (<code class="docutils literal notranslate"><span class="pre">False</span></code> by default) to indicate whether this function should be called
repeatedly.</p></li>
<li><p>Additional keyword arguments <code class="docutils literal notranslate"><span class="pre">sec</span></code>, <code class="docutils literal notranslate"><span class="pre">min</span></code>, <code class="docutils literal notranslate"><span class="pre">hour</span></code>, <code class="docutils literal notranslate"><span class="pre">day</span></code>, <code class="docutils literal notranslate"><span class="pre">month</span></code> and <code class="docutils literal notranslate"><span class="pre">year</span></code> to describe the time
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> 1
@ -155,22 +188,43 @@
<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="k">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>
</div>
<p>The script will be created silently. The <code class="docutils literal notranslate"><span class="pre">at_sunrise</span></code> function will now be called every in-game day at 6 AM. You can use the <code class="docutils literal notranslate"><span class="pre">&#64;scripts</span></code> command to see it. You could stop it using <code class="docutils literal notranslate"><span class="pre">&#64;scripts/stop</span></code>. If we hadnt set <code class="docutils literal notranslate"><span class="pre">repeat</span></code> the sun would only have risen once and then never again.</p>
<p>We used the <code class="docutils literal notranslate"><span class="pre">&#64;py</span></code> command here: nothing prevents you from adding the system into your game code. Remember to be careful not to add each event at startup, however, otherwise there will be a lot of overlapping events scheduled when the sun rises.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">schedule</span></code> function when using <code class="docutils literal notranslate"><span class="pre">repeat</span></code> set to <code class="docutils literal notranslate"><span class="pre">True</span></code> works with the higher, non-specified unit. In our example, we have specified hour, minute and second. The higher unit we havent specified is day: <code class="docutils literal notranslate"><span class="pre">schedule</span></code> assumes we mean “run the callback every day at the specified time”. Therefore, you can have an event that runs every hour at HH:30, or every month on the 3rd day.</p>
<p>The script will be created silently. The <code class="docutils literal notranslate"><span class="pre">at_sunrise</span></code> function will now be called every in-game day
at 6 AM. You can use the <code class="docutils literal notranslate"><span class="pre">&#64;scripts</span></code> command to see it. You could stop it using <code class="docutils literal notranslate"><span class="pre">&#64;scripts/stop</span></code>. If
we hadnt set <code class="docutils literal notranslate"><span class="pre">repeat</span></code> the sun would only have risen once and then never again.</p>
<p>We used the <code class="docutils literal notranslate"><span class="pre">&#64;py</span></code> command here: nothing prevents you from adding the system into your game code.
Remember to be careful not to add each event at startup, however, otherwise there will be a lot of
overlapping events scheduled when the sun rises.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">schedule</span></code> function when using <code class="docutils literal notranslate"><span class="pre">repeat</span></code> set to <code class="docutils literal notranslate"><span class="pre">True</span></code> works with the higher, non-specified unit.
In our example, we have specified hour, minute and second. The higher unit we havent specified is
day: <code class="docutils literal notranslate"><span class="pre">schedule</span></code> assumes we mean “run the callback every day at the specified time”. Therefore, you
can have an event that runs every hour at HH:30, or every month on the 3rd day.</p>
<blockquote>
<div><p>A word of caution for repeated scripts on a monthly or yearly basis: due to the variations in the real-life calendar you need to be careful when scheduling events for the end of the month or year. For example, if you set a script to run every month on the 31st it will run in January but find no such day in February, April etc. Similarly, leap years may change the number of days in the year.</p>
<div><p>A word of caution for repeated scripts on a monthly or yearly basis: due to the variations in the
real-life calendar you need to be careful when scheduling events for the end of the month or year.
For example, if you set a script to run every month on the 31st it will run in January but find no
such day in February, April etc. Similarly, leap years may change the number of days in the year.</p>
</div></blockquote>
</div>
</div>
<div class="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>
<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 werent really fond of the hassle of following the astronomical calendar). Another example would be creating a planet in a different solar system with, say, days 29 hours long and months of only 18 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>
<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
werent really fond of the hassle of following the astronomical calendar). Another example would be
creating a planet in a different solar system with, say, days 29 hours long and months of only 18
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>
<div class="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 need the notion of weeks… but we need the notion of months having 30 days, not 28.</p>
<p>The custom calendar is defined by adding the <code class="docutils literal notranslate"><span class="pre">TIME_UNITS</span></code> setting to your settings file. Its a dictionary containing as keys the name of the units, and as value the number of seconds (the 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>
<p>In our first example of the Shire calendar, used by hobbits in books by Tolkien, we dont really
need the notion of weeks… but we need the notion of months having 30 days, not 28.</p>
<p>The custom calendar is defined by adding the <code class="docutils literal notranslate"><span class="pre">TIME_UNITS</span></code> setting to your settings file. Its a
dictionary containing as keys the name of the units, and as value the number of seconds (the
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>1
2
3
@ -186,8 +240,11 @@
<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>
<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>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> 1
2
@ -222,12 +279,18 @@
<span class="p">}</span>
</pre></div>
</td></tr></table></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>
<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>
</div>
<div class="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>
<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>
<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> 1
2
3
@ -327,16 +390,21 @@
<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>
<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>
<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>
</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>
<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>
</div>
<div class="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>
<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>
<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>
</div>
</div>
</div>
@ -404,7 +472,10 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> &#187;</li>
<li class="nav-item nav-item-0"><a href="index.html">Evennia 1.0-dev documentation</a> &#187;</li>
<li class="nav-item nav-item-last"><a href="#">Gametime Tutorial</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">