Jump to content

Photo

Screen Flag Constants in std.zh are incorrect


  • Please log in to reply
4 replies to this topic

#1 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 07 March 2021 - 12:20 PM

I believe all of the individual bitwise Screen Flag constants in std.zh are incorrect.  Here's an excerpt:

//Screen Flag Warp
const int SFW_AUTODIRECT = 0; //  0x0001; //Auto Warps are Direct
const int SFW_SENDSIRECT = 1; //0x0002; //Sensitive Warps are direct.
const int SFW_MAZEPATHS = 2; //0x0004; //Use maze Path
const int SFW_MAZEOVERRIDE = 3; //0x0008; //maze Overrides Sidewarps
const int SFW_SPRITECARRY = 4; //0x0010; //Sprites carry over. 

//Screen Flag Items
const int SFI_HOLDUP = 0; //0x0001; //Hold up item.
const int SFI_FALLS = 1; //0x0002; //Falls from ceiling

The const values do not match the binary values that they're supposed to correspond to.  The result of this is that SFI_FALLS (1) actually checks for the Hold Up Item Screen Flag (0x0001) and the same is true for all the others.



#2 Saffith

Saffith

    IPv7 user

  • Members

Posted 10 March 2021 - 10:27 AM

It looks like they're meant to be shift values, e.g. the sprite carryover flag is 1<<SWF_SPRITECARRY. Might just need that clarification in the documentation.



#3 Mitchfork

Mitchfork

    no fun. not ever.

  • Members
  • Real Name:Mitch
  • Location:Alabama

Posted 10 March 2021 - 01:28 PM

That works, but I don't really understand why they would be setup that way... surely

Screen->Flags[SF_ITEMS] && SFI_HOLDUP

Is a much more readable / sensible logical check than 

Screen->Flags[SF_ITEMS] && (1<<SFI_HOLDUP)

It seems like there was some confusion with this anyway since 

 

//! These DMap Flag values do not return the expected results when compared via TraeS()ing what is anticipated!

 

is also right above all of these in std_constants.zh.

 

EDIT: Got curious, so I looked at the std.zh functions for these:

//Returns 1 if Screen Enemy Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenEFlag(int category, int flag) 
{
	int catsizes[] = {5,5,4}; //this is what the editor shows. 
	//int catsizes[] = {1,5,4}; //this is what ffscript seems to think, anyway. 
	//int catsizes[] = {6,6,5}; //old value, plain wrong. -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return Screen->EFlags[category]&(1<<flag);
}

//Returns 1 if Screen Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenFlag(int category, int flag) 
{
	int catsizes[] = {3,7,4,5,2,4,4,2,3,7}; //according to ffscript.cpp, the last flagset size is 3, but the editor is 7. 
	//int catsizes[] = {3,7,5,3,2,4,4,2,3,7}; //old value, plain wrong -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return Screen->Flags[category]&(1<<flag);
}

//Returns 1 if Screen Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenFlag(int m, int scr, int category, int flag) 
{
	mapdata md = Game->LoadMapData(m,scr); 
	int catsizes[] = {3,7,4,5,2,4,4,2,3,7}; //according to ffscript.cpp, the last flagset size is 3, but the editor is 7. 
	//int catsizes[] = {3,7,5,3,2,4,4,2,3,7}; //old value, plain wrong -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return md->Flags[category]&(1<<flag);
}

//Returns 1 if Screen Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenFlag(mapdata m, int category, int flag) 
{
	int catsizes[] = {3,7,4,5,2,4,4,2,3,7}; //according to ffscript.cpp, the last flagset size is 3, but the editor is 7. 
	//int catsizes[] = {3,7,5,3,2,4,4,2,3,7}; //old value, plain wrong -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return m->Flags[category]&(1<<flag);
}

These all left-shift to return the correct value, so I guess this is intended.  Definitely should have clarification in the documentation since it's absolutely not what someone would expect by default.


Edited by Mitchfork, 10 March 2021 - 01:34 PM.


#4 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 12 March 2021 - 06:37 PM

Those constants are meant specifically for use with the std functions, not direct flags[] access.



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 21 March 2021 - 12:19 PM

That works, but I don't really understand why they would be setup that way... surely

Screen->Flags[SF_ITEMS] && SFI_HOLDUP

Is a much more readable / sensible logical check than 

Screen->Flags[SF_ITEMS] && (1<<SFI_HOLDUP)

It seems like there was some confusion with this anyway since 

 

is also right above all of these in std_constants.zh.

 

EDIT: Got curious, so I looked at the std.zh functions for these:

//Returns 1 if Screen Enemy Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenEFlag(int category, int flag) 
{
	int catsizes[] = {5,5,4}; //this is what the editor shows. 
	//int catsizes[] = {1,5,4}; //this is what ffscript seems to think, anyway. 
	//int catsizes[] = {6,6,5}; //old value, plain wrong. -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return Screen->EFlags[category]&(1<<flag);
}

//Returns 1 if Screen Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenFlag(int category, int flag) 
{
	int catsizes[] = {3,7,4,5,2,4,4,2,3,7}; //according to ffscript.cpp, the last flagset size is 3, but the editor is 7. 
	//int catsizes[] = {3,7,5,3,2,4,4,2,3,7}; //old value, plain wrong -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return Screen->Flags[category]&(1<<flag);
}

//Returns 1 if Screen Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenFlag(int m, int scr, int category, int flag) 
{
	mapdata md = Game->LoadMapData(m,scr); 
	int catsizes[] = {3,7,4,5,2,4,4,2,3,7}; //according to ffscript.cpp, the last flagset size is 3, but the editor is 7. 
	//int catsizes[] = {3,7,5,3,2,4,4,2,3,7}; //old value, plain wrong -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return md->Flags[category]&(1<<flag);
}

//Returns 1 if Screen Flag 'flag' is set from category 'category', 0 if it's not and -1 if an invalid flag is passed
//Flags are numbered starting from 0
int ScreenFlag(mapdata m, int category, int flag) 
{
	int catsizes[] = {3,7,4,5,2,4,4,2,3,7}; //according to ffscript.cpp, the last flagset size is 3, but the editor is 7. 
	//int catsizes[] = {3,7,5,3,2,4,4,2,3,7}; //old value, plain wrong -Z ( 12th February, 2019 )
	if(flag < 0 || flag >= catsizes[category]) return -1;
	return m->Flags[category]&(1<<flag);
}

These all left-shift to return the correct value, so I guess this is intended.  Definitely should have clarification in the documentation since it's absolutely not what someone would expect by default.

 

I believe that these are documented in std.txt. This has been the implementation since 2.50 beta. The documentation is not altogether clear, admittedly:

 

const int SF_*

 * Screen Flag Categories, can be used with Screen->Flags, GetScreenFlags
 
const int SFR_*
 * Room types.
 
const int SFV_*
 * Screen View Flags
 
const int SFS_* 
 * Screen Secret Flags
 
const int SFW_*
 * Screen Warp Flags
 
const int SFI_*
 * Screen Item Flags



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users