1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-13 16:16:08 +00:00

Decouple form specific effects from the actual form.

Most hardcoded form == FORM_* checks all over the place have been replaced.
Now, forms change certain avatar properties, which are in turn checked
in the places that previously had these explicit form checks.
This allows specifying functionality via scripting, for additional forms
with new effects or a new combination of existing effects.

OT_HURT now deals damage of type DT_WALLHURT,
and by setting avatar->setDamageTarget(DT_WALLHURT, false) collision
with walls can be made harmless (exactly as nature form used to be).

Add related Lua functions:
+ setWorldType() - Change WT without actually switching to spirit form
+ setCanActivate()
+ avatar_setCanBurst()
+ avatar_canBurst()
+ avatar_setCanLockToWall()
+ avatar_canLockToWall()
+ avatar_setCanSwimAgainstCurrents()
+ avatar_canSwimAgainstCurrents()
+ getSceneColor()
+ DT_WALLHURT
This commit is contained in:
fgenesis 2013-04-26 00:34:06 +02:00
parent 55ead19076
commit e8a7889f82
7 changed files with 124 additions and 47 deletions

View file

@ -744,7 +744,7 @@ void Avatar::toggleMovement(bool on)
bool Avatar::isLockable()
{
return (bursting || !_isUnderWater) && (boneLockDelay == 0) && (dsq->continuity.form != FORM_FISH);
return (bursting || !_isUnderWater) && (boneLockDelay == 0) && canLockToWall();
}
bool Avatar::isSinging()
@ -1590,6 +1590,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF
//rotationOffset.interpolateTo(Vector(0,0,0), 0.5);
collideRadius = COLLIDE_RADIUS_NORMAL;
setCanLockToWall(true);
}
break;
case FORM_SUN:
@ -1601,9 +1602,13 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF
position = bodyPosition;
dsq->continuity.warpLiToAvatar();
spiritBeaconEmitter.start();
setCanActivateStuff(true);
setCanLockToWall(true);
setCanBurst(true);
setDamageTarget(DT_WALLHURT, true);
break;
case FORM_BEAST:
//dsq->game->sceneColor3.interpolateTo(Vector(1, 1, 1), 0.5);
setCanSwimAgainstCurrents(false);
break;
case FORM_DUAL:
if (dsq->continuity.hasLi())
@ -1613,6 +1618,9 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF
dsq->game->li->setState(STATE_IDLE);
}
break;
case FORM_NATURE:
setDamageTarget(DT_WALLHURT, true);
break;
default:
if (leftHandEmitter && rightHandEmitter)
{
@ -1722,6 +1730,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF
//refreshModel("NaijaFish", "");
collideRadius = COLLIDE_RADIUS_FISH;
setCanLockToWall(false);
}
break;
case FORM_SUN:
@ -1753,42 +1762,13 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF
hair->setTexture("Naija/Cape-NatureForm");
hair->alphaMod = 1.0;
}
/*
skeletalSprite.loadSkin("ChildTeira");
refreshModel();
*/
/*
if (dsq->game->sceneNatureForm == "forest")
{
debugLog("Forest Form");
dsq->continuity.form = FORM_NATURE_FOREST;
}
else if (dsq->game->sceneNatureForm == "sun")
{
dsq->continuity.form = FORM_NATURE_SUN;
debugLog("Sun Form");
}
else if (dsq->game->sceneNatureForm == "fire")
{
dsq->continuity.form = FORM_NATURE_FIRE;
debugLog("Fire Form");
}
else if (dsq->game->sceneNatureForm == "dark")
{
dsq->continuity.form = FORM_NATURE_DARK;
debugLog("Dark Form");
}
else if (dsq->game->sceneNatureForm == "rock" || dsq->game->sceneNatureForm.empty())
{
dsq->continuity.form = FORM_NATURE_ROCK;
debugLog("Rock Form");
}
*/
setDamageTarget(DT_WALLHURT, false);
break;
case FORM_BEAST:
{
refreshModel("Naija", "BeastForm");
setCanSwimAgainstCurrents(true);
}
break;
case FORM_SPIRIT:
@ -1796,6 +1776,10 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF
bodyOffset = offset;
fallOffWall();
dsq->continuity.shiftWorlds();
setCanActivateStuff(false);
setCanLockToWall(false);
setCanBurst(false);
setDamageTarget(DT_WALLHURT, false);
if (onInit)
{
@ -3490,8 +3474,8 @@ void Avatar::lockToWallCommon()
void Avatar::lockToWall()
{
if (riding) return;
if (inCurrent && dsq->continuity.form != FORM_BEAST) return;
if (dsq->continuity.form == FORM_FISH || dsq->continuity.form == FORM_SPIRIT) return;
if (inCurrent && !canSwimAgainstCurrents()) return;
if (!canLockToWall()) return;
if (state.lockedToWall) return;
if (vel.x == 0 && vel.y == 0) return;
if (dsq->game->isPaused()) return;
@ -3589,7 +3573,7 @@ void Avatar::lockToWall()
}
}
if (dsq->game->getGrid(t)==OT_HURT && dsq->continuity.form != FORM_NATURE)
if (dsq->game->getGrid(t)==OT_HURT && isDamageTarget(DT_WALLHURT))
{
good = false;
}
@ -4123,6 +4107,12 @@ Avatar::Avatar() : Entity(), ActionMapper()
collideRadius = COLLIDE_RADIUS_FISH;
else
collideRadius = COLLIDE_RADIUS_NORMAL;
// defaults for normal form
_canActivateStuff = true;
_canBurst = true;
_canLockToWall = true;
_canSwimAgainstCurrents = false;
}
void Avatar::revert()
@ -4319,7 +4309,7 @@ void Avatar::startBurstCommon()
void Avatar::startBurst()
{
if (!riding && dsq->continuity.form != FORM_SPIRIT && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE))
if (!riding && canBurst() && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE))
&& getState() != STATE_PUSH && (!skeletalSprite.getCurrentAnimation() || (skeletalSprite.getCurrentAnimation()->name != "spin"))
&& _isUnderWater && !isActing(ACTION_ROLL))
{
@ -5409,7 +5399,12 @@ void Avatar::setWasUnderWater()
bool Avatar::canActivateStuff()
{
return dsq->continuity.form != FORM_SPIRIT;
return _canActivateStuff;
}
void Avatar::setCanActivateStuff(bool on)
{
_canActivateStuff = on;
}
bool Avatar::canQuickSong()
@ -7142,7 +7137,6 @@ void Avatar::onUpdate(float dt)
else
omov -= mov;
lastLastPosition = position;
lastPosition = position;
Vector newPosition = position + mov;
//Vector testPosition = position + (vel *dt)*2;
@ -7151,11 +7145,11 @@ void Avatar::onUpdate(float dt)
if (dsq->game->collideCircleWithGrid(position, collideRadius))
{
if (dsq->game->lastCollideTileType == OT_HURT
&& !dsq->game->isWorldPaused()
&& dsq->continuity.form != FORM_NATURE)
&& isDamageTarget(DT_WALLHURT))
{
DamageData d;
d.damage = 1;
d.damageType = DT_WALLHURT;
damage(d);
vel2 = Vector(0,0,0);
//doCollisionAvoidance(1, 3, 1);
@ -7338,7 +7332,7 @@ void Avatar::checkNearWall()
{
t.x = oT.x + v.x*i;
t.y = oT.y + v.y*i;
if (dsq->game->isObstructed(t) && dsq->game->getGrid(t) != OT_HURT)
if (dsq->game->isObstructed(t, ~OT_HURT))
{
obs = true;
break;

View file

@ -283,6 +283,7 @@ public:
void endOfGameState();
bool canQuickSong();
bool canActivateStuff();
void setCanActivateStuff(bool on);
bool hasThingToActivate();
float biteTimer;
@ -319,6 +320,15 @@ public:
void doBindSong();
void doShieldSong();
bool canBurst() const { return _canBurst; }
void setCanBurst(bool b) { _canBurst = b; }
bool canLockToWall() const { return _canLockToWall; }
void setCanLockToWall(bool b) { _canLockToWall = b; }
bool canSwimAgainstCurrents() const { return _canSwimAgainstCurrents; }
void setCanSwimAgainstCurrents(bool b) { _canSwimAgainstCurrents = b; }
int leaches;
protected:
@ -451,7 +461,10 @@ protected:
void lockToWall();
void doShock(const std::string &shotName);
Vector lastLastPosition;
bool _canActivateStuff;
bool _canBurst;
bool _canLockToWall;
bool _canSwimAgainstCurrents;
};

View file

@ -2024,7 +2024,7 @@ void Continuity::applyWorldEffects(WorldType type, bool transition, bool affectM
dsq->game->avatar->enableInput();
*/
}
//worldType = type;
worldType = type;
}
void Continuity::eatBeast(const EatData &eatData)

View file

@ -4564,6 +4564,10 @@ void DSQ::onUpdate(float dt)
os << " headRot: " << b->rotation.z;
os << std::endl;
os << "fh: " << dsq->game->avatar->isfh() << " fv: " << dsq->game->avatar->isfv() << std::endl;
os << "canActivate: " << dsq->game->avatar->canActivateStuff();
os << " canBurst: " << dsq->game->avatar->canBurst();
os << " canLTW: " << dsq->game->avatar->canLockToWall();
os << " canSAC: " << dsq->game->avatar->canSwimAgainstCurrents() << std::endl;
}
// DO NOT CALL AVATAR-> beyond this point

View file

@ -1419,7 +1419,7 @@ bool Entity::updateCurrents(float dt)
float useLen = len;
if (useLen < 500)
useLen = 500;
if (!(this->getEntityType() == ET_AVATAR && dsq->continuity.form == FORM_BEAST && dsq->game->avatar->bursting))
if (!(this->getEntityType() == ET_AVATAR && dsq->game->avatar->canSwimAgainstCurrents() && dsq->game->avatar->bursting))
{
doCollisionAvoidance(1, 4, 1, &vel2, useLen);
}
@ -1439,7 +1439,7 @@ bool Entity::updateCurrents(float dt)
}
}
}
if (this->getEntityType() == ET_AVATAR && dsq->continuity.form == FORM_BEAST)
if (this->getEntityType() == ET_AVATAR && dsq->game->avatar->canSwimAgainstCurrents())
{
int cap = 100;
if (!vel.isZero())

View file

@ -123,6 +123,7 @@ enum DamageType
DT_CRUSH = 1032,
DT_SPIKES = 1033,
DT_STEAM = 1034,
DT_WALLHURT = 1035,
DT_REALMAX
};

View file

@ -1580,6 +1580,7 @@ luaFunc(quad_setSegs)
RO_FUNC(getter, prefix, disableMotionBlur ) \
RO_FUNC(getter, prefix, collideCircleVsLine) \
RO_FUNC(getter, prefix, collideCircleVsLineAngle) \
RO_FUNC(getter, prefix, getVectorToObj ) \
MK_ALIAS(prefix, fh, flipHorizontal ) \
MK_ALIAS(prefix, fv, flipVertical )
@ -2352,6 +2353,14 @@ luaFunc(getWorldType)
luaReturnNum((int)dsq->continuity.getWorldType());
}
luaFunc(setWorldType)
{
WorldType wt = (WorldType)lua_tointeger(L, 1);
bool trans = getBool(L, 2);
dsq->continuity.applyWorldEffects(wt, trans, 1); // last arg is not used
luaReturnNil();
}
luaFunc(isWorldPaused)
{
luaReturnBool(dsq->game->isWorldPaused());
@ -2709,6 +2718,47 @@ luaFunc(avatar_setCanDie)
luaReturnNil();
}
// not naming this avatar_* because it rather belongs into the UI category...
luaFunc(setCanActivate)
{
dsq->game->avatar->setCanActivateStuff(getBool(L, 1));
luaReturnNil();
}
luaFunc(avatar_setCanBurst)
{
dsq->game->avatar->setCanBurst(getBool(L, 1));
luaReturnNil();
}
luaFunc(avatar_canBurst)
{
luaReturnBool(dsq->game->avatar->canBurst());
}
luaFunc(avatar_setCanLockToWall)
{
dsq->game->avatar->setCanBurst(getBool(L, 1));
luaReturnNil();
}
luaFunc(avatar_canLockToWall)
{
luaReturnBool(dsq->game->avatar->canBurst());
}
luaFunc(avatar_setCanSwimAgainstCurrents)
{
dsq->game->avatar->setCanSwimAgainstCurrents(getBool(L, 1));
luaReturnNil();
}
luaFunc(avatar_canSwimAgainstCurrents)
{
luaReturnBool(dsq->game->avatar->canSwimAgainstCurrents());
}
luaFunc(avatar_toggleCape)
{
dsq->game->avatar->toggleCape(getBool(L,1));
@ -3773,6 +3823,12 @@ luaFunc(setSceneColor)
luaReturnNil();
}
luaFunc(getSceneColor)
{
const Vector& c = dsq->game->sceneColor3;
luaReturnVec3(c.x, c.y, c.z);
}
luaFunc(setCameraLerpDelay)
{
dsq->game->cameraLerpDelay = lua_tonumber(L, 1);
@ -7626,6 +7682,7 @@ static const struct {
luaRegister(getNoteName),
luaRegister(getWorldType),
luaRegister(setWorldType),
luaRegister(setWorldPaused),
luaRegister(isWorldPaused),
@ -7704,9 +7761,16 @@ static const struct {
luaRegister(avatar_setCanDie),
luaRegister(setCanActivate),
luaRegister(avatar_toggleCape),
luaRegister(avatar_setPullTarget),
luaRegister(avatar_setCanLockToWall),
luaRegister(avatar_canLockToWall),
luaRegister(avatar_setCanBurst),
luaRegister(avatar_canBurst),
luaRegister(avatar_setCanSwimAgainstCurrents),
luaRegister(avatar_canSwimAgainstCurrents),
luaRegister(avatar_clampPosition),
luaRegister(avatar_updatePosition),
@ -8318,7 +8382,7 @@ static const struct {
luaRegister(setSceneColor),
luaRegister(getSceneColor),
luaRegister(entity_watchEntity),
@ -9129,6 +9193,7 @@ static const struct {
luaConstant(DT_CRUSH),
luaConstant(DT_SPIKES),
luaConstant(DT_STEAM),
luaConstant(DT_WALLHURT),
luaConstant(FRAME_TIME),