evennia/docs/1.0-dev/Contribs/Contrib-Wilderness.html
Evennia docbuilder action fd31020c21 Updated HTML docs.
2022-11-15 20:29:38 +00:00

256 lines
No EOL
15 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Wilderness system &#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" />
<link rel="next" title="XYZgrid" href="Contrib-XYZGrid.html" />
<link rel="prev" title="Slow Exit" href="Contrib-Slow-Exit.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Contrib-XYZGrid.html" title="XYZgrid"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Contrib-Slow-Exit.html" title="Slow Exit"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="Contribs-Overview.html" accesskey="U">Contribs</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Wilderness system</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<h3><a href="../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Wilderness system</a><ul>
<li><a class="reference internal" href="#installation">Installation</a></li>
<li><a class="reference internal" href="#usage">Usage</a></li>
<li><a class="reference internal" href="#customisation">Customisation</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
<li><a class="reference internal" href="#implementation-details">Implementation details</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="Contrib-Slow-Exit.html"
title="previous chapter">Slow Exit</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Contrib-XYZGrid.html"
title="next chapter">XYZgrid</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../_sources/Contribs/Contrib-Wilderness.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com">Home page</a> </li>
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Versions</h3>
<ul>
<li><a href="Contrib-Wilderness.html">1.0-dev (develop branch)</a></li>
<ul>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="wilderness-system">
<h1>Wilderness system<a class="headerlink" href="#wilderness-system" title="Permalink to this headline"></a></h1>
<p>Contribution by titeuf87, 2017</p>
<p>This contrib provides a wilderness map without actually creating a large number
of rooms - as you move, you instead end up back in the same room but its description
changes. This means you can make huge areas with little database use as
long as the rooms are relatively similar (name/desc changing).</p>
<section id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h2>
<p>This contrib does not provide any new commands. Instead the default <code class="docutils literal notranslate"><span class="pre">py</span></code> command
is used to call functions/classes in this contrib directly.</p>
</section>
<section id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline"></a></h2>
<p>A wilderness map needs to created first. There can be different maps, all
with their own name. If no name is provided, then a default one is used. Internally,
the wilderness is stored as a Script with the name you specify. If you dont
specify the name, a script named “default” will be created and used.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>@py from evennia.contrib.grid import wilderness; wilderness.create_wilderness()
</pre></div>
</div>
<p>Once created, it is possible to move into that wilderness map:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>@py from evennia.contrib.grid import wilderness; wilderness.enter_wilderness(me)
</pre></div>
</div>
<p>All coordinates used by the wilderness map are in the format of <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y)</span></code>
tuples. x goes from left to right and y goes from bottom to top. So <code class="docutils literal notranslate"><span class="pre">(0,</span> <span class="pre">0)</span></code>
is the bottom left corner of the map.</p>
</section>
<section id="customisation">
<h2>Customisation<a class="headerlink" href="#customisation" title="Permalink to this headline"></a></h2>
<p>The defaults, while useable, are meant to be customised. When creating a
new wilderness map it is possible to give a “map provider”: this is a
python object that is smart enough to create the map.</p>
<p>The default provider, <code class="docutils literal notranslate"><span class="pre">WildernessMapProvider</span></code>, just creates a grid area that
is unlimited in size.
This <code class="docutils literal notranslate"><span class="pre">WildernessMapProvider</span></code> can be subclassed to create more interesting
maps and also to customize the room/exit typeclass used.</p>
<p>There is also no command that allows players to enter the wilderness. This
still needs to be added: it can be a command or an exit, depending on your
needs.</p>
</section>
<section id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<p>To give an example of how to customize, we will create a very simple (and
small) wilderness map that is shaped like a pyramid. The map will be
provided as a string: a “.” symbol is a location we can walk on.</p>
<p>Lets create a file <code class="docutils literal notranslate"><span class="pre">world/pyramid.py</span></code>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># mygame/world/pyramid.py</span>
<span class="n">map_str</span> <span class="o">=</span> <span class="s1">&#39;&#39;&#39;</span>
<span class="s1"> .</span>
<span class="s1"> ...</span>
<span class="s1"> .....</span>
<span class="s1"> .......</span>
<span class="s1">&#39;&#39;&#39;</span>
<span class="kn">from</span> <span class="nn">evennia.contrib.grid</span> <span class="kn">import</span> <span class="n">wilderness</span>
<span class="k">class</span> <span class="nc">PyramidMapProvider</span><span class="p">(</span><span class="n">wilderness</span><span class="o">.</span><span class="n">WildernessMapProvider</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">is_valid_coordinates</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">wilderness</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">):</span>
<span class="s2">&quot;Validates if these coordinates are inside the map&quot;</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">coordinates</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">lines</span> <span class="o">=</span> <span class="n">map_str</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="c1"># The reverse is needed because otherwise the pyramid will be</span>
<span class="c1"># upside down</span>
<span class="n">lines</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">y</span><span class="p">]</span>
<span class="n">column</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="n">x</span><span class="p">]</span>
<span class="k">return</span> <span class="n">column</span> <span class="o">==</span> <span class="s2">&quot;.&quot;</span>
<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">False</span>
<span class="k">def</span> <span class="nf">get_location_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">):</span>
<span class="s2">&quot;Set the location name&quot;</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">coordinates</span>
<span class="k">if</span> <span class="n">y</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;Atop the pyramid.&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;Inside a pyramid.&quot;</span>
<span class="k">def</span> <span class="nf">at_prepare_room</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">,</span> <span class="n">caller</span><span class="p">,</span> <span class="n">room</span><span class="p">):</span>
<span class="s2">&quot;Any other changes done to the room before showing it&quot;</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">coordinates</span>
<span class="n">desc</span> <span class="o">=</span> <span class="s2">&quot;This is a room in the pyramid.&quot;</span>
<span class="k">if</span> <span class="n">y</span> <span class="o">==</span> <span class="mi">3</span> <span class="p">:</span>
<span class="n">desc</span> <span class="o">=</span> <span class="s2">&quot;You can see far and wide from the top of the pyramid.&quot;</span>
<span class="n">room</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">desc</span> <span class="o">=</span> <span class="n">desc</span>
</pre></div>
</div>
<p>Now we can use our new pyramid-shaped wilderness map. From inside Evennia we
create a new wilderness (with the name “default”) but using our new map provider:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>py from world import pyramid as p; p.wilderness.create_wilderness(mapprovider=p.PyramidMapProvider())
py from evennia.contrib import wilderness; wilderness.enter_wilderness(me, coordinates=(4, 1))
</pre></div>
</div>
</section>
<section id="implementation-details">
<h2>Implementation details<a class="headerlink" href="#implementation-details" title="Permalink to this headline"></a></h2>
<p>When a character moves into the wilderness, they get their own room. If they
move, instead of moving the character, the room changes to match the new
coordinates. If a character meets another character in the wilderness, then
their room merges. When one of the character leaves again, they each get their
own separate rooms. Rooms are created as needed. Unneeded rooms are stored away
to avoid the overhead cost of creating new rooms again in the future.</p>
<hr class="docutils" />
<p><small>This document page is generated from <code class="docutils literal notranslate"><span class="pre">evennia/contrib/grid/wilderness/README.md</span></code>. Changes to this
file will be overwritten, so edit that file rather than this one.</small></p>
</section>
</section>
</div>
</div>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Contrib-XYZGrid.html" title="XYZgrid"
>next</a> |</li>
<li class="right" >
<a href="Contrib-Slow-Exit.html" title="Slow Exit"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="Contribs-Overview.html" >Contribs</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Wilderness system</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2022, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>