From 3ed40e73d3c102c148c708181b59de3a5fca3526 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 24 Apr 2013 04:51:26 +0200 Subject: [PATCH] Minor refactor & add Lua funcs: + avatar_setShieldActive() + entity_isFillGrid() * entity_setBoneLock() code made easier to read and not warn on no lock entity + entity_getMaxSpeedLerp() + entity_isEntityInside() --- Aquaria/Avatar.cpp | 29 +++++++++++++++++++++ Aquaria/Avatar.h | 2 ++ Aquaria/Continuity.cpp | 36 ++----------------------- Aquaria/DSQ.h | 1 - Aquaria/Entity.cpp | 11 ++++++++ Aquaria/Entity.h | 2 ++ Aquaria/ScriptInterface.cpp | 52 +++++++++++++++++++++++++++++++------ Aquaria/ScriptedEntity.cpp | 26 ------------------- Aquaria/ScriptedEntity.h | 1 - 9 files changed, 90 insertions(+), 70 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index a4c030f..1b47b1b 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4686,6 +4686,35 @@ void Avatar::action(int id, int state) } } +void Avatar::doBindSong() +{ + if (pullTarget) + { + pullTarget->stopPull(); + pullTarget = 0; + core->sound->playSfx("Denied"); + } + else + { + dsq->game->bindIngredients(); + setNearestPullTarget(); + if (!pullTarget) + { + core->sound->playSfx("Denied"); + } + else + { + core->sound->playSfx("Bind"); + } + } +} + +void Avatar::doShieldSong() +{ + core->sound->playSfx("Shield-On"); + activateAura(AURA_SHIELD); +} + void Avatar::render() { diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 0b8a196..d3a787e 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -317,6 +317,8 @@ public: bool canSetBoneLock(); void revert(); + void doBindSong(); + void doShieldSong(); int leaches; diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 063dd8a..31a6ac3 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -1347,16 +1347,6 @@ Song *Continuity::getSongByIndex(int idx) return &songBank[idx]; } -int Continuity::getSongBankSize() -{ - int c = 0; - for (SongMap::iterator i = songBank.begin(); i != songBank.end(); i++) - { - c++; - } - return c; -} - void Continuity::castSong(int num) { if (!dsq->continuity.hasSong((SongType)num)) return; @@ -1409,32 +1399,10 @@ void Continuity::castSong(int num) switch((SongType)num) { case SONG_SHIELDAURA: - core->sound->playSfx("Shield-On"); - dsq->game->avatar->activateAura(AURA_SHIELD); + dsq->game->avatar->doShieldSong(); break; case SONG_BIND: - //debugLog("sang pull"); - if (dsq->game->avatar->pullTarget) - { - dsq->game->avatar->pullTarget->stopPull(); - dsq->game->avatar->pullTarget = 0; - core->sound->playSfx("Denied"); - } - else - { - dsq->game->bindIngredients(); - dsq->game->avatar->setNearestPullTarget(); - if (!dsq->game->avatar->pullTarget) - { - core->sound->playSfx("Denied"); - } - else - { - core->sound->playSfx("Bind"); - } - } - //dsq->game->avatar->openPullTargetInterface(); - //pickingPullTarget = true; + dsq->game->avatar->doBindSong(); break; case SONG_ENERGYFORM: dsq->game->avatar->changeForm(FORM_ENERGY); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 5043f36..e24d4ff 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -996,7 +996,6 @@ public: FormUpgrades formUpgrades; void loadSongBank(); - int getSongBankSize(); void loadIntoSongBank(const std::string &file); int checkSong(const Song &song); int checkSongAssisted(const Song &song); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 8e7f027..f0c1e8f 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -3133,3 +3133,14 @@ void Entity::exertHairForce(const Vector &force, float dt) } } +bool Entity::isEntityInside() +{ + FOR_ENTITIES(i) + { + Entity *e = *i; + if (e && e->life == 1 && e != this && e->ridingOnEntity != this && isCoordinateInside(e->position)) + return true; + + } + return false; +} diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 724aa64..d89154e 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -489,6 +489,8 @@ public: void setHairHeadPosition(const Vector &pos); void exertHairForce(const Vector &force, float dt); + bool isEntityInside(); + protected: bool calledEntityDied; Path *waterBubble; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 9741251..a4e0753 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2112,18 +2112,22 @@ luaFunc(entity_setRidingData) luaFunc(entity_setBoneLock) { Entity *e = entity(L); - Entity *e2 = entity(L, 2); - Bone *b = 0; - if (lua_isuserdata(L, 3)) - b = bone(L, 3); bool ret = false; if (e) { BoneLock bl; - bl.entity = e2; - bl.bone = b; - bl.on = true; - bl.collisionMaskIndex = dsq->game->lastCollideMaskIndex; + if (lua_isuserdata(L, 2)) + { + Entity *e2 = entity(L, 2); + Bone *b = 0; + if (lua_isuserdata(L, 3)) + b = bone(L, 3); + + bl.entity = e2; + bl.bone = b; + bl.on = true; + bl.collisionMaskIndex = dsq->game->lastCollideMaskIndex; + } ret = e->setBoneLock(bl); } luaReturnBool(ret); @@ -2553,6 +2557,12 @@ luaFunc(entity_setFillGrid) luaReturnNil(); } +luaFunc(entity_isFillGrid) +{ + Entity *e = entity(L); + luaReturnBool(e ? e->fillGridFromQuad : false); +} + luaFunc(entity_getAimVector) { Entity *e = entity(L); @@ -2731,6 +2741,16 @@ luaFunc(avatar_isShieldActive) luaReturnBool(v); } +luaFunc(avatar_setShieldActive) +{ + bool on = getBool(L, 1); + if (on) + dsq->game->avatar->activateAura(AURA_SHIELD); + else + dsq->game->avatar->stopAura(); + luaReturnNil(); +} + luaFunc(avatar_getStillTimer) { luaReturnNum(dsq->game->avatar->stillTimer.getValue()); @@ -5049,6 +5069,12 @@ luaFunc(entity_setMaxSpeedLerp) luaReturnNil(); } +luaFunc(entity_getMaxSpeedLerp) +{ + Entity *e = entity(L); + luaReturnNum(e ? e->maxSpeedLerp.x : 0.0f); +} + // note: this is a weaker setState than perform // this is so that things can override it // for example getting PUSH-ed (Force) or FROZEN (bubbled) @@ -6165,6 +6191,12 @@ luaFunc(entity_getDistanceToEntity) luaReturnNum(d); } +luaFunc(entity_isEntityInside) +{ + Entity *e = entity(L); + luaReturnBool(e ? e->isEntityInside() : false); +} + // entity_istargetInRange luaFunc(entity_isTargetInRange) { @@ -7844,6 +7876,7 @@ static const struct { luaRegister(entity_isTargetInRange), luaRegister(entity_getDistanceToEntity), + luaRegister(entity_isEntityInside), luaRegister(entity_isInvincible), @@ -7860,6 +7893,7 @@ static const struct { luaRegister(entity_setMaxSpeed), luaRegister(entity_getMaxSpeed), luaRegister(entity_setMaxSpeedLerp), + luaRegister(entity_getMaxSpeedLerp), luaRegister(entity_setState), luaRegister(entity_getState), luaRegister(entity_getEnqueuedState), @@ -8050,6 +8084,7 @@ static const struct { luaRegister(avatar_isRolling), luaRegister(avatar_isOnWall), luaRegister(avatar_isShieldActive), + luaRegister(avatar_setShieldActive), luaRegister(avatar_getRollDirection), luaRegister(avatar_fallOffWall), @@ -8278,6 +8313,7 @@ static const struct { luaRegister(entity_setTexture), luaRegister(entity_setFillGrid), + luaRegister(entity_isFillGrid), luaRegister(entity_push), diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 67aa2a1..10f4c9e 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -759,32 +759,6 @@ void ScriptedEntity::songNoteDone(int note, float len) } } -bool ScriptedEntity::isEntityInside() -{ - bool v = false; - int avatars = 0; - FOR_ENTITIES(i) - { - Entity *e = *i; - if (e->getEntityType() == ET_AVATAR) - avatars ++; - if (e && e->life == 1 && e != this && e->ridingOnEntity != this) - { - if (isCoordinateInside(e->position)) - { - /* - Vector diff = (e->position - position); - diff.setLength2D(100); - e->vel += diff; - */ - v = true; - } - } - - } - return v; -} - void ScriptedEntity::becomeSolid() { //vel = 0; diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index 3c13dc7..f943f6a 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -68,7 +68,6 @@ public: typedef std::vector Strands; Strands strands; int strandSpacing; - bool isEntityInside(); void becomeSolid(); std::string deathParticleEffect;