mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 18:26:32 +01:00
342 lines
No EOL
15 KiB
HTML
342 lines
No EOL
15 KiB
HTML
|
||
|
||
<!DOCTYPE html>
|
||
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
||
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
||
<head>
|
||
<meta charset="utf-8">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<title>Mass and weight for objects — Evennia 1.0-dev documentation</title>
|
||
|
||
|
||
|
||
|
||
<link rel="shortcut icon" href="_static/favicon.ico"/>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
||
|
||
|
||
|
||
|
||
|
||
<link rel="index" title="Index"
|
||
href="genindex.html"/>
|
||
<link rel="search" title="Search" href="search.html"/>
|
||
<link rel="top" title="Evennia 1.0-dev documentation" href="index.html"/>
|
||
|
||
|
||
<script src="_static/js/modernizr.min.js"></script>
|
||
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav" role="document">
|
||
|
||
|
||
<div class="wy-grid-for-nav">
|
||
|
||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
<div class="wy-side-scroll">
|
||
<div class="wy-side-nav-search">
|
||
|
||
|
||
|
||
<a href="index.html" class="icon icon-home"> Evennia
|
||
|
||
|
||
|
||
</a>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="search">
|
||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||
<input type="text" name="q" placeholder="Search docs" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
|
||
|
||
|
||
<!-- Local TOC -->
|
||
<div class="local-toc"><ul>
|
||
<li><a class="reference internal" href="#">Mass and weight for objects</a><ul>
|
||
<li><a class="reference internal" href="#objects">Objects</a></li>
|
||
<li><a class="reference internal" href="#characters-and-rooms">Characters and rooms</a></li>
|
||
<li><a class="reference internal" href="#inventory">Inventory</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
||
|
||
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="index.html">Evennia</a>
|
||
|
||
</nav>
|
||
|
||
|
||
|
||
<div class="wy-nav-content">
|
||
<div class="rst-content">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
||
<ul class="wy-breadcrumbs">
|
||
|
||
<li><a href="index.html">Docs</a> »</li>
|
||
|
||
<li>Mass and weight for objects</li>
|
||
|
||
|
||
<li class="wy-breadcrumbs-aside">
|
||
|
||
|
||
<a href="_sources/Mass-and-weight-for-objects.md.txt" rel="nofollow"> View page source</a>
|
||
|
||
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
|
||
<hr/>
|
||
</div>
|
||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
<div itemprop="articleBody">
|
||
|
||
<div class="section" id="mass-and-weight-for-objects">
|
||
<h1>Mass and weight for objects<a class="headerlink" href="#mass-and-weight-for-objects" title="Permalink to this headline">¶</a></h1>
|
||
<p>An easy addition to add dynamic variety to your world objects is to give them some mass. Why mass
|
||
and not weight? Weight varies in setting; for example things on the Moon weigh 1/6 as much. On
|
||
Earth’s surface and in most environments, no relative weight factor is needed.</p>
|
||
<p>In most settings, mass can be used as weight to spring a pressure plate trap or a floor giving way,
|
||
determine a character’s burden weight for travel speed… The total mass of an object can
|
||
contribute to the force of a weapon swing, or a speeding meteor to give it a potential striking
|
||
force.</p>
|
||
<div class="section" id="objects">
|
||
<h2>Objects<a class="headerlink" href="#objects" title="Permalink to this headline">¶</a></h2>
|
||
<p>Now that we have reasons for keeping track of object mass, let’s look at the default object class
|
||
inside your mygame/typeclasses/objects.py and see how easy it is to total up mass from an object and
|
||
its contents.</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># inside your mygame/typeclasses/objects.py</span>
|
||
|
||
<span class="k">class</span> <span class="nc">Object</span><span class="p">(</span><span class="n">DefaultObject</span><span class="p">):</span>
|
||
<span class="c1"># [...]</span>
|
||
<span class="k">def</span> <span class="nf">get_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="n">mass</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">attributes</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'mass'</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># Default objects have 1 unit mass.</span>
|
||
<span class="k">return</span> <span class="n">mass</span> <span class="o">+</span> <span class="nb">sum</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">get_mass</span><span class="p">()</span> <span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">contents</span><span class="p">)</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
<p>Adding the <code class="docutils literal notranslate"><span class="pre">get_mass</span></code> definition to the objects you want to sum up the masses for is done with
|
||
Python’s “sum” function which operates on all the contents, in this case by summing them to
|
||
return a total mass value.</p>
|
||
<p>If you only wanted specific object types to have mass or have the new object type in a different
|
||
module, see [[Adding-Object-Typeclass-Tutorial]] with its Heavy class object. You could set the
|
||
default for Heavy types to something much larger than 1 gram or whatever unit you want to use. Any
|
||
non-default mass would be stored on the <code class="docutils literal notranslate"><span class="pre">mass</span></code> [[Attributes]] of the objects.</p>
|
||
</div>
|
||
<div class="section" id="characters-and-rooms">
|
||
<h2>Characters and rooms<a class="headerlink" href="#characters-and-rooms" title="Permalink to this headline">¶</a></h2>
|
||
<p>You can add a <code class="docutils literal notranslate"><span class="pre">get_mass</span></code> definition to characters and rooms, also.</p>
|
||
<p>If you were in a one metric-ton elevator with four other friends also wearing armor and carrying gold bricks, you might wonder if this elevator’s going to move, and how fast.</p>
|
||
<p>Assuming the unit is grams and the elevator itself weights 1,000 kilograms, it would already be
|
||
<code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">elevator/mass=1000000</span></code>, we’re <code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">me/mass=85000</span></code> and our armor is <code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">armor/mass=50000</span></code>.
|
||
We’re each carrying 20 gold bars each <code class="docutils literal notranslate"><span class="pre">@set</span> <span class="pre">gold</span> <span class="pre">bar/mass=12400</span></code> then step into the elevator and see
|
||
the following message in the elevator’s appearance: <code class="docutils literal notranslate"><span class="pre">Elevator</span> <span class="pre">weight</span> <span class="pre">and</span> <span class="pre">contents</span> <span class="pre">should</span> <span class="pre">not</span> <span class="pre">exceed</span> <span class="pre">3</span> <span class="pre">metric</span> <span class="pre">tons.</span></code> Are we safe? Maybe not if you consider dynamic loading. But at rest:</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># Elevator object knows when it checks itself:</span>
|
||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_mass</span><span class="p">()</span> <span class="o"><</span> <span class="mi">3000000</span><span class="p">:</span>
|
||
<span class="k">pass</span> <span class="c1"># Elevator functions as normal.</span>
|
||
<span class="k">else</span><span class="p">:</span>
|
||
<span class="k">pass</span> <span class="c1"># Danger! Alarm sounds, cable snaps, elevator stops...</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
</div>
|
||
<div class="section" id="inventory">
|
||
<h2>Inventory<a class="headerlink" href="#inventory" title="Permalink to this headline">¶</a></h2>
|
||
<p>Example of listing mass of items in your inventory:</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
27
|
||
28
|
||
29
|
||
30
|
||
31</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CmdInventory</span><span class="p">(</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||
<span class="sd">"""</span>
|
||
<span class="sd"> view inventory</span>
|
||
<span class="sd"> Usage:</span>
|
||
<span class="sd"> inventory</span>
|
||
<span class="sd"> inv</span>
|
||
<span class="sd"> Switches:</span>
|
||
<span class="sd"> /weight to display all available channels.</span>
|
||
<span class="sd"> Shows your inventory: carrying, wielding, wearing, obscuring.</span>
|
||
<span class="sd"> """</span>
|
||
|
||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"inventory"</span>
|
||
<span class="n">aliases</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"inv"</span><span class="p">,</span> <span class="s2">"i"</span><span class="p">]</span>
|
||
<span class="n">locks</span> <span class="o">=</span> <span class="s2">"cmd:all()"</span>
|
||
|
||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="s2">"check inventory"</span>
|
||
<span class="n">items</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">contents</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">items</span><span class="p">:</span>
|
||
<span class="n">string</span> <span class="o">=</span> <span class="s2">"You are not carrying anything."</span>
|
||
<span class="k">else</span><span class="p">:</span>
|
||
<span class="n">table</span> <span class="o">=</span> <span class="n">prettytable</span><span class="o">.</span><span class="n">PrettyTable</span><span class="p">([</span><span class="s2">"name"</span><span class="p">,</span> <span class="s2">"desc"</span><span class="p">])</span>
|
||
<span class="n">table</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="bp">False</span>
|
||
<span class="n">table</span><span class="o">.</span><span class="n">border</span> <span class="o">=</span> <span class="bp">False</span>
|
||
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
|
||
<span class="n">second</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">get_mass</span><span class="p">()</span> \
|
||
<span class="k">if</span> <span class="s1">'weight'</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">switches</span> <span class="k">else</span> <span class="n">item</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">desc</span>
|
||
<span class="n">table</span><span class="o">.</span><span class="n">add_row</span><span class="p">([</span><span class="s2">"</span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">item</span><span class="o">.</span><span class="n">get_display_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">sessions</span><span class="p">),</span>
|
||
<span class="n">second</span> <span class="ow">and</span> <span class="n">second</span> <span class="ow">or</span> <span class="s2">""</span><span class="p">])</span>
|
||
<span class="n">string</span> <span class="o">=</span> <span class="s2">"|wYou are carrying:</span><span class="se">\n</span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">table</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">string</span><span class="p">)</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<footer>
|
||
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>
|
||
© Copyright 2020, The Evennia developer community.
|
||
|
||
</p>
|
||
</div>
|
||
Built with <a href="http://sphinx-doc.org/">Sphinx</a> and ❤️ using a custom <a href="https://github.com/LinxiFan/Sphinx-theme">theme</a> based on <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
||
</footer>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript">
|
||
var DOCUMENTATION_OPTIONS = {
|
||
URL_ROOT:'./',
|
||
VERSION:'1.0-dev',
|
||
COLLAPSE_INDEX:false,
|
||
FILE_SUFFIX:'.html',
|
||
HAS_SOURCE: true,
|
||
SOURCELINK_SUFFIX: '.txt'
|
||
};
|
||
</script>
|
||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||
<script type="text/javascript" src="_static/language_data.js"></script>
|
||
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript" src="_static/js/theme.js"></script>
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript">
|
||
jQuery(function () {
|
||
SphinxRtdTheme.StickyNav.enable();
|
||
});
|
||
</script>
|
||
|
||
|
||
</body>
|
||
</html> |