1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-25 22:25:46 +00:00

Add canShotHit() interface function

Let entity decide if it wants to collide with shot or not.
This commit is contained in:
fgenesis 2014-04-01 18:16:33 +02:00
parent 84ffb703e1
commit 209ad526c6
7 changed files with 39 additions and 10 deletions

View file

@ -243,6 +243,7 @@ public:
//virtual void onCollide(Entity *e);
virtual bool damage(const DamageData &d);
virtual bool canShotHit(const DamageData &d) { return true; }
virtual void songNote(int note);
virtual void songNoteDone(int note, float len);

View file

@ -8414,7 +8414,6 @@ bool Game::isEntityCollideWithShot(Entity *e, Shot *shot)
void Game::handleShotCollisions(Entity *e, bool hasShield)
{
BBGE_PROF(Game_handleShotCollisions);
bool isRegValid=true;
for (size_t i = 0; i < Shot::shots.size(); ++i)
{
Shot *shot = Shot::shots[i];
@ -8428,7 +8427,7 @@ void Game::handleShotCollisions(Entity *e, bool hasShield)
if ((collidePoint - shot->position).isLength2DIn(shot->collideRadius + e->collideRadius))
{
lastCollidePosition = shot->position;
shot->hitEntity(e,0,isRegValid);
shot->hitEntity(e,0);
}
}
}

View file

@ -67,6 +67,7 @@ static const char * const interfaceFunctions[] = {
"activate",
"animationKey",
"castSong",
"canShotHit",
"cookFailure",
"damage",
"deathNotify",

View file

@ -38,6 +38,7 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E
becomeSolidDelay = false;
strandSpacing = 10;
animKeyFunc = true;
canShotHitFunc = true;
//runningActivation = false;
setEntityType(et);
@ -562,6 +563,26 @@ void ScriptedEntity::lightFlare()
}
}
bool ScriptedEntity::canShotHit(const DamageData &d)
{
bool doDefault = true;
if (script && canShotHitFunc)
{
if (!script->call("canShotHit", this, d.attacker, d.bone, int(d.damageType), d.damage, d.hitPos.x, d.hitPos.y, d.shot, &doDefault))
{
debugLog(name + ": canShotHit function failed");
canShotHitFunc = false;
}
}
if (doDefault)
{
return Entity::canShotHit(d);
}
return false;
}
bool ScriptedEntity::damage(const DamageData &d)
{
if (d.damageType == DT_NONE) return false;

View file

@ -55,6 +55,8 @@ public:
void sporesDropped(const Vector &pos, int type);
bool damage(const DamageData &d);
bool canShotHit(const DamageData &d);
void song(SongType songType);
void startPull();
@ -109,6 +111,7 @@ protected:
void onEnterState(int action);
void onExitState(int action);
virtual void deathNotify(RenderObject *r);
bool canShotHitFunc;
};
#endif

View file

@ -558,7 +558,7 @@ bool Shot::isHitEnts() const
return false;
}
void Shot::hitEntity(Entity *e, Bone *b, bool isValid)
void Shot::hitEntity(Entity *e, Bone *b)
{
if (!dead)
{
@ -567,12 +567,6 @@ void Shot::hitEntity(Entity *e, Bone *b, bool isValid)
if (e)
{
if (damageType == DT_AVATAR_BITE)
{
//debugLog("Shot::hitEntity bittenEntities.push_back");
dsq->game->avatar->bittenEntities.push_back(e);
}
DamageData d;
d.attacker = firer;
d.bone = b;
@ -585,6 +579,16 @@ void Shot::hitEntity(Entity *e, Bone *b, bool isValid)
if ((firer && firer->getEntityType() == ET_AVATAR))
d.form = dsq->continuity.form;
if (!e->canShotHit(d))
return;
if (damageType == DT_AVATAR_BITE)
{
//debugLog("Shot::hitEntity bittenEntities.push_back");
dsq->game->avatar->bittenEntities.push_back(e);
}
bool damaged = e->damage(d);
// doesn't have anything to do with effectTime

View file

@ -94,7 +94,7 @@ public:
float maxSpeed;
void fire(bool playSfx = true);
void hitEntity(Entity *e, Bone *b, bool isValid=true);
void hitEntity(Entity *e, Bone *b);
void noSegs();