diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 33a9139..5ea7e08 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -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); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 30cc416..ddd07e3 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -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); } } } diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 0731ec1..503f68b 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -67,6 +67,7 @@ static const char * const interfaceFunctions[] = { "activate", "animationKey", "castSong", + "canShotHit", "cookFailure", "damage", "deathNotify", diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 61477a8..6ac9b53 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -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; diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index d13b6c0..55276c4 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -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 diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index 702a87f..0fdff8b 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -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 diff --git a/Aquaria/Shot.h b/Aquaria/Shot.h index 100a3e1..d35e65e 100644 --- a/Aquaria/Shot.h +++ b/Aquaria/Shot.h @@ -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();