Skip to content

Commit

Permalink
refactor(zscript): deprecate many getters/setters, replace with varia…
Browse files Browse the repository at this point in the history
…bles

~40 built-in methods exist in this style:

```c++
int Max(); // Returns the max.
void Max(int value); // Sets the max.
int GetCurDMapScreen();
```

These have been deprecated and replaced with a variable, like so:

```
int Max; // The max number.
int CurDMapScreen;
```
  • Loading branch information
connorjclark committed Apr 22, 2024
1 parent fd4e4b4 commit 7a20dab
Show file tree
Hide file tree
Showing 61 changed files with 14,417 additions and 304 deletions.
22 changes: 11 additions & 11 deletions resources/docs/ZScript_Additions.txt
Expand Up @@ -1403,7 +1403,7 @@ of iterations is known at compile-time.
will run if the loop ends naturally, i.e. not via 'return' or 'break'.

[example--
for(int q = 1; q <= Screen->NumNPCs(); ++q)
for(int q = 1; q <= Screen->NumNPCs; ++q)
{
npc n = Screen->LoadNPC(q);
if(Distance(n->X,n->Y,Hero->X,Hero->Y) < 64)
Expand Down Expand Up @@ -3313,7 +3313,7 @@ int GetCurScreen();
int CurScreen; //Read-only
* The current screen, relative to the top-left corner of the map

int GetCurDMapScreen();
int CurDMapScreen;
int CurDMScreen; //Read-only
* The current screen, relative to the top-left corner of the DMap
* (Accounts for the DMap offset)
Expand All @@ -3322,7 +3322,7 @@ int GetCurMap();
int CurMap; //Read-only
* The current map

int GetCurDMap();
int CurDMap;
int CurDMap; //Read-only
* The current dmap

Expand Down Expand Up @@ -4829,7 +4829,7 @@ bool Animation;
* Normally 'true'. If enabled, the item is animated by the ZC engine.
* Set this false to disable engine animation.

int Max();
int Max;
* Returns the maximum number of itemsprite sprites (eweapon and lweapon are
* separate values, and should be read from the appropriate
* pointer type) that arw allowed to be on the screen at one time.
Expand Down Expand Up @@ -4938,7 +4938,7 @@ int DroppedBy;

void Remove();
* Instantly DELETES an itemsprite.
* This will immediately invalidate the itemsprite pointer, as well as update 'Screen->NumItems()', and change the indexes for 'Screen->LoadItem()'
* This will immediately invalidate the itemsprite pointer, as well as update 'Screen->NumItems', and change the indexes for 'Screen->LoadItem()'
* If called from an itemsprite script on the itemsprite running the script, immediately terminates the script.

bool SwitchHooked;
Expand Down Expand Up @@ -5005,7 +5005,7 @@ bool Animation;
* Normally 'true'. If enabled, the weapon is animated by the ZC engine.
* Set this false to disable engine animation.

int Max();
int Max;
* Returns the maximum number of weapon sprites (eweapon and lweapon are
* separate values, and should be read from the appropriate
* pointer type) that arw allowed to be on the screen at one time.
Expand Down Expand Up @@ -5264,7 +5264,7 @@ bool Animation;
* Normally 'true'. If enabled, the npc is animated by the ZC engine.
* Set this false to disable engine animation.

int Max();
int Max;
* Returns the maximum number of npc sprites (eweapon and lweapon are
* separate values, and should be read from the appropriate
* pointer type) that arw allowed to be on the screen at one time.
Expand Down Expand Up @@ -5658,7 +5658,7 @@ int DeathSprite;

void Remove();
* Instantly DELETES an npc. No items will be dropped, no sound will play; the npc is simply DELETED OUTRIGHT.
* This will immediately invalidate the npc pointer, as well as update 'Screen->NumNPCs()', and change the indexes for 'Screen->LoadNPC()'
* This will immediately invalidate the npc pointer, as well as update 'Screen->NumNPCs', and change the indexes for 'Screen->LoadNPC()'
* If called from an NPC script on the NPC running the script, immediately terminates the script.

bool Switch(int effect);
Expand Down Expand Up @@ -7284,7 +7284,7 @@ void SetFFCInitA(int ffc_index, int init_a, float value);

int Layer();
int Layer;
* Returns the layer the combo is on in a combodata script, from the 'this->' pointer as 'this->Layer()'
* Returns the layer the combo is on in a combodata script, from the 'this->' pointer as 'this->Layer'
* Using this from any other combodata variable is illegal and undefined.

int Pos();
Expand Down Expand Up @@ -7916,7 +7916,7 @@ Commands for graphics, sound, text, and bitmap objects.
int GetPixel(bitmap b, int x, int y);
* Returns the palette index value for a pixel on a bitmap, at coordinates x, y on that bitmap.

int NumDraws();
int NumDraws;
* Returns the number of script draws that have been executed during the current frame.

int MaxDraws();
Expand Down Expand Up @@ -8108,7 +8108,7 @@ bool PlayEnhancedMusic(int filename[], int track);
*/ Example Use:

int music[]="myfile.mp3"; // Make a string with the filename of the music to play.
if ( !Game->PlayEnhancedMusic(music, 1) ) Game->PlayMIDI(midi_id);
if ( !Game->PlayEnhancedMusic(music, 1) ) Audio->PlayMIDI(midi_id);

// Plays the enhanced music file 'myfle.mp3', track 1.
// If the file is mssing, the game will instead play
Expand Down
36 changes: 18 additions & 18 deletions resources/docs/zscript.txt
Expand Up @@ -46,9 +46,9 @@ Search for !#! to find areas that require completion.
* and "[property]" is the function.
*
* Example:
* void GetCurDMap() is a Game property, and is called as:
* void CurDMap is a Game property, and is called as:
*
* Game->GetCurDMap();
* Game->CurDMap;
*
* "Link", "Screen" and "Game" are always available and don't need to be
* instantiated, while you must initialise other classes, such as ffc, item,
Expand Down Expand Up @@ -813,7 +813,7 @@ float Sqrt(float val); ZASM Instruction:

/************************************************************************************************************/

int GetCurDMapScreen(); ZASM Instruction:
int CurDMapScreen; ZASM Instruction:
CURDSCR
/**
* Retrieves the number of the current screen within the current DMap.
Expand All @@ -839,7 +839,7 @@ float Sqrt(float val); ZASM Instruction:

/************************************************************************************************************/

int GetCurDMap(); ZASM Instruction:
int CurDMap; ZASM Instruction:
CURDMAP
/**
* Returns the number of the current DMap.
Expand Down Expand Up @@ -887,7 +887,7 @@ float Sqrt(float val); ZASM Instruction:
* Positive numbers are for custom MIDIs, and negative values are used for
* the built-in game MIDIs. Because of the way DMap MIDIs are handled
* internally, however, built-in MIDIs besides the overworld, dungeon, and
* level 9 songs won't match up with Game->PlayMIDI() and Game->GetMIDI().
* level 9 songs won't match up with Audio->PlayMIDI() and Game->GetMIDI().
*/ Example Use: !#!

/************************************************************************************************************/
Expand Down Expand Up @@ -1262,7 +1262,7 @@ float Sqrt(float val); ZASM Instruction:
*/ Example Use:

int music[]="myfile.mp3"; // Make a string with the filename of the music to play.
if ( !Game->PlayEnhancedMusic(music, 1) ) Game->PlayMIDI(midi_id);
if ( !Game->PlayEnhancedMusic(music, 1) ) Audio->PlayMIDI(midi_id);

// Plays the enhanced music file 'myfle.mp3', track 1.
// If the file is mssing, the game will instead play
Expand Down Expand Up @@ -2047,7 +2047,7 @@ int LayerScreen(int n); ZASM Instruction:

/************************************************************************************************************/

int NumItems(); ZASM Instruction:
int NumItems; ZASM Instruction:
ITEMCOUNT

/**
Expand All @@ -2067,7 +2067,7 @@ item LoadItem(int num); ZASM Instruction:

/**
* Returns a pointer to the numth item on the current screen. The return
* value is undefined unless 1 <= num <= NumItems().
* value is undefined unless 1 <= num <= NumItems.
*
* Attempting to return an invalid item pointer will print an error to allegro.log.
*
Expand Down Expand Up @@ -2100,7 +2100,7 @@ ffc LoadFFC(int num); ZASM Instruction:

/************************************************************************************************************/

int NumNPCs(); ZASM Instruction:
int NumNPCs; ZASM Instruction:
NPCCOUNT

/**
Expand All @@ -2118,7 +2118,7 @@ npc LoadNPC(int num); ZASM Instruction:

/**
* Returns a pointer to the numth NPC on the current screen. The return
* value is undefined unless 1 <= num <= NumNPCs().
* value is undefined unless 1 <= num <= NumNPCs.
*
*/ Example Use: !#!

Expand All @@ -2139,7 +2139,7 @@ npc CreateNPC(int id); ZASM Instruction:

/************************************************************************************************************/

int NumLWeapons(); ZASM Instruction:
int NumLWeapons; ZASM Instruction:
LWPNCOUNT

/**
Expand All @@ -2157,7 +2157,7 @@ lweapon LoadLWeapon(int num); ZASM Instruction:

/**
* Returns a pointer to the num-th lweapon on the current screen. The return
* value is undefined unless 1 <= num <= NumLWeapons().
* value is undefined unless 1 <= num <= NumLWeapons.
*
*/ Example Use: !#!

Expand All @@ -2180,7 +2180,7 @@ lweapon CreateLWeapon(int type); ZASM Instruction:

/************************************************************************************************************/

int NumEWeapons(); ZASM Instruction:
int NumEWeapons; ZASM Instruction:
EWPNCOUNT

/**
Expand All @@ -2198,7 +2198,7 @@ eweapon LoadEWeapon(int num); ZASM Instruction:

/**
* Returns a pointer to the numth eweapon on the current screen. The return
* value is undefined unless 1 <= num <= NumEWeapons().
* value is undefined unless 1 <= num <= NumEWeapons.
*
*/ Example Use: !#!

Expand Down Expand Up @@ -6148,7 +6148,7 @@ The maximum number of arrays in operation at one time is 4095.

You attempted to reference a game object that has a maximum legal range of 1 to 255.
It is possible that you tried to read outside that range, or that the pointer that you were loading is not valid.
Check NumItems(), NumLWeapons(), NumEWeapons(0, and NumNPCs() before referencing them; and verify that the object ->IsValid()
Check NumItems, NumLWeapons, NumEWeapons(0, and NumNPCs before referencing them; and verify that the object ->IsValid()
Check for loops that may attempt ro reference items outside of the range that actually exist.
Look for any for loops that access these objects, that start, or end at zero.

Expand All @@ -6158,9 +6158,9 @@ The best way to ensure this does not occur, is to make a for loop as follows:

//or//

for ( int q = Screen->NumLWeapons(); q > 0; q-- )
for ( int q = Screen->NumLWeapons; q > 0; q-- )

...replacing NumLWeapons() withthe appropriate type that you are attempting to load.
...replacing NumLWeapons withthe appropriate type that you are attempting to load.

You may be attempting to refrence a pointer that has fallen out of scope.
You may be attempting to reference a pointer that is no longer valid, or has been removed.
Expand Down Expand Up @@ -6205,7 +6205,7 @@ Chweck for any hardcoded values, or constants that are in use with these functio

You may create a maximum of 255 of any one object type on the screen at any one time.
Look for anything that is generating extra pointers, and add a statement such as:
if ( Screen->NumNPCs() < 255 )
if ( Screen->NumNPCs < 255 )

"Max draw primitive limit reached\n"
The maximum number of drawing function calls, per frame, is 1,000.
Expand Down
24 changes: 12 additions & 12 deletions resources/headers/Music.zh
Expand Up @@ -81,13 +81,13 @@ ffc script NPC_MIDI
bool enhanced = ( enh_music[0] != 0 ); //is the dmap music enhanced?

int originalmusic = Game->DMapMIDI[Game->GetCurDMap()];
while(!Screen->NumNPCs())
while(!Screen->NumNPCs)
{
//LogPrint("NPC_MIDI is %s \n", "Waiting (!Screen->NumNPCs())");
//LogPrint("NPC_MIDI is %s \n", "Waiting (!Screen->NumNPCs)");
Waitframe();
}
while(true){
for ( q[0] = Screen->NumNPCs(); q[0] > 0; --q[0] ) {
for ( q[0] = Screen->NumNPCs; q[0] > 0; --q[0] ) {
n = Screen->LoadNPC(q);
if ( n->ID == npc_ID )
{
Expand All @@ -114,7 +114,7 @@ ffc script NPC_MIDI

while(1)
{
for ( int w = Screen->NumNPCs(); w > 0; --w )
for ( int w = Screen->NumNPCs; w > 0; --w )
{
npc n = Screen->LoadNPC(w);
if ( n->ID == npc_ID )
Expand Down Expand Up @@ -172,10 +172,10 @@ ffc script NPC_Music
bool playing;

int originalmusic = Game->DMapMIDI[Game->GetCurDMap()];
while(!Screen->NumNPCs()) Waitframe();
while(!Screen->NumNPCs) Waitframe();

while(true){
for ( q[0] = Screen->NumNPCs(); q[0] > 0; --q[0] )
for ( q[0] = Screen->NumNPCs; q[0] > 0; --q[0] )
{
n = Screen->LoadNPC(q);
if ( n->ID == npc_ID )
Expand All @@ -199,7 +199,7 @@ ffc script NPC_Music
bool stillalive;
while(1)
{
for ( int w = Screen->NumNPCs(); w > 0; --w )
for ( int w = Screen->NumNPCs; w > 0; --w )
{
npc n = Screen->LoadNPC(w);
if ( n->ID == npc_ID )
Expand Down Expand Up @@ -291,7 +291,7 @@ ffc script MusicZH_BossMusic
{
dat = Game->GetScreenD(curScreen,reg);

if ( enem == -1 && !Screen->NumNPCs() )
if ( enem == -1 && !Screen->NumNPCs )
{
Game->SetScreenD(curScreen,reg,1);
}
Expand Down Expand Up @@ -474,7 +474,7 @@ ffc script BossMusicEnhanced_InternalStrings
dat = Game->GetScreenD(curScreen,reg);
//Waitframes(6); //Wait for enemies to spawn. 1.3.4
//Set Screen->D[reg] = 1 if the enemy is dead.
if ( enem == -1 && !Screen->NumNPCs() )
if ( enem == -1 && !Screen->NumNPCs )
{
Game->SetScreenD(curScreen,reg,1);
}
Expand Down Expand Up @@ -526,7 +526,7 @@ ffc script BossMusicEnhanced_InternalStrings
Game->PlayMIDI(midiNumber); //Play MIDI if enhanced music is not available.
}
}
if ( enem == -1 && !Screen->NumNPCs() )
if ( enem == -1 && !Screen->NumNPCs )
{
Game->SetScreenD(curScreen,reg,1);
}
Expand Down Expand Up @@ -772,7 +772,7 @@ ffc script BossMusicEnhanced_old
dat = Game->GetScreenD(curScreen,reg);
//Waitframes(6); //Wait for enemies to spawn. 1.3.4
//Set Screen->D[reg] = 1 if the enemy is dead.
if ( enem == -1 && !Screen->NumNPCs() )
if ( enem == -1 && !Screen->NumNPCs )
{
Game->SetScreenD(curScreen,reg,1);
}
Expand Down Expand Up @@ -831,7 +831,7 @@ ffc script BossMusicEnhanced_old
}
}
}
if ( enem == -1 && !Screen->NumNPCs() )
if ( enem == -1 && !Screen->NumNPCs )
{
Game->SetScreenD(curScreen,reg,1);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/headers/ghost_zh/2.8/ghost2_drawing.zh
Expand Up @@ -73,7 +73,7 @@ void DrawGhostFFCs()
overlayLayer=5;
}

for(int i=1; i<=Screen->NumNPCs(); i++)
for(int i=1; i<=Screen->NumNPCs; i++)
{
ghost=Screen->LoadNPC(i);
aptr=__GetDrawingArray(ghost);
Expand Down
8 changes: 4 additions & 4 deletions resources/headers/ghost_zh/2.8/ghost2_eweapon.zh
Expand Up @@ -96,7 +96,7 @@ eweapon FireEWeapon(int weaponID, int x, int y, float angle, int step, int damag
if((wpn->Misc[__EWI_FLAGS]&EWF_ROTATE)!=0)
SetEWeaponRotation(wpn);

Game->PlaySound(sound);
Audio->PlaySound(sound);

return wpn;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ eweapon FireNonAngularEWeapon(int weaponID, int x, int y, int dir, int step, int

wpn->Misc[__EWI_FLAGS]=flags|__EWFI_IS_GHZH_EWPN;

Game->PlaySound(sound);
Audio->PlaySound(sound);
return wpn;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ eweapon CreateDummyEWeapon(int weaponID, int step, int damage, int sprite, int s
wpn->Misc[__EWI_DUMMY_SPRITE]=sprite;

// Give the weapon a unique ID number so it can be found later
for(int i=Screen->NumEWeapons(); i>0; i--)
for(int i=Screen->NumEWeapons; i>0; i--)
{
checkWpn=Screen->LoadEWeapon(i);
if((checkWpn->Misc[__EWI_FLAGS]&__EWFI_DUMMY_CHECK)==__EWFI_DUMMY_CHECK)
Expand Down Expand Up @@ -856,7 +856,7 @@ eweapon GetAssociatedEWeapon(int weaponID)
{
eweapon wpn;

for(int i=Screen->NumEWeapons(); i>0; i--)
for(int i=Screen->NumEWeapons; i>0; i--)
{
wpn=Screen->LoadEWeapon(i);
if((wpn->Misc[__EWI_FLAGS]&__EWFI_DUMMY_CHECK)!=__EWFI_IS_GHZH_EWPN) // Filter out dummies
Expand Down

0 comments on commit 7a20dab

Please sign in to comment.