forked from Mirrors/openclonk
Changed SimFlight behavior
SimFlight now returns the array [x, y, xdir, ydir, steps_taken] instead of trying to modify parameters.To preserve old functionality, steps_taken will be negative if it doesn't hit anything before time runs out.floating-point
parent
0ec10db0bf
commit
854483bf27
|
@ -1237,7 +1237,7 @@ func StartJump()
|
|||
SetTurnType(0);
|
||||
// TODO: make dive animation and uncomment here
|
||||
// var iX=GetX(),iY=GetY(),iXDir=GetXDir(),iYDir=GetYDir();
|
||||
// if (SimFlight(iX,iY,iXDir,iYDir,25))
|
||||
// if (SimFlight(iX,iY,iXDir,iYDir,25)) // SimFlight behavior changed. (10/1/10)
|
||||
// if (GBackLiquid(iX-GetX(),iY-GetY()) && GBackLiquid(iX-GetX(),iY+GetDefHeight()/2-GetY()))
|
||||
// PlayAnimation("Dive", 5, Anim_Linear(0, 0, GetAnimationLength("Dive"), 8*3, ANIM_Hold), Anim_Linear(0, 0, 1000, 5, ANIM_Remove));;
|
||||
AddEffect("Fall",this,1,1,this);
|
||||
|
|
|
@ -312,7 +312,7 @@ func GetJumpLength(pClonk)
|
|||
{
|
||||
if(!pClonk->~IsJumping()) return 0;
|
||||
var x = pClonk->GetX(), y = pClonk->GetY(), xDir = pClonk->GetXDir(), yDir = pClonk->GetYDir();
|
||||
//crash! var l=SimFlight(x, y, xDir, yDir, 0, 0, 100, 0);
|
||||
//crash! var l=SimFlight(x, y, xDir, yDir, 0, 0, 100, 0); //SimFlight behavior changed (10/1/10)
|
||||
var l=0;
|
||||
if(!l) return 50;
|
||||
else
|
||||
|
|
|
@ -601,14 +601,16 @@ bool C4Object::ExecMovement() // Every Tick1 by Execute
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t iIter)
|
||||
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter)
|
||||
{
|
||||
bool hitOnTime = true;
|
||||
bool fBreak = false;
|
||||
int32_t ctcox,ctcoy,cx,cy;
|
||||
int32_t ctcox,ctcoy,cx,cy,i;
|
||||
cx = fixtoi(x); cy = fixtoi(y);
|
||||
i = iIter;
|
||||
do
|
||||
{
|
||||
if (!iIter--) return false;
|
||||
if (!--i) {hitOnTime = false; break;}
|
||||
// Set target position by momentum
|
||||
x+=xdir; y+=ydir;
|
||||
// Movement to target
|
||||
|
@ -631,18 +633,23 @@ bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensit
|
|||
while (!fBreak);
|
||||
// write position back
|
||||
x = itofix(cx); y = itofix(cy);
|
||||
// ok
|
||||
return true;
|
||||
|
||||
// how many steps did it take to get here?
|
||||
i = iIter - i;
|
||||
iIter = i;
|
||||
|
||||
return hitOnTime;
|
||||
}
|
||||
|
||||
bool SimFlightHitsLiquid(C4Real fcx, C4Real fcy, C4Real xdir, C4Real ydir)
|
||||
{
|
||||
// Start in water?
|
||||
int temp;
|
||||
if (DensityLiquid(GBackDensity(fixtoi(fcx), fixtoi(fcy))))
|
||||
if (!SimFlight(fcx, fcy, xdir, ydir, 0, C4M_Liquid - 1, 10))
|
||||
if (!SimFlight(fcx, fcy, xdir, ydir, 0, C4M_Liquid - 1, temp=10))
|
||||
return false;
|
||||
// Hits liquid?
|
||||
if (!SimFlight(fcx, fcy, xdir, ydir, C4M_Liquid, 100, -1))
|
||||
if (!SimFlight(fcx, fcy, xdir, ydir, C4M_Liquid, 100, temp=-1))
|
||||
return false;
|
||||
// liquid & deep enough?
|
||||
return GBackLiquid(fixtoi(fcx), fixtoi(fcy)) && GBackLiquid(fixtoi(fcx), fixtoi(fcy) + 9);
|
||||
|
|
|
@ -4649,40 +4649,44 @@ static bool FnSetObjDrawTransform2(C4AulObjectContext *ctx, long iA, long iB, lo
|
|||
return true;
|
||||
}
|
||||
|
||||
#define COPY_C4V_PAR(Var, Par, ParType, Std) \
|
||||
Var = (Par && Par->GetType() == ParType \
|
||||
? Par->GetData().Int \
|
||||
: Std)
|
||||
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t &iIter);
|
||||
|
||||
bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensityMin, int32_t iDensityMax, int32_t iIter);
|
||||
|
||||
static C4Value FnSimFlight(C4AulContext *ctx, C4Value *pvrX, C4Value *pvrY, C4Value *pvrXDir, C4Value *pvrYDir, C4Value *pviDensityMin, C4Value *pviDensityMax, C4Value *pviIter, C4Value *pviPrec)
|
||||
static C4ValueArray* FnSimFlight(C4AulContext *ctx, int X, int Y, Nillable<int> pvrXDir, Nillable<int> pvrYDir, Nillable<int> pviDensityMin, Nillable<int> pviDensityMax, Nillable<int> pviIter, int iPrec)
|
||||
{
|
||||
// check and copy parameters
|
||||
if (!pvrX || !pvrY || !pvrXDir || !pvrYDir) return C4VFalse;
|
||||
// check and set parameters
|
||||
if (ctx->Obj)
|
||||
{
|
||||
X += ctx->Obj->GetX();
|
||||
Y += ctx->Obj->GetY();
|
||||
}
|
||||
int XDir = pvrXDir.IsNil() && ctx->Obj ? fixtoi(ctx->Obj->xdir) : pvrXDir;
|
||||
int YDir = pvrXDir.IsNil() && ctx->Obj ? fixtoi(ctx->Obj->ydir) : pvrYDir;
|
||||
|
||||
COPY_C4V_PAR(int iDensityMin, pviDensityMin, C4V_Int, C4M_Solid);
|
||||
COPY_C4V_PAR(int iDensityMax, pviDensityMax, C4V_Int, 100);
|
||||
COPY_C4V_PAR(int iIter, pviIter, C4V_Int, -1);
|
||||
COPY_C4V_PAR(int iPrec, pviPrec, C4V_Int, 10);
|
||||
int iDensityMin = pviDensityMin.IsNil() ? C4M_Solid : pviDensityMin;
|
||||
int iDensityMax = pviDensityMax.IsNil() ? 100 : pviDensityMax;
|
||||
int iIter = pviIter.IsNil() ? -1 : pviIter;
|
||||
if (!iPrec) iPrec = 10;
|
||||
|
||||
// convert to C4Real
|
||||
C4Real x = itofix(pvrX->GetData().Int), y = itofix(pvrY->GetData().Int),
|
||||
xdir = itofix(pvrXDir->GetData().Int, iPrec), ydir = itofix(pvrYDir->GetData().Int, iPrec);
|
||||
C4Real x = itofix(X), y = itofix(Y),
|
||||
xdir = itofix(XDir, iPrec), ydir = itofix(YDir, iPrec);
|
||||
|
||||
// simulate
|
||||
if (!SimFlight(x, y, xdir, ydir, iDensityMin, iDensityMax, iIter))
|
||||
return C4VFalse;
|
||||
{
|
||||
iIter *= -1;
|
||||
}
|
||||
|
||||
// write results to array
|
||||
C4ValueArray *pResults = new C4ValueArray(4);
|
||||
C4ValueArray *pResults = new C4ValueArray(5);
|
||||
pResults->SetItem(0, C4VInt(fixtoi(x)));
|
||||
pResults->SetItem(1, C4VInt(fixtoi(y)));
|
||||
pResults->SetItem(2, C4VInt(fixtoi(xdir * iPrec)));
|
||||
pResults->SetItem(3, C4VInt(fixtoi(ydir * iPrec)));
|
||||
return C4VArray(pResults);
|
||||
pResults->SetItem(4, C4VInt(iIter));
|
||||
return pResults;
|
||||
}
|
||||
#undef COPY_C4V_PAR
|
||||
|
||||
static bool FnSetPortrait(C4AulObjectContext *ctx, C4String *pstrPortrait, C4ID idSourceDef, bool fPermanent, bool fCopyGfx)
|
||||
{
|
||||
// safety
|
||||
|
@ -6301,6 +6305,7 @@ void InitFunctionMap(C4AulScriptEngine *pEngine)
|
|||
AddFunc(pEngine, "RemoveUnusedTexMapEntries", FnRemoveUnusedTexMapEntries, false);
|
||||
AddFunc(pEngine, "SetObjDrawTransform", FnSetObjDrawTransform);
|
||||
AddFunc(pEngine, "SetObjDrawTransform2", FnSetObjDrawTransform2, false);
|
||||
AddFunc(pEngine, "SimFlight", FnSimFlight);
|
||||
AddFunc(pEngine, "SetPortrait", FnSetPortrait);
|
||||
AddFunc(pEngine, "LoadScenarioSection", FnLoadScenarioSection, false);
|
||||
AddFunc(pEngine, "SetObjectStatus", FnSetObjectStatus, false);
|
||||
|
@ -6798,7 +6803,6 @@ C4ScriptFnDef C4ScriptFnMap[]=
|
|||
{ "GetPlrExtraData", 1 ,C4V_Any ,{ C4V_Int ,C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any} ,MkFnC4V FnGetPlrExtraData, 0 },
|
||||
{ "SetCrewExtraData", 1 ,C4V_Any ,{ C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any} ,MkFnC4V FnSetCrewExtraData, 0 },
|
||||
{ "GetCrewExtraData", 1 ,C4V_Any ,{ C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any} ,MkFnC4V FnGetCrewExtraData, 0 },
|
||||
{ "SimFlight", 1 ,C4V_Bool ,{ C4V_Int ,C4V_Int ,C4V_Int ,C4V_Int ,C4V_Int ,C4V_Int ,C4V_Int ,C4V_Int ,C4V_Any ,C4V_Any} ,MkFnC4V FnSimFlight, 0 },
|
||||
{ "GetPortrait", 1 ,C4V_Any ,{ C4V_C4Object,C4V_Bool ,C4V_Bool ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any} ,MkFnC4V FnGetPortrait, 0 },
|
||||
{ "AddEffect", 1 ,C4V_Int ,{ C4V_String ,C4V_C4Object,C4V_Int ,C4V_Int ,C4V_C4Object,C4V_PropList,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any} ,MkFnC4V FnAddEffect_C4V, 0 },
|
||||
{ "GetEffect", 1 ,C4V_Any ,{ C4V_String ,C4V_C4Object,C4V_Int ,C4V_Int ,C4V_Int ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any} ,MkFnC4V FnGetEffect_C4V, 0 },
|
||||
|
|
Loading…
Reference in New Issue