UFO:Alien Invasion
Development => Newbie Coding => Topic started 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.
-
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.
-
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? :-[
-
bit operations. especially the logical and and the right shifting for the level flags.
-
So surfaceflags is 'bitwise and' ?
-
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)
-
oh sorry, yes, left shifting of course.