1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-03 18:14:01 +00:00

Add support for below-maxspeed shots

The game used to unconditionally enforce shots to go at close to their max speed;
it is now possible to turn that behavior off if needed:
In a shot txt file, set AlwaysMaxSpeed = 0

New Lua functions:
+ shot_setAlwaysMaxSpeed()
+ shot_isAlwaysMaxSpeed
This commit is contained in:
fgenesis 2022-10-12 18:58:48 +02:00
parent cc1530b5e5
commit 0469ab8dfb
3 changed files with 65 additions and 50 deletions

View file

@ -2614,6 +2614,19 @@ luaFunc(shot_canHitEntity)
luaReturnBool(hit);
}
luaFunc(shot_setAlwaysMaxSpeed)
{
if(Shot *shot = getShot(L))
shot->alwaysMaxSpeed = getBool(L, 2);
luaReturnNil();
}
luaFunc(shot_isAlwaysMaxSpeed)
{
Shot *shot = getShot(L);
luaReturnBool(shot && shot->alwaysMaxSpeed);
}
typedef std::pair<Shot*, float> ShotDistancePair;
static std::vector<ShotDistancePair> filteredShots(20);
@ -10602,6 +10615,8 @@ static const struct {
luaRegister(shot_setTargetPoint),
luaRegister(shot_getTargetPoint),
luaRegister(shot_canHitEntity),
luaRegister(shot_setAlwaysMaxSpeed),
luaRegister(shot_isAlwaysMaxSpeed),
luaRegister(filterNearestShots),
luaRegister(filterNearestShotsAdd),
luaRegister(getNextFilteredShot),

View file

@ -67,6 +67,7 @@ ShotData::ShotData()
rotateToVel = 1;
waveSpeed = waveMag = 0;
ignoreShield = false;
alwaysMaxSpeed = true;
}
template <typename T> void readEquals2(T &in)
@ -246,6 +247,8 @@ void ShotData::bankLoad(const std::string &file, const std::string &path)
inf >> ignoreShield;
else if (token == "DieOnKill")
inf >> dieOnKill;
else if (token == "AlwaysMaxSpeed")
inf >> alwaysMaxSpeed;
else
{
// if having weirdness, check for these
@ -353,54 +356,54 @@ void Shot::loadBankShot(const std::string &ident, Shot *setter)
std::string id = ident;
stringToLower(id);
setter->applyShotData(&shotBank[id]);
ShotBank::const_iterator it = shotBank.find(id);
if(it != shotBank.end())
setter->applyShotData(it->second);
}
}
void Shot::applyShotData(ShotData *shotData)
void Shot::applyShotData(const ShotData& shotData)
{
if (shotData)
this->shotData = &shotData;
this->setBlendType(shotData.blendType);
this->homingness = shotData.homing;
this->maxSpeed = shotData.maxSpeed;
this->setTexture(shotData.texture);
this->scale = shotData.scale;
this->lifeTime = shotData.lifeTime;
this->collideRadius = shotData.collideRadius;
this->renderQuad = !shotData.invisible;
this->gravity = shotData.gravity;
this->damageType = shotData.damageType;
this->checkDamageTarget = shotData.checkDamageTarget;
this->alwaysMaxSpeed = shotData.alwaysMaxSpeed;
if (!shotData.trailPrt.empty())
{
this->shotData = shotData;
this->setBlendType(shotData->blendType);
this->homingness = shotData->homing;
this->maxSpeed = shotData->maxSpeed;
this->setTexture(shotData->texture);
this->scale = shotData->scale;
this->lifeTime = shotData->lifeTime;
this->collideRadius = shotData->collideRadius;
this->renderQuad = !shotData->invisible;
this->gravity = shotData->gravity;
this->damageType = shotData->damageType;
this->checkDamageTarget = shotData->checkDamageTarget;
if (!shotData->trailPrt.empty())
{
setParticleEffect(shotData->trailPrt);
}
if (shotData->numSegs > 0)
{
segments.resize(shotData->numSegs);
for (int i = segments.size()-1; i >=0 ; i--)
{
Quad *flame = new Quad;
flame->setTexture(shotData->segTexture);
flame->scale = shotData->segScale - Vector(shotData->segTaper, shotData->segTaper)*(i);
flame->setBlendType(this->getBlendType());
flame->alpha = 0.5;
dsq->game->addRenderObject(flame, LR_PARTICLES);
segments[i] = flame;
segments[i]->position = position;
}
maxDist = shotData->segDist;
minDist = 0;
initSegments(position);
}
setParticleEffect(shotData.trailPrt);
}
std::string scriptname = "shot_" + shotData->name;
if (shotData.numSegs > 0)
{
segments.resize(shotData.numSegs);
for (int i = segments.size()-1; i >=0 ; i--)
{
Quad *flame = new Quad;
flame->setTexture(shotData.segTexture);
flame->scale = shotData.segScale - Vector(shotData.segTaper, shotData.segTaper)*(i);
flame->setBlendType(this->getBlendType());
flame->alpha = 0.5;
dsq->game->addRenderObject(flame, LR_PARTICLES);
segments[i] = flame;
segments[i]->position = position;
}
maxDist = shotData.segDist;
minDist = 0;
initSegments(position);
}
std::string scriptname = "shot_" + shotData.name;
std::string file = ScriptInterface::MakeScriptFileName(scriptname, "shots");
script = dsq->scriptInterface.openScript(file, true);
updateScript = !!script;
@ -750,13 +753,9 @@ void Shot::onUpdate(float dt)
else if (target->alpha == 0)
target = 0;
}
if (life >= 1.0f)
if (alwaysMaxSpeed && life >= 1.0f)
{
if (velocity.isZero())
{
}
else if (velocity.isLength2DIn(maxSpeed*0.75f))
if (!velocity.isZero() && velocity.isLength2DIn(maxSpeed*0.75f))
{
velocity.setLength2D(maxSpeed);
}

View file

@ -63,7 +63,7 @@ struct ShotData
float waveSpeed, waveMag;
float spinSpeed;
bool invisible, checkDamageTarget, hitWalls, hitEnts, alwaysDoHitEffects;
bool invisible, checkDamageTarget, hitWalls, hitEnts, alwaysDoHitEffects, alwaysMaxSpeed;
float rotIncr;
float avatarKickBack, avatarKickBackTime;
@ -108,7 +108,7 @@ public:
static void clearShotBank();
static ShotData* getShotData(const std::string &ident);
static void loadBankShot(const std::string &ident, Shot *shot);
void applyShotData(ShotData *shotData);
void applyShotData(const ShotData& shotData);
void setAimVector(const Vector &aim);
void setTarget(Entity *target);
@ -116,7 +116,7 @@ public:
float getDamage() const;
int getCollideRadius() const;
DamageType getDamageType() const;
ShotData *shotData;
const ShotData *shotData;
void updatePosition();
bool isHitEnts() const;
bool canHit(Entity *e, Bone *b);
@ -129,6 +129,7 @@ public:
float lifeTime;
DamageType damageType;
bool checkDamageTarget;
bool alwaysMaxSpeed;
protected: