PDA

View Full Version : Attempting to Fix Ghost.zh



Tamamo
09-19-2015, 12:38 PM
First up: random rate is ignored in one of the functions. __Ghost_NewDir4 to be exact.
// Used by walk functions to pick a new direction
void __Ghost_NewDir4(int rate, int homing, int hunger)
{
int newDir=-1;
// Go for bait?
if(Rand(4)<hunger)
{
// See if any is on the screen
lweapon bait=LoadLWeaponOf(LW_BAIT);

if(bait->isValid())
{
// Found bait; try to move toward it
if(Abs(Ghost_Y-bait->Y)>14)
{
if(bait->Y<Ghost_Y)

newDir=DIR_UP;
else
newDir=DIR_DOWN;

if(__Ghost_CanMoveNES(newDir, 1, 0))
{
Ghost_Dir=newDir;
return;
}
}

if(bait->X<Ghost_X)
newDir=DIR_LEFT;
else
newDir=DIR_RIGHT;

if(__Ghost_CanMoveNES(newDir, 1, 0))
{
Ghost_Dir=newDir;
return;
}
}
} // End hunger check

// Homing?
if(Rand(256)<homing)
{
newDir=__Ghost_LinedUp(8, false);
if(newDir>=0 && __Ghost_CanMoveNES(newDir, 1, 0))
{
Ghost_Dir=newDir;
return;
}
}

// Check solidity of surrounding combos
bool combos[4];
int numDirs;
int ndir;

for(int i=0; i<4; i++)
{
if(__Ghost_CanMoveNES(i, 1, 0))
{
combos[i]=true;
// numDirs++;
}
}

int i=0;

for(; i <32; i++)
{
int r=Rand(255);

if((r&15)<rate)
ndir=(r>>4)&3;
else
ndir=Ghost_Dir;

if(combos[ndir])
break;
}

if(i==32)
{
for(ndir=0; ndir<4; ndir++)
{
if(combos[ndir])
break;
}

if(ndir==4) //Trapped
{
// if(IsSideView)
// ndir=Cond(Rand(1,DIR_LEFT,DIR_RIGHT)) //Sideview Enemies bug out if their dir becomes -1
// else
ndir=-1;
}
}

Ghost_Dir=ndir;
}

Note this hasn't been tested, since it's my second attempt this morning. This is acutely how ZC does it. So yeah a lot of shit is different from the original random direction code. Yeah the enemy code is weird. Oh yeah before I forget. In case you want to help when you got some spare time. Here's a tag. Saffith

edit: Works like a charm regardless of rate. Tested it with a normal enemy and a ghost enemy using the walk function. :thumbsup:

Next up is Dummy Weapons... ugh

Tamamo
09-19-2015, 01:27 PM
This fix was a colloborative effort and fixes the following.
1. EWF_ROTATE_360 is no longer drawn while link is dying. "tamamo"
2. Dummy weapons work now. "lejes"
3. Big EWeapons can have EWF_ROTATE_360 "saffith"

http://pastebin.com/9RZFD6VJ

Let me know if you guys have any problems.

Tamamo
09-19-2015, 01:29 PM
void Ghost_WaitframeLight(ffc this, npc ghost)
{
// Remember all the global variables

// Initializing the array is faster than setting it up afterward...
// but the difference is probably negligible, realistically
float tempGhostData[24] = {
Ghost_X, // 0
Ghost_Y, // 1
Ghost_Z, // 2
Ghost_Jump, // 3
Ghost_Vx, // 4
Ghost_Vy, // 5
Ghost_Ax, // 6
Ghost_Ay, // 7
__Ghost_PrevX, // 8
__Ghost_PrevY, // 9
Ghost_CSet, // 10
Ghost_Dir, // 11
Ghost_Data, // 12
Ghost_TileWidth, // 13
Ghost_TileHeight, // 14
__Ghost_Flags, // 15
__Ghost_Flags2, // 16
__Ghost_InternalFlags, // 17
__Ghost_FlashCounter, // 18
__Ghost_KnockbackCounter, // 19
Ghost_HP, // 20
__Ghost_XOffsets, // 21
__Ghost_YOffsets // 22
// 23 is for either drawingData or tempGhostAdditionalCombos;
// update DrawGhostFFCs if that changes
};
int tempGhostAdditionalCombos[21]; // Same size as __Ghost_AdditionalCombos
// Change it in the loop below, too
if(__Ghost_AdditionalCombos[0]>0)
{
for(int i=0; i<21; i++)
tempGhostAdditionalCombos[i]=__Ghost_AdditionalCombos[i];
}

// Give ghost an array pointer so its data can be found by other scripts
if(ghost->isValid())
ghost->Misc[__GHI_NPC_DATA]=0x10000|tempGhostData;

// Position additional FFCs, set draw data, make FFCs invisible if flickering.
do
{
if(ghost->isValid())
{
// Set up drawing array if needed. The array size depends on what
// might need drawn. If only ZScript had malloc...
if(__GH_USE_DRAWCOMBO!=0)
{
// DrawCombo and additional combos
if(__Ghost_AdditionalCombos[__GHI_AC_COUNT]>0)
{
// Array size is 4 + (__GH_AC_MAX_ADDITIONAL_COMBOS + 1) * __GHCD_DATA_SIZE
int drawData[34];
__SetUpDrawingArray(this, ghost, drawData);
tempGhostData[23]=drawData;
__HideFFCAndWait(this);
}

// DrawCombo and no additional combos
else
{
// 4 + __GHCD_DATA_SIZE
int drawData[10];
__SetUpDrawingArray(this, ghost, drawData);
tempGhostData[23]=drawData;
__HideFFCAndWait(this);
}
}
else // __GH_USE_DRAWCOMBO==0
{
// Additional combos, no DrawCombo
if(__Ghost_AdditionalCombos[__GHI_AC_COUNT]>0)
{
// 4 + __GH_AC_MAX_ADDITIONAL_COMBOS * __GHCD_DATA_SIZE
int drawData[28];
__SetUpDrawingArray(this, ghost, drawData);
tempGhostData[23]=drawData;

// Hide the FFC if the enemy is flickering.
if(__Ghost_IsFlickering(ghost) &&
(__ghzhData[__GHI_GLOBAL_FLAGS]&__GHGF_FLICKER)!=0)
__HideFFCAndWait(this);
else
Waitframe();
}

// No DrawCombo or additional combos
else
{
if(__Ghost_IsFlickering(ghost) &&
(__ghzhData[__GHI_GLOBAL_FLAGS]&__GHGF_FLICKER)==0)
__HideFFCAndWait(this);
else
Waitframe();
}
}
}
else // ghost is not valid
__HideFFCAndWait(this);

// Restore the global variables
Ghost_X=tempGhostData[0];
Ghost_Y=tempGhostData[1];
Ghost_Z=tempGhostData[2];
Ghost_Jump=tempGhostData[3];
Ghost_Vx=tempGhostData[4];
Ghost_Vy=tempGhostData[5];
Ghost_Ax=tempGhostData[6];
Ghost_Ay=tempGhostData[7];
__Ghost_PrevX=tempGhostData[8];
__Ghost_PrevY=tempGhostData[9];
Ghost_CSet=tempGhostData[10];
Ghost_Dir=tempGhostData[11];
Ghost_Data=tempGhostData[12];
Ghost_TileWidth=tempGhostData[13];
Ghost_TileHeight=tempGhostData[14];
__Ghost_Flags=tempGhostData[15];
__Ghost_Flags2=tempGhostData[16];
__Ghost_InternalFlags=tempGhostData[17];
__Ghost_FlashCounter=tempGhostData[18];
__Ghost_KnockbackCounter=tempGhostData[19];
Ghost_HP=tempGhostData[20];
__Ghost_XOffsets=tempGhostData[21];
__Ghost_YOffsets=tempGhostData[22];

if(tempGhostAdditionalCombos[0]>0)
{
for(int i=0; i<21; i++)
__Ghost_AdditionalCombos[i]=tempGhostAdditionalCombos[i];
}
else
__Ghost_AdditionalCombos[0]=0; //this is all I added

} while((__ghzhData[__GHI_GLOBAL_FLAGS]&__GHGF_SUSPEND)!=0);

if(ghost->isValid())
ghost->Misc[__GHI_NPC_DATA]=0x10000;
}

Goes in update.zh by the way. Fixes some bugs with Additional combos.

edit: whoops posted again. My mistake. Here's update 4... Custom pits.

Put this in ghost.zh
const int __GH_CUSTOM_PITS = 0;

bool __Ghost_IsPit(int combo)
{
if(__GH_CUSTOM_PITS!=0)
{
//Insert the check for a custom pit here.
//Besure you return a true/false statement
}
else
return IsPit(combo);
}

And replace line 467 in movement.zh with this.

if(__Ghost_IsPit(combo)

Saffith
10-02-2015, 07:22 PM
I know, I've been lazy. I've pretty much got this stuff done, I just have one or two more things I want to do and haven't gotten around to.

Tamamo
10-02-2015, 11:16 PM
Saffith
No honey, you haven't been lazy at all. This past week you've been working on ZC Stuff, I keep a eye on beta news my good friend. So it's all good no worries. It's just that when your scripts you write don't work. You need to debug ghost.zh and fix it yourself our wait for you patiently to be able to get around to finishing it. Being a seasoned programmer and scripter like yourself I chose the former only so I could get my Z2 enemies working in prime condition upon zscript release "1000 lines of code right there folks". Also any chance we can have EWF_FAKE_Z to. That was the one thing I couldn't figure out how to do. :/

Tamamo
10-04-2015, 12:29 PM
Saffith
So I was thinking this morning about the problem with adding EWF_FAKE_Z. And I might have an idea to make it work. Some of the misc indices are always integers and don't go that high, such as __EWI_MOVEMENT which goes to like 30 something. It might be possible to use one of those and some dark binary mathematics in order to fake implement __EWI_ZPOS without using another index. Thoughts?

Saffith
10-04-2015, 01:43 PM
I just did it with hit and draw offsets. Amusingly, although it's called fake Z, it's really using eweapon->Z and faking not using it.

Tamamo
10-04-2015, 02:01 PM
Saffith
DOH! That's how GH_FAKE_Z works! Why didn't I think of that. :thumbsup:
So what else is left?

Saffith
10-04-2015, 02:49 PM
A bit of testing and documentation.

Anarchy_Balsac
10-05-2015, 11:15 PM
I don't know if this is known or not, but it also has a nasty habit of fucking with your global variables. I tried an autoghost script today from pureZC (The Acid Handla to be Specific), but all my game's global variables reset, and didn't unreset until after I deleted not only the new code, but ghost.zh as well.

Tamamo
10-06-2015, 11:08 AM
If your using more then 256 variables that just might happen, I don't know. Never have reached that count.

Saffith
10-06-2015, 01:17 PM
If you have more than 256 global variables, your scripts won't compile.


I don't know if this is known or not, but it also has a nasty habit of fucking with your global variables. I tried an autoghost script today from pureZC (The Acid Handla to be Specific), but all my game's global variables reset, and didn't unreset until after I deleted not only the new code, but ghost.zh as well.
Did you start a new game? Adding global variables and continuing an existing save will always cause problems.

Anarchy_Balsac
10-06-2015, 01:28 PM
I have a few, but nowhere near 256. It's possible that the global script that seems to compile automatically when you include the ghost header may have enough globals to have caused the problem. But then, if that means it won't compile, then it can't be that. I do know that removing the "import "ghost.zh"" line also reversed the problem.