PDA

View Full Version : How to set the warp return point?



ZoriaRPG
12-14-2016, 12:43 AM
I tried a few things, and I'm coming up short.


Does wrindex=(tmpscr->warpreturnc>>(8+(index*2)))&3; not set the return square by using an index of 0 to 3, where those are the valid warp returns?
For that matter, what is the intent of this:

>>(8+(index*2)))&3

There are no code comments to explain what is going on with this...so tat I know what the appropriate values might be.


What I have now, is this:




//added public vars
int warpretsq; //Used as tmpscr[t].sidewarp*[warpretsq];
and
bool isscriptedwarp;
//to link.h

//Added a setter/getter pair both to link.h and link.cpp. The functions for LinkClass are:

//
void LinkClass::setWarpReturnSquare(int sq)
{
warpretsq=vbound(sq,0,3);

}

int LinkClass::getWarpReturnSquare()
{
return warpretsq;
}

void LinkClass::setWarpReturnSquare(int sq)
{
warpretsq=vbound(sq,0,3);

}

bool LinkClass::getScriptedWarp(){

return isscriptedwarp;
}

void LinkClass::setScriptedWarp(bool v){

isscriptedwarp = v;
}


Obviously, I added a setter to select warpretsq to ZScript. This part works. (Setting, and getting it.)

isscripted warp is a flag that I might use if it comes down to it and this needs wholly special conditions.
//Added some routines to dowarp(int, int)



//in dowarp() link.cpp
case 1: // side warp
wtype = tmpscr[t].sidewarptype[index];
wdmap = tmpscr[t].sidewarpdmap[index];
wscr = tmpscr[t].sidewarpscr[index];
overlay = get_bit(&tmpscr[t].sidewarpoverlayflags,index)?1:0;
wrindex=(tmpscr->warpreturnc>>(8+(index*2)))&3;
Z_message("Warp Return is (index, warpreturnc,sum wrindex)\n", index, tmpscr->warpreturnc, wrindex);
Z_scripterrlog("index: \n", index);
Z_scripterrlog("tmpscr->warpreturnc: \n", tmpscr->warpreturnc);
Z_scripterrlog("wrindex: \n", wrindex);
break;

case wtIWARP:
case wtIWARPBLK:
case wtIWARPOPEN:
case wtIWARPZAP:
case wtIWARPWAVE: // insta-warps
{
//for determining whether to exit cave
int type1 = combobuf[MAPCOMBO(x,y-16)].type;
int type2 = combobuf[MAPCOMBO(x,y)].type;
int type3 = combobuf[MAPCOMBO(x,y+16)].type;

bool cavewarp = ((type1==cCAVE)||(type1>=cCAVEB && type1<=cCAVED) || (type2==cCAVE)||(type2>=cCAVEB && type2<=cCAVED)
||(type3==cCAVE2)||(type3>=cCAVE2B && type3<=cCAVE2D) || (type2==cCAVE2)||(type2>=cCAVE2B && type2<=cCAVE2D));

if(!(tmpscr->flags3&fIWARPFULLSCREEN))
{
//ALLOFF kills the action, but we want to preserve Link's action if he's swimming or diving -DD
bool wasswimming = (action == swimming);
byte olddiveclk = diveclk;
ALLOFF();

if(wasswimming)
{
action = swimming;
diveclk = olddiveclk;
}

kill_sfx();
if ( warpsound > 0 && getPlayLinkWarpSound() !=0 ) {
sfx(warpsound);
setPlayLinkWarpSound(false);
}
}

if(wtype==wtIWARPZAP)
{
zapout();
}
else if(wtype==wtIWARPWAVE)
{
//only draw Link if he's not in a cave -DD
wavyout(!cavewarp);
}
else if(wtype!=wtIWARP)
{
bool b2 = COOLSCROLL&&cavewarp;
blackscr(30,b2?false:true);
}

int c = DMaps[currdmap].color;
currdmap = wdmap;
dlevel = DMaps[currdmap].level;
currmap = DMaps[currdmap].map;
init_dmap();
update_subscreens(wdmap);

ringcolor(false);

if(DMaps[currdmap].color != c)
loadlvlpal(DMaps[currdmap].color);

homescr = currscr = wscr + DMaps[currdmap].xoff;

lightingInstant(); // Also sets naturaldark

loadscr(0,currdmap,currscr,-1,overlay);

x = tmpscr->warpreturnx[wrindex];



!Note that we get this variable from:
wrindex=(tmpscr->warpreturnc>>(8+(index*2)))&3;

This gets its 'index' value from the new var: warpretsq

So, this ultimately becomes

wrindex=(tmpscr->warpreturnc>>(8+(warpretsq*2)))&3;
x = tmpscr->warpreturnx[wrindex];

If I set warpretsq to '3, it becomes

wrindex=(tmpscr->warpreturnc>>(8+(3*2)))&3;
x = tmpscr->warpreturnx[wrindex];
y = tmpscr->warpreturny[wrindex];

Why the deuce is this not working?!

...continuing the warp function code...



y = tmpscr->warpreturny[wrindex];

if(didpit)
{
didpit=false;
x=pitx;
y=pity;
}

type1 = combobuf[MAPCOMBO(x,y-16)].type;
type2 = combobuf[MAPCOMBO(x,y)].type;
type3 = combobuf[MAPCOMBO(x,y+16)].type;

if(x==0) dir=right;

if(x==240) dir=left;

if(y==0) dir=down;

if(y==160) dir=up;

markBmap(dir^1);

if(iswater(MAPCOMBO(x,y+8)) && _walkflag(x,y+8,0) && current_item(itype_flippers))
{
hopclk=0xFF;
attackclk = charging = spins = 0;
action=swimming;
}
else
action = none;

//preloaded freeform combos
ffscript_engine(true);

putscr(scrollbuf,0,0,tmpscr);
putscrdoors(scrollbuf,0,0,tmpscr);

if((type1==cCAVE)||(type1>=cCAVEB && type1<=cCAVED) || (type2==cCAVE)||(type2>=cCAVEB && type2<=cCAVED))
{
reset_pal_cycling();
putscr(scrollbuf,0,0,tmpscr);
putscrdoors(scrollbuf,0,0,tmpscr);
walkup(COOLSCROLL);
}
else if((type3==cCAVE2)||(type3>=cCAVE2B && type3<=cCAVE2D) || (type2==cCAVE2)||(type2>=cCAVE2B && type2<=cCAVE2D))
{
reset_pal_cycling();
putscr(scrollbuf,0,0,tmpscr);
putscrdoors(scrollbuf,0,0,tmpscr);
walkdown2(COOLSCROLL);
}
else if(wtype==wtIWARPZAP)
{
zapin();
}
else if(wtype==wtIWARPWAVE)
{
wavyin();
}
else if(wtype==wtIWARPOPEN)
{
openscreen();
}

show_subscreen_life=true;
show_subscreen_numbers=true;
playLevelMusic();
currcset=DMaps[currdmap].color;
dointro();
setEntryPoints(x,y);
}
break;




Why is this not having the expected results?!

The desired outcome is:

Link->SetWarpReturn = 3; //Set to Warp Return C
Link->Warp(dmap,screen); //Warps to dmap, screen, warp return 3

Saffith
12-14-2016, 01:26 AM
warpreturnc is return index 0-3 for all 8 warps. Each one gets two bits.
0-1: Tile warp A
2-3: Tile warp B
...
14-15: Side warp D

There's no reason to deal with that. You would just need

x = tmpscr->warpreturnx[warpretsq];
y = tmpscr->warpreturny[warpretsq];

Why not make the return an optional third argument to Link->Warp() instead of a separate function?

ZoriaRPG
12-14-2016, 05:10 AM
warpreturnc is return index 0-3 for all 8 warps. Each one gets two bits.
0-1: Tile warp A
2-3: Tile warp B
...
14-15: Side warp D

There's no reason to deal with that. You would just need

x = tmpscr->warpreturnx[warpretsq];
y = tmpscr->warpreturny[warpretsq];


Aye, that certainly worked, and did the job.




Why not make the return an optional third argument to Link->Warp() instead of a separate function?


My reasons...

Gleeok expressly told me that it would be better to add new functions, than to modify or overload existing ones.

Replacing Link->Warp(int, int) with Link->Warp(int, int, int, ...) would break existing scripts, and probably quests.

Overloading a ZASM instruction and making redirects is a bloody pain...

What I did, is add in Link->WarpReturnSquare, int Link->WarpEffect, int Link->WarpSound, bool Link->PlayWarpSound

int WarpEffect allows setting an effect for a Link->Warp, or Link->PitWarp. This is andled with a switch-case, so only valid types do things differently.
int WarpSound, if set to > 0 allows playing a sound when warping. I expressly forbid this during sidewarps, and I probably need to vbound it.
bool PlayWarpSound is a flag that the user may toggle to allow a warp sound during a sidewarp. I need to rename it to SideWarpSound.

While I was at it, I plugged in Screen->ZapIn(), Screen->ZapOut, Screen->WavyIn(), Screen->WavyOut, and Screen->OpeningWipe
These allow replicating the in-build warp animations on demand, without warping. Could be useful. I know that I wanted to do that in the past for an effect, as did one of the other scripters.

Meanwhile, Dimentio added SCC warp codes for Link, that also use these variables, so it isn't only for one thing.

Thankfully, all of these new ZScript things work, and I've been doing bug testing. Thus far, the only bugs that I was unable to kill, are caused by the SCC warp. I also patched in an SCC for setting Screen->D, while I was working with Dimentio. This felt natural, given that there is one to read it.

Anyway...thank you Saffith for clarifying this.

P.S. Don't fret.I used intermediate handlers for allof this, rather than directly tying anything to a class variable.

Edit:

If you want to look at, or try out anything:
Sources (http://timelord.insomnia247.nl/zc/zc_dev/ZC_2.54_Sources_Beta_21.zip) | Windows Binaries (http://timelord.insomnia247.nl/zc/zc_dev/ZC_2.54_Beta_21.zip)

LinkClass::dowarp() is such a mess that I may just rewrite some parts of it to segregate normal, pit, and other warping.