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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Castle Game Engine: CastleItems: Class TInventoryItem</title>
<meta name="generator" content="PasDoc 0.13.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="StyleSheet" type="text/css" href="pasdoc.css">
</head>
<body>
<table class="container"><tr><td class="navigation">
<h2>Castle Game Engine</h2><p><a href="introduction.html" class="navigation">Introduction</a></p><p><a href="AllUnits.html" class="navigation">Units</a></p><p><a href="ClassHierarchy.html" class="navigation">Class Hierarchy</a></p><p><a href="AllClasses.html" class="navigation">Classes, Interfaces, Objects and Records</a></p><p><a href="AllTypes.html" class="navigation">Types</a></p><p><a href="AllVariables.html" class="navigation">Variables</a></p><p><a href="AllConstants.html" class="navigation">Constants</a></p><p><a href="AllFunctions.html" class="navigation">Functions and Procedures</a></p><p><a href="AllIdentifiers.html" class="navigation">Identifiers</a></p></td><td class="content">
<a name="TInventoryItem"></a><h1 class="cio">Class TInventoryItem</h1>
<table class="sections wide_list">
<tr>
<td><a class="section" href="#PasDoc-Description">Description</a></td><td><a class="section" href="#PasDoc-Hierarchy">Hierarchy</a></td><td>Fields</td><td><a class="section" href="#PasDoc-Methods">Methods</a></td><td><a class="section" href="#PasDoc-Properties">Properties</a></td></tr></table>
<a name="PasDoc-Description"></a><h2 class="unit">Unit</h2>
<p class="unitlink">
<a href="CastleItems.html">CastleItems</a></p>
<h2 class="declaration">Declaration</h2>
<p class="declaration">
<code>type TInventoryItem = class(TComponent)</code></p>
<h2 class="description">Description</h2>
<p>
An item that can be used, kept in the inventory, or (using <a class="normal" href="CastleItems.TInventoryItem.html#PutOnWorld">PutOnWorld</a> that wraps it in <a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a>) dropped on 3D world. Thanks to the <a class="normal" href="CastleItems.TInventoryItem.html#Quantity">Quantity</a> property, this may actually represent many "stacked" items, all having the same properties.</p>
<a name="PasDoc-Hierarchy"></a><h2 class="hierarchy">Hierarchy</h2>
<ul class="hierarchy"><li class="ancestor">TComponent</li>
<li class="thisitem">TInventoryItem</li></ul><h2 class="overview">Overview</h2>
<a name="PasDoc-Methods"></a><h3 class="summary">Methods</h3>
<table class="summary wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="protected.gif" alt="Protected" title="Protected"></a></td>
<td class="itemcode"><code>procedure <b><a href="CastleItems.TInventoryItem.html#Stack">Stack</a></b>(var Item: <a href="CastleItems.TInventoryItem.html">TInventoryItem</a>); virtual;</code></td>
</tr>
<tr class="list2">
<td class="visibility"><a href="legend.html"><img src="protected.gif" alt="Protected" title="Protected"></a></td>
<td class="itemcode"><code>procedure <b><a href="CastleItems.TInventoryItem.html#Picked">Picked</a></b>(const NewOwner: <a href="CastleItems.T3DAliveWithInventory.html">T3DAliveWithInventory</a>); virtual;</code></td>
</tr>
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="protected.gif" alt="Protected" title="Protected"></a></td>
<td class="itemcode"><code>procedure <b><a href="CastleItems.TInventoryItem.html#Use">Use</a></b>; virtual;</code></td>
</tr>
<tr class="list2">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <b><a href="CastleItems.TInventoryItem.html#Split">Split</a></b>(QuantitySplit: Cardinal): <a href="CastleItems.TInventoryItem.html">TInventoryItem</a>;</code></td>
</tr>
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <b><a href="CastleItems.TInventoryItem.html#PutOnWorld">PutOnWorld</a></b>(const AWorld: <a href="Castle3D.T3DWorld.html">T3DWorld</a>; const APosition: <a href="CastleVectors.html#TVector3Single">TVector3Single</a>): <a href="CastleItems.TItemOnWorld.html">TItemOnWorld</a>;</code></td>
</tr>
<tr class="list2">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>function <b><a href="CastleItems.TInventoryItem.html#World">World</a></b>: <a href="Castle3D.T3DWorld.html">T3DWorld</a>;</code></td>
</tr>
</table>
<a name="PasDoc-Properties"></a><h3 class="summary">Properties</h3>
<table class="summary wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>property <b><a href="CastleItems.TInventoryItem.html#Resource">Resource</a></b>: <a href="CastleItems.TItemResource.html">TItemResource</a> read FResource;</code></td>
</tr>
<tr class="list2">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>property <b><a href="CastleItems.TInventoryItem.html#Quantity">Quantity</a></b>: Cardinal read FQuantity write FQuantity;</code></td>
</tr>
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><code>property <b><a href="CastleItems.TInventoryItem.html#Owner3D">Owner3D</a></b>: <a href="Castle3D.T3D.html">T3D</a> read FOwner3D;</code></td>
</tr>
</table>
<h2 class="description">Description</h2>
<h3 class="detail">Methods</h3>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="protected.gif" alt="Protected" title="Protected"></a></td>
<td class="itemcode"><a name="Stack"></a><code>procedure <b>Stack</b>(var Item: <a href="CastleItems.TInventoryItem.html">TInventoryItem</a>); virtual;</code></td>
</tr>
<tr><td colspan="2">
<p>
Try to sum (<code>stack</code>) the given Item with current <a class="normal" href="CastleItems.TInventoryItem.html">TInventoryItem</a>. The idea is that if player has 5 arrows, and picks an item representing another 5 arrows, then we sum then into one <a class="normal" href="CastleItems.TInventoryItem.html">TInventoryItem</a> instance representing 10 arrows.
<p>Various games, and various items, may require various approaches: for example, maybe you don't want some items to <code>stack</code> at all (e.g. you want to only allow stacking for items naturally appearing in vast quantities, like arrows and bolts and bullets (if you represent them as <a class="normal" href="CastleItems.TInventoryItem.html">TInventoryItem</a> at all)). Maybe you want to allow stacking only to centain number, e.g. arrows are summed into groups of maximum 20 items, anything above creates new <code>stack</code>? Overriding this procedure allows you to do all this.
<p>You can here increase the Quantity of current item, decrease the Quantity of parameter Item. In case the parameter Item no longer exists (it's Quantity reaches 0) you have to free it and set to <code>Nil</code> the Item parameter, in practice you usually want to call then <code>FreeAndNil(Item)</code>.
<p>The default implementation of this in <a class="normal" href="CastleItems.TInventoryItem.html">TInventoryItem</a> class allows stacking always, as long as the Resource matches. This means that, by default, every <a class="normal" href="CastleItems.TItemResource.html">TItemResource</a> is existing at most once in <a class="normal" href="CastleItems.T3DAliveWithInventory.html#Inventory">T3DAliveWithInventory.Inventory</a>.</p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="protected.gif" alt="Protected" title="Protected"></a></td>
<td class="itemcode"><a name="Picked"></a><code>procedure <b>Picked</b>(const NewOwner: <a href="CastleItems.T3DAliveWithInventory.html">T3DAliveWithInventory</a>); virtual;</code></td>
</tr>
<tr><td colspan="2">
<p>
Item is <code>picked</code> by an alive player/creature. The default implementation in this class adds the item to the Inventory by calling <a class="normal" href="CastleItems.T3DAliveWithInventory.html#PickItem">T3DAliveWithInventory.PickItem</a>.
<p>You can override this to cause different behavior (for example, to consume some items right at pickup). Remember that this method must take care of memory management of this item.</p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="protected.gif" alt="Protected" title="Protected"></a></td>
<td class="itemcode"><a name="Use"></a><code>procedure <b>Use</b>; virtual;</code></td>
</tr>
<tr><td colspan="2">
<p>
<code>Use</code> this item.
<p>In this class, this just prints a message "this item cannot be used".
<p>Implementation of this method can assume for now that this is one of player's owned Items. Implementation of this method can change our properties, including Quantity. As a very special exception, implementation of this method is allowed to set Quantity of Item to 0.
<p>Never call this method when Player.Dead. Implementation of this method may assume that Player is not Dead.
<p>Caller of this method should always be prepared to immediately handle the "Quantity = 0" situation by freeing given item, removing it from any list etc.</p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><a name="Split"></a><code>function <b>Split</b>(QuantitySplit: Cardinal): <a href="CastleItems.TInventoryItem.html">TInventoryItem</a>;</code></td>
</tr>
<tr><td colspan="2">
<p>
Splits item (with Quantity >= 2) into two items. It returns newly created object with the same properties as this object, and with Quantity set to QuantitySplit. And it lowers our Quantity by QuantitySplit.
<p>Always QuantitySplit must be >= 1 and < Quantity.</p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><a name="PutOnWorld"></a><code>function <b>PutOnWorld</b>(const AWorld: <a href="Castle3D.T3DWorld.html">T3DWorld</a>; const APosition: <a href="CastleVectors.html#TVector3Single">TVector3Single</a>): <a href="CastleItems.TItemOnWorld.html">TItemOnWorld</a>;</code></td>
</tr>
<tr><td colspan="2">
<p>
Create <a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a> instance referencing this item, and add this to the given 3D AWorld. Although normal item knows (through <a class="normal" href="CastleItems.TInventoryItem.html#Owner3D">Owner3D</a>) the world it lives in, but this method may be used for items that don't have an owner yet, so we take AWorld parameter explicitly. This is how you should create new <a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a> instances. It is analogous to <a class="normal" href="CastleCreatures.TCreatureResource.html#CreateCreature">TCreatureResource.CreateCreature</a>, but now for items.</p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><a name="World"></a><code>function <b>World</b>: <a href="Castle3D.T3DWorld.html">T3DWorld</a>;</code></td>
</tr>
<tr><td colspan="2">
<p>
3D world of this item, if any.
<p>Although the <a class="normal" href="CastleItems.TInventoryItem.html">TInventoryItem</a>, by itself, is not a 3D thing (only pickable <a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a> is a 3D thing). But it exists inside a 3D world: either as pickable (<a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a>), or as being owned by a 3D object (like player or creature) that are part of 3D world. In other words, our Owner3D.World is the 3D world this item lives in.</p>
</td></tr>
</table>
<h3 class="detail">Properties</h3>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><a name="Resource"></a><code>property <b>Resource</b>: <a href="CastleItems.TItemResource.html">TItemResource</a> read FResource;</code></td>
</tr>
<tr><td colspan="2">
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><a name="Quantity"></a><code>property <b>Quantity</b>: Cardinal read FQuantity write FQuantity;</code></td>
</tr>
<tr><td colspan="2">
<p>
Quantity of this item. This must always be >= 1.</p>
</td></tr>
</table>
<table class="detail wide_list">
<tr class="list">
<td class="visibility"><a href="legend.html"><img src="public.gif" alt="Public" title="Public"></a></td>
<td class="itemcode"><a name="Owner3D"></a><code>property <b>Owner3D</b>: <a href="Castle3D.T3D.html">T3D</a> read FOwner3D;</code></td>
</tr>
<tr><td colspan="2">
<p>
3D owner of the item, like a player or creature (if the item is in the backpack) or the <a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a> instance (if the item is lying on the world, pickable). May be <code>Nil</code> only in special situations (when item is moved from one 3D to another, and technically it's safer to <code>Nil</code> this property).
<p>The owner is always responsible for freeing this <a class="normal" href="CastleItems.TInventoryItem.html">TInventoryItem</a> instance (in case of <a class="normal" href="CastleItems.TItemOnWorld.html">TItemOnWorld</a>, it does it directly; in case of player or creature, it does it by <a class="normal" href="CastleItems.TInventory.html">TInventory</a>).</p>
</td></tr>
</table>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://michalis.ii.uni.wroc.pl/piwik-castle-engine/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "1"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code -->
<noscript>
<!-- Piwik Image Tracker -->
<img src="http://michalis.ii.uni.wroc.pl/piwik-castle-engine/piwik.php?idsite=1&rec=1" style="border:0" alt="" />
<!-- End Piwik -->
</noscript>
<hr noshade size="1"><span class="appinfo"><em>Generated by <a href="http://pasdoc.sourceforge.net/">PasDoc 0.13.0</a> on 2015-06-15 04:43:10</em>
</span>
</td></tr></table></body></html>
|