Jump to content

Photo

Detecting whether Link has the map of the current DMap


  • Please log in to reply
7 replies to this topic

#1 Twilight Knight

Twilight Knight

    Tell all with glee, Argon's on PureZC

  • Members
  • Real Name:Sven
  • Location:Rotterdam, NL

Posted 24 August 2020 - 04:29 PM

Hey all.

 

I'm wondering if there already is a way to detect whether Link has the map of the current DMap.

Or am I better off using an item script for the Map that will alter an global array based on the current level number? Then I can read that global array in a ffc or dmap script.

 

Thanks in advance!



#2 Mani Kanina

Mani Kanina

    Rabbits!

  • Members

Posted 24 August 2020 - 07:07 PM

Just check Game->LItems[] with your scripts.
 

LItems[i]

The exploration items (map, compass, boss key etc.) of dungeon level i
currently under the possession of the player, where i is
the index used to access this array. Each element of this
array consists of flags OR'd (|) together; use the LI_ constants in
std.zh to set or compare these values.


Edited by Mani Kanina, 24 August 2020 - 07:07 PM.

  • Twilight Knight likes this

#3 ywkls

ywkls

    Master

  • Members

Posted 24 August 2020 - 07:57 PM

Here's some actually useful information,.
//From stdfunctions
//D0- the level to check
//D1- the item to check. In this case, LI_MAP
 
bool GetLevelItem(int level, int itm) {
     return (Game->LItems[level]&itm) != 0;
}

Edited by ywkls, 24 August 2020 - 07:57 PM.

  • Twilight Knight likes this

#4 Aevin

Aevin

  • Members
  • Pronouns:He / Him
  • Location:Oregon

Posted 24 August 2020 - 09:45 PM

The usefulness of Mani Kanina's solution depends entirely on how comfortable you are with binary. It's a perfectly valid answer, though. In fact, I'd argue it's more straightforward than calling a function that does exactly the same thing in its body.

if(Game->LItems[Game->GetCurLevel()] & LI_MAP)

is equivalent to

if(GetLevelItem(Game->GetCurLevel(), LI_MAP))

Either method works fine, though.


  • Twilight Knight, Mani Kanina and Evan20000 like this

#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 25 August 2020 - 01:02 AM

Hey all.

 

I'm wondering if there already is a way to detect whether Link has the map of the current DMap.

Or am I better off using an item script for the Map that will alter an global array based on the current level number? Then I can read that global array in a ffc or dmap script.

 

Thanks in advance!

 

What script type you use will depend on the ZC version you are using, but across all versions, an item script is the worst option here, and ffc is probably the second worst, unless the effect that you want is screen specific (in which case, screendata script in 2.55 may be more appropriate, but ffc is fine).

 

If you are using 2.55, you may want to consider a dmapdata script, as it is far more appropriate, and you can narrow the effects with a range of them; whereas if the effect is truly global, such as drawing a visual map when you press a button with the map item for the current level, then you want global active, or alternatively hero active or some sort of ad-hoc passive itemdata script.

 

The array is the above posts is int Game->LevelItems[int level_id], which you access bitwise with the LI_* constants in <std>. Note that the array index is the level ID, not the DMap ID, so, items collected on multiple DMaps, where those DMaps have the same level value, are shared values. This is also used for the boss key, the TF piece, the compass, and the boss defeated flags on a specific level ID; but not for level-specific keys. (Those use the LevelKeys[int level] array).

 

To read bitwise, you use bitwise AND, and to write you use bitwise OR-ASSIGN (set true), or AND-ASSIGN-NOT:

 

//Note: Integer expansion is used here to demonstrate the activity. 
 
int lvl_id = Game->GetCurLevel();
int a = Rand(1); // Randomly select 0 or 1.
 
// Read:
 
bool  hasmap = (Game->LevelItems[lvl_id] & LI_MAP); // Always wrap bitwise expressions in parens to give them the higher OoO.
 
//Write:
 
if ( a ) Game-LevelItems[lvl_id] |= LI_MAP; // Gives the map for the desired level.
if (!a) Game->LevelItems &= ~LI_MAP; // Removes the map for the desired level. Note that the NOT is used on the value,  and isn't required for AND-ASSIGN. You are setting a bit false with bitwise NOT.
 
// In 2.55, there is a shorthand version as:
if(!a) Game->LevelItems ~= LI_MAP; // This is identical to AND-EQUALS-NOT, but requires ZScript 18 or higher.
 

 

 

You can read more on these arrays in zscript.txt, and view the list of flags to use to access them, in std.txt. These arrays are read-write, so you can not only check if the player has a level item for a specific level ID, but you can also set or unset the items (and the boss flag) for any level, at any time.


  • Twilight Knight likes this

#6 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 25 August 2020 - 01:15 AM

....does `LevelItems[]` work? If so, I don't think it's documented... `LItems[]` is in the docs


  • Twilight Knight likes this

#7 Twilight Knight

Twilight Knight

    Tell all with glee, Argon's on PureZC

  • Members
  • Real Name:Sven
  • Location:Rotterdam, NL

Posted 25 August 2020 - 02:25 AM

Thanks everyone for the help.

Game->LItems[] was the property I was looking for, thanks Mani.

 

But everyone's following answers are helpful too since I didn't even know about the bitwise operators. I'm used to multidimensional arrays ;-)

 

 

To clear this up btw:

an item script is the worst option here

I was referring to using an item script to keep track of which maps are collecting for which level number. So basically making my own LItems[]. Which is not necessary anymore now I know about LItems[]

 

 


Edited by Twilight Knight, 25 August 2020 - 02:27 AM.


#8 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 27 August 2020 - 09:08 PM

....does `LevelItems[]` work? If so, I don't think it's documented... `LItems[]` is in the docs

 

It might, or I could have thought that I added it to both versions, and didn't. Expanding some of those obtuse identifiers was on my to do list, but IDK if that stuff was merged, or happened when I was dreaming.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users