Skip to content

Commit

Permalink
Changes to the way the flags were processed.
Browse files Browse the repository at this point in the history
Removed references to non-inuse items.
Updated documentation.
Included new Racalac Guide documentation supplied by Yukiko.
Clangified my changes.
Updated change log.
  • Loading branch information
sigmantium committed Sep 7, 2018
1 parent b9071bb commit 771f288
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 36 deletions.
11 changes: 10 additions & 1 deletion docs/docs.polserver.com/pol100/corechanges.xml
Expand Up @@ -2,9 +2,18 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>07-30-2018</datemodified>
<datemodified>09-07-2018</datemodified>
</header>
<version name="POL100">
<entry>
<date>09-07-2018</date>
<author>DevGIB:</author>
<change type="Changed">FindObjtypeInContainer(container, objtype, flags :=0 ) to recurse all containers from base container.</change>
<change type="Added">FINDOBJTYPE_IGNORE_LOCKED and FINDOBJTYPE_ROOT_ONLY to UO.EM</change>
<change type="Added">Flags to FindObjtypeInContainer() for only accessing root container, and bypassing locked container checks.</change>
<change type="Note">THESE CHANGES TO FindObjtypeInContainer() WILL EFFECTIVELY CHANGE THE DEFAULT FUNCTIONALITY OF THE FUNCTION AS DEFAULT IS NOW TO RECURSE SUB CONTAINERS.</change>
<change type="Added">Additional documentation to the Racalac escript guide to include additional information supplied by Yukiko.</change>
</entry>
<entry>
<date>07-27-2018</date>
<author>DevGIB:</author>
Expand Down
119 changes: 112 additions & 7 deletions docs/docs.polserver.com/pol100/include/escriptguide.inc
@@ -1,5 +1,5 @@
<h1>Racalac's eScript Reference and Guide v096<br>
<font size="2">(Last Updated: Feb 19, 2009)</font></h1>
<font size="2">(Last Updated: Sept 07, 2018)</font></h1>

<!-- TODO:
- talk about ecompile.cfg and recursive compiling, mention POL ignores
Expand Down Expand Up @@ -188,6 +188,26 @@ eScript are:</p>
<td align="center">Bit-Shift left</td>
</tr>

<tr>
<td align="center">&amp;</td>
<td align="center">Logical <b>AND</b></td>
</tr>

<tr>
<td align="center">|</td>
<td align="center">Logical <b>OR</b></td>
</tr>

<tr>
<td align="center">^</td>
<td align="center">Logical <b>XOR</b></td>
</tr>

<tr>
<td align="center">~</td>
<td align="center">Ones Complement</td>
</tr>

</table>

<p>The expressions are evaluated first inside parenthesis then from
Expand All @@ -198,12 +218,92 @@ left-to-right. Such as:</p>
var pies_left := number_of_trays * (pies_in_tray &#8211; pies_used);
</pre></div>

<h3>Logical <b>AND</b></h3>
<p>
The single &amp; (ampersand) symbol will perform a logical <b>AND</b> of the value on the left of the operator with the value on the right.
<p>If we have a statement
var value := 10 &amp; 14;
The result will equal 10. What is actually happening is that eScript will AND the binary value of 10, 1010, with the binary value of 14, 1110.
<p>Every 1 bit in the value on the left that corresponds to a 1 bit in the same position in the value on the right produces a 1 bit in that position in the result. You can see this visually in the table below.
<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td>Value: 10</td><td>1</td><td>0</td><td>1</td><td>0</td>
</tr>
<tr>
<td>Value: 14</td><td>1</td><td>1</td><td>1</td><td>0</td>
</tr>
<tr>
<td><b>AND</b> (10)</td><td>1</td><td>0</td><td>1</td><td>0</td>
</tr>
</table>

<h3>Logical <b>OR</b></h3>
<p>
The single | (bar) symbol will perform a logical <b>OR</b> of the value on the left of the operator with the value on the right. If we have a statement
var value := 10 | 6;
The result will equal 14. Escript will <b>OR</b> the binary value of 10, 1010, with the binary value of 6, 0110. Where there is a 1 bit in either the value on the left or the value on the right, or both bits are 1, produces a 1 bit in the result. The table below helps you visualize this.

<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td>Value: 10</td><td>1</td><td>0</td><td>1</td><td>0</td>
</tr>
<tr>
<td>Value: 6</td>
<td>0</td>
<td>1</td><td>1</td><td>0</td>
</tr>
<tr>
<td><b>OR</b> (14)</td>
<td>1</td>
<td>1</td>
<td>1</td><td>0</td>
</tr>
</table>

<h3>Logical <b>XOR</b></h3>
<p>
The ^ (caret) will perform a logical <strong>XOR</strong>, or exclusive <strong>OR</strong>, of the value on the left of the operator with the value on the right. If we have a statement
var value := 10 ^ 12;
The result will equal 6. This time eScript will <strong>XOR</strong> the binary value of 10, 1010, with the binary value of 12, 1100. Where there is a 1 bit in either the value on the left or the value on the right produces a 1 bit in the result. Where there is a 0 or a 1 in both bits produces a 0. Again, see the table below.


<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td>Value: 10</td><td>1</td><td>0</td><td>1</td><td>0</td>
</tr>
<tr>
<td>Value: 12</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td><b>XOR</b> (6)</td>
<td>0</td>
<td>1</td>
<td>1</td><td>0</td>
</tr>
</table>

<h3><strong id="docs-internal-guid-f9b28dc1-7fff-cec3-02c5-0ed74c4fce53">Ones&rsquo; complement</strong></h3>
<p>
The ~ (tilde) symbol will perform a ones’ complement on the value to the right of the operator. A ones’ complement operation inverts all the bits in an integer. 1s are flipped to 0s and 0s are flipped to 1s. The following statement will return -2 or in hexadecimal 0xFFFFFFFE.
Var value := ~1;
In a 32 bit hexadecimal representation the value 1 is 0x00000001 or, in binary
0000 0000 0000 0000 0000 0000 0000 0001
If you invert the bits, ones’ complement, you end up with the result, in hexadecimal, of 0xFFFFFFFE or in binary
1111 1111 1111 1111 1111 1111 1111 1110
Quoting “The Book of Knowledge”, Wikipedia: <em>“The ones' complement of the number then behaves like the negative of the original number in some arithmetic operations. To within a constant (of −1), the ones' complement behaves like the negative of the original number with binary addition. However, unlike two's complement, these numbers have not seen widespread use because of issues such as the offset of −1, that negating zero results in a distinct negative zero bit pattern, less simplicity with arithmetic borrowing, etc.”</em>.


<h3>In Addition</h3>
<p>I should mention something about variable types in arithmetic, especially
division. If you divide two integers together such that the result would have a
decimal part, POL will only look at the whole number part. To make sure the
result is a real (integer+decimal part), make sure at least one of the operands
is a real. You can make sure of this by using a raw number with a decimal part
(such as 100.0), or "cast" it to a real (convert the type). There are a few
division. If you divide two integers together such that the result would have a
decimal part, POL will only look at the whole number part. To make sure the
result is a real (integer+decimal part), make sure at least one of the operands
is a real. You can make sure of this by using a raw number with a decimal part
(such as 100.0), or "cast" it to a real (convert the type). There are a few
casting functions in eScript, CInt(), CStr(), CDbl().</p>

<div class="doc-guide-pre">
Expand Down Expand Up @@ -711,6 +811,7 @@ you what iteration you are on.</p>
<pre>
var a := array{&quot;A&quot;, 1000};
foreach i in ( a )

Print(_value_iter);
Print(value);
endforeach</pre></div>
Expand Down Expand Up @@ -1634,6 +1735,7 @@ forgot an 'endif' keyword. The compile ran into the 'endprogram' keyword before

<div class="doc-guide-pre">
<pre>

Token 'item' cannot follow token ')'
Error compiling statement at D:\pd\pol\scripts\items\torch.src, Line 2</pre></div>

Expand Down Expand Up @@ -1730,6 +1832,7 @@ SetGlobalProperty(globname ,"No");</pre></div>
can also but more than just simple variables as the value, for both GProps and
CProps. Here's an example:</p>


<div class="doc-guide-pre">
<pre>
var propname := "Property1";
Expand Down Expand Up @@ -2391,5 +2494,7 @@ value, and then destroy it when the function is done.</p>
v0.6d: 19/02/2009<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Reformated. -Turley<br>
v0.6e: 12/10/2015<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Cleaned HTML code. - Bodom<br>
Cleaned HTML code. - Bodom</p>
<p>v0.7: 07/09/2018<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Added additional information regarding AND, OR, XOR, Ones Compliment operators supplied by Yukiko<br>
</p>
12 changes: 11 additions & 1 deletion docs/docs.polserver.com/pol100/uoem.xml
Expand Up @@ -138,6 +138,10 @@
<constant>const FINDSUBSTANCE_ROOT_ONLY := 0x2; // Do not find matches in sub-containers.</constant>
<constant>const FINDSUBSTANCE_FIND_ALL := 0x4; // Find all matches ignoring given amount</constant>
<constant> </constant>
<constant>// FindObjtypeInContainer constants</constant>
<constant>const FINDOBJTYPE_IGNORE_LOCKED := 0x1; // Find matches in locked containers</constant>
<constant>const FINDOBJTYPE_ROOT_ONLY := 0x2; // Do not find matches in sub-containers.</constant>
<constant> </constant>
<constant>// SendTextEntryGump options</constant>
<constant>const TE_CANCEL_DISABLE := 0;</constant>
<constant>const TE_CANCEL_ENABLE := 1;</constant>
Expand Down Expand Up @@ -287,10 +291,16 @@ container
</function>

<function name="FindObjtypeInContainer">
<prototype>FindObjtypeInContainer( container, objtype )</prototype>
<prototype>FindObjtypeInContainer( container, objtype, flags:=0 )</prototype>
<parameter name="container" value="Container reference" />
<parameter name="objtype" value="integer objtype to find" />
<parameter name="flags" value="Integer" />
<explain>Returns an Item Reference to the first found item matching objtype starting in "container".</explain>
<explain>uo.em constants for flags:
<code>
// FindObjtype constants
const FINDOBJTYPE_IGNORE_LOCKED := 0x1; // Find matches in locked containers
const FINDOBJTYPE_ROOT_ONLY := 0x2; // Do not find matches in sub-containers.</code></explain>
<return>Item reference or Error</return>
<error>"Invalid parameter type"</error>
<error>"That is not a container" if container.isa(POLCLASS_CONTAINER) == false</error>
Expand Down
6 changes: 6 additions & 0 deletions pol-core/doc/core-changes.txt
@@ -1,4 +1,10 @@
-- POL100 --
09-07-2018 DevGIB:
Changed: FindObjtypeInContainer(container, objtype, flags :=0 ) to recurse all containers from base container.
Added: FINDOBJTYPE_IGNORE_LOCKED and FINDOBJTYPE_ROOT_ONLY to UO.EM
Added: Flags to FindObjtypeInContainer() for only accessing root container, and bypassing locked container checks.
Note: THESE CHANGES TO FindObjtypeInContainer() WILL EFFECTIVELY CHANGE THE DEFAULT FUNCTIONALITY OF THE FUNCTION AS DEFAULT IS NOW TO RECURSE SUB CONTAINERS.
Added: Additional documentation to the Racalac escript guide to include additional information supplied by Yukiko.
07-27-2018 DevGIB:
Added: ListStaticsNearLocationOfType( x, y, z, range, objtype, flags := 0, realm := _DEFAULT_REALM ) to get a struct of statics near a location which match an objtype.
Added: ListStaticsNearLocationWithFlag( x, y, z, range, flags, realm := _DEFAULT_REALM ) to get a struct of statics near a location which have matching flags in the tiledata.
Expand Down
44 changes: 22 additions & 22 deletions pol-core/pol/containr.cpp
Expand Up @@ -67,9 +67,9 @@ UContainer::~UContainer()
size_t UContainer::estimatedSize() const
{
const size_t size = base::estimatedSize() + sizeof( u16 ) /*held_weight_*/
+ sizeof( unsigned int ) /*held_item_count_*/
// no estimateSize here element is in objhash
+ 3 * sizeof( Items::Item** ) + contents_.capacity() * sizeof( Items::Item* );
+ sizeof( unsigned int ) /*held_item_count_*/
// no estimateSize here element is in objhash
+ 3 * sizeof( Items::Item** ) + contents_.capacity() * sizeof( Items::Item* );
return size;
}

Expand Down Expand Up @@ -421,28 +421,28 @@ Items::Item* UContainer::find_addable_stack( const Items::Item* adding_item ) co
return nullptr;
}

Items::Item* UContainer::find_objtype(u32 objtype, int flags) const
Items::Item* UContainer::find_objtype( u32 objtype, int flags ) const
{
Items::Item* _item = find_toplevel_objtype(objtype);
if (_item != nullptr)
return _item;
if (!(flags & FINDOBJTYPE_ROOT_ONLY))
Items::Item* _item = find_toplevel_objtype( objtype );
if ( _item != nullptr )
return _item;
if ( !( flags & FINDOBJTYPE_ROOT_ONLY ) )
{
for ( const auto& item : contents_ )
{
for (const auto& item : contents_)
if ( item && item->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
{
UContainer* cont = static_cast<UContainer*>( item );
if ( !cont->locked() || ( flags & FINDOBJTYPE_IGNORE_LOCKED ) )
{
if (item && item->isa(UOBJ_CLASS::CLASS_CONTAINER) && !item->inuse())
{
UContainer* cont = static_cast<UContainer*>(item);
if (!cont->locked() || (flags & FINDOBJTYPE_IGNORE_LOCKED) )
{
auto child_item = cont->find_objtype_noninuse(objtype);
if (child_item != nullptr)
return child_item;
}
}
auto child_item = cont->find_objtype( objtype, flags );
if ( child_item != nullptr )
return child_item;
}
}
}
return nullptr;
}
return nullptr;
}


Expand Down Expand Up @@ -934,7 +934,7 @@ unsigned short UContainer::max_items() const
{
const auto max_items = desc.max_items + max_items_mod();

return std::max( 1, std::min<decltype(max_items)>( max_items, MAX_CONTAINER_ITEMS ) );
return std::max( 1, std::min<decltype( max_items )>( max_items, MAX_CONTAINER_ITEMS ) );
}

unsigned short UContainer::max_weight() const
Expand All @@ -953,7 +953,7 @@ u8 UContainer::max_slots() const
{
const auto max_slots = desc.max_slots + max_slots_mod();

return std::max( 0, std::min<decltype(max_slots)>( max_slots, MAX_SLOTS ) );
return std::max( 0, std::min<decltype( max_slots )>( max_slots, MAX_SLOTS ) );
}

bool UContainer::no_drop_exception() const
Expand Down
2 changes: 1 addition & 1 deletion pol-core/pol/containr.h
Expand Up @@ -148,7 +148,7 @@ class UContainer : public ULockable
Items::Item* find_toplevel_objtype_noninuse( u32 objtype ) const;
Items::Item* find_toplevel_objtype_noninuse( u32 objtype, unsigned short maxamount ) const;
Items::Item* find_objtype_noninuse( u32 objtype ) const;
Items::Item* find_objtype(u32 objtype, int flags) const;
Items::Item* find_objtype( u32 objtype, int flags ) const;

virtual void for_each_item( void ( *f )( Item* item, void* a ), void* arg );

Expand Down
4 changes: 2 additions & 2 deletions pol-core/pol/core.h
Expand Up @@ -91,6 +91,6 @@ const int JOURNAL_PRINT_YOU_SEE = 0x01;

Items::Item* find_walkon_item( ItemsVector& ivec, short z );
void restart_all_clients();
}
}
} // namespace Core
} // namespace Pol
#endif
4 changes: 2 additions & 2 deletions pol-core/pol/module/uomod.cpp
Expand Up @@ -679,8 +679,8 @@ BObjectImp* UOExecutorModule::mf_FindObjtypeInContainer()
{
return new BError( "That is not a container" );
}
if (!getParam(4, flags))
flags = 0;
if ( !getParam( 4, flags ) )
flags = 0;

UContainer* cont = static_cast<UContainer*>( item );
Item* found = cont->find_objtype( objtype, flags );
Expand Down

0 comments on commit 771f288

Please sign in to comment.