UFO:Alien Invasion

Development => Newbie Coding => Topic started by: ShipIt on December 20, 2014, 10:31:50 am

Title: computing surface- and contentflags
Post by: ShipIt on December 20, 2014, 10:31:50 am
What should be my general approach when I try to find out if a certain flag is set, based on the number given in the .map file?

So, if the value for surfaceflags given in the .map file is 24059. How do I know whether the flag for 'light' (1) is set or not?

Right now I am using a quite excessive method:subtract the highest value and check the result, next value, ... for each single value down from high to low. Somehow I have the feeling there should be an easier way.
Title: Re: computing surface- and contentflags
Post by: DarkRain on December 20, 2014, 06:04:16 pm
Open your windows calculator, set it to scientific mode, then you can use the 'and' operator on the surface flags and the value for the flag you are checking (like: 24059 'and' 1), if the result is the flag's value (in this case 1) then the flag is set, if it is zero then the flag is not set.
Title: Re: computing surface- and contentflags
Post by: ShipIt on January 09, 2015, 06:28:02 am
Somehow I missed the reply. Sorry and thank you.

What I am looking for is a way to do that in a script. Is there a name for this kind of encoding that I could ask my favourite www-search-engine for? Or an easy way to do this in ..., well ..., let's say ..., Python?  :-[
Title: Re: computing surface- and contentflags
Post by: Mattn on January 09, 2015, 07:30:21 am
bit operations. especially the logical and and the right shifting for the level flags.
Title: Re: computing surface- and contentflags
Post by: ShipIt on January 10, 2015, 08:08:01 am
So surfaceflags is 'bitwise and' ?
Title: Re: computing surface- and contentflags
Post by: DarkRain on January 14, 2015, 05:56:22 am
To check a flag you use the 'bitwise and' say: surfaceflags & someflag == someflag  (like the example I gave with windows' calculator — which does precisely a bitwise and)

You can get the flag for a given level by *left* shifting like this: 1 << n where n is the level number (starts from zero)

Additionally you can add flags together with 'bitwise or' so for example to get the flags for the two bottom levels in a single value: levelflags = (1 << 0) | (1 << 1)
Title: Re: computing surface- and contentflags
Post by: Mattn on January 14, 2015, 12:59:25 pm
oh sorry, yes, left shifting of course.