PDA

View Full Version : [Guide] Binary Flags



an7hraxjax
06-12-2011, 10:20 AM
Hello there,

This is a small guide to binary flags. It allows to convert an integer into binary code, with the XML tags. You never know you might need it in an algorithm.
The problem is that S2 didn't provide a modulo calculation function yet :(

A possible situation is where you want to apply a state and give more than 1 parameter (flag) to it.
One solution is to make several states, one for each parameter. But this is not very handy when the number gets big.

A more concrete example :

In my :slit: Slither Bomberman map, the AI bots run around without getting stuck into walls or trees. How is this ? If you draw a grid, there are 4 ways to go : up, down, left, right. I made a grid with location gadgets that allow the player to go only in open directions. At the moment, i do this with a different entity for each location that knows its neighbors ... this is very clumsy. It doesn't allow random map generation in HoN itself as well.

The next update will contain only one type of location gadgets, each with only one aura state, containing 4 parameters : allow up, down, left, right.
This will allow to change the gadgets aura state, for example when you destroyed a few crates, you open new routes. Dynamic terrain. I'm looking forward to it.


Integer ==> Binary :bubb:

param ==> var3 var2 var1 var0

Assume we apply a state and we want to add 4 flags. We use param to pass the parameters.
4 flags = 4 bits , this gives param in 0 - 15 range.

<applystate name="My_State" param="13"/>The <onimpact> (or another event) of My_state :


<!--save the original in param-->
<setaccumulator value="param"/>

<compare a="accumulator" b="8" op="ge"/>
<setvar3 a="result" b="8" op="mult"/>
<changeaccumulator b="var3" op="sub"/>

<compare a="accumulator" b="4" op="ge"/>
<setvar2 a="result" b="4" op="mult"/>
<changeaccumulator b="var2" op="sub"/>

<compare a="accumulator" b="2" op="ge"/>
<setvar1 a="result" b="2" op="mult"/>
<changeaccumulator b="var1" op="sub"/>

<compare a="accumulator" b="1" op="eq"/>
<setvar0 a="result" b="1" op="mult"/>

<!-- do stuff depending on the vars -->
<!-- if you want you can rescale them so they are 0 and 1 -->
You can extends this of-course, but then you have to take action right after you extract the flags (there are only 4 flags).

For a full use of this code you'll have to wait a bit. Soon.

Feel free to ask any questions, here or on IRC channel honscience .

Schm0ftie
06-12-2011, 02:55 PM
Very interesting, will be looking forward to use it in a
matching situation =)