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

Fixed some script interface functions, error handling & code cleanups

== Script interface changes: ==

Removed entity_setClampOnSwitchDir(), which was a no-op.

Added entity_getFlag() function, for fairness, as nodes already have one.

Added node_getLabel() function, which does not return the _full_ node string, but only the first part before parameters.

dofile() supports relative paths now, and it is no longer necessary to use appendUserDataPath() + full path from a mod.

entity_color() does now support all interpolation functions that similar vector-manipulation functions support (loop, ping-pong, ease).

added entity_getVel() function (an entity_setVel() can be emulated with entity_clearVel(), followed by entity_addVel()).

*_getNearestNode() and *_getNearestEntity() allow an optional ignore parameter.
node_getNearestNode() allowed to specify a node to exclude from the search,
the others not -- now the interface is more consistent.

Deprecated entity_[incr/decr]TargetLeaches(entity) - the attached leach amount was never handled
by any entity other than Naija. Replaced them with avatar_[incr/decr]Leaches(), but kept the old
ames for now, too. Should be removed in a while.


== Script interface & related fixes: ==

Added bool loudScriptErrors to control displaying script syntax error and global variable usage warnings.
So far, syntax errors always went do debugLog(), but it is less time consuming when writing scripts
to have them displayed right away.

*_getNearestNode now scan by label, and not full name.
This allows searching for nodes but ignoring its parameters. The original game scripts never search
for nodes that have parameters, so this does not break anything,
but allows modding without an exploding amount of specialized node scripts.

entity_setBoneLock() failed for certain entites with throwLuaErrors=true,
allowing to burst through them (gears, grouper, big mithalas jelly, probably more).

Removed unnecessary int-casts in entity_setHealth(), entity_changeHealth(), and a few others,
which truncated float fractional parts.

Fixed possible crashes in many functions due to missing NULL-pointer checks,
if wrong data were passed to Lua.

Optimized entity_getNearestEntity() a little - do nocasecmp() after checking all other params

UPPERCASE global variables as used in mod include files are now tolerated, even with all warnings on.
This makes sense because it was impossible to include a custom flags definition file
(which _must_ have globals, otherwise the including scripts won't see them) in a mod without beeing buried in spam.
They won't change, or clobber any states, and UPPERCASE sort of implies a constant/#define, imho.

Added better control over warnings about not-existing files. map_*.lua and premap_*.lua files are optional,
and no warning should be given if they do not exist. Missing Entity scripts and mod-init.lua must be
warned about, however.

Fixed a crash in global variable access warning (NULL pushed into std::ostringstream)

Fixed 2 random warnings i found in scrips


== Misc stuff: ==

Related to the changes above, cleaned out unused variables from the Entity class,
and removed the code that had to do with them somehow. Some parts of the removed code
were still in use, although totally unnecessary.
Saves a few bytes of memory per entity, and less code that can cause headache.
This commit is contained in:
fgenesis 2011-09-18 23:12:02 +02:00
parent 7d0c2351ed
commit c78d4d7a11
23 changed files with 314 additions and 619 deletions

View file

@ -4553,6 +4553,7 @@ Avatar::Avatar() : Entity(), ActionMapper()
pullTarget = 0;
revertTimer = 0;
currentSongIdx = -1;
leaches = 0;
debugLog("Avatar vars->");
@ -5987,11 +5988,6 @@ int Avatar::getBeamWidth()
return c * TILE_SIZE;
}
void Avatar::onGetEXP(unsigned int exp)
{
dsq->continuity.exp += exp;
}
void Avatar::onEnterState(int action)
{
Entity::onEnterState(action);

View file

@ -353,6 +353,8 @@ public:
bool canSetBoneLock();
void revert();
int leaches;
protected:
void setSongIconPositions();
@ -459,7 +461,6 @@ protected:
void onEnterState(int action);
void onExitState(int action);
void onGetEXP(unsigned int exp);
std::vector<ParticleEffect*>targetQuads;
Quad *blinder, *fader, *tripper;
void applyBlindEffects();

View file

@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
CollideEntity::CollideEntity() : Entity()
{
this->canBeTargetedByAvatar = true;
collideWithEntity = false;
weight = 0;
bounceAmount = 0.5f;
bounceEntityAmount = 0.5f;

View file

@ -33,7 +33,6 @@ public:
void entityDied(Entity *e);
protected:
virtual void onHitWall(){}
virtual void onHitEntity(const CollideData &c){}
void onUpdateFrozen(float dt);
virtual void onBounce() {}

View file

@ -3844,9 +3844,9 @@ void DSQ::runGesture(const std::string &line)
}
}
bool DSQ::runScript(const std::string &name, const std::string &function)
bool DSQ::runScript(const std::string &name, const std::string &function, bool ignoremissing /* = false */)
{
if (!scriptInterface.runScript(name, function))
if (!scriptInterface.runScript(name, function, ignoremissing))
{
debugLog("Could not find script file [" + name + "]");
}

View file

@ -1367,7 +1367,7 @@ public:
void doLoadMenu();
void onExitSaveSlotMenu();
ScriptInterface scriptInterface;
bool runScript(const std::string &name, const std::string &func="");
bool runScript(const std::string &name, const std::string &func="", bool ignoremissing = false);
bool runScriptNum(const std::string &name, const std::string &func="", float num=0);
void collectScriptGarbage();

View file

@ -240,36 +240,21 @@ Entity::Entity() : StateMachine(), DFSprite()
swimPath = false;
currentEntityTarget = 0;
deleteOnPathEnd = false;
shockTimer = 0;
overideMaxSpeedValue= 0;
overideMaxSpeedTime=0;
followingPath = 0;
multColor = Vector(1,1,1);
collideRadius = 24;
entityType = EntityType(0);
behaviorType = BehaviorType(0);
targets.resize(10);
attachedTo = 0;
currentPathNode = -1;
notify = 0;
itemUseRange = 400;
flipScene = true;
collideWithEntity = false;
//target = 0;
leaches = 0;
frozenTimer = 0;
shockTimer = 0;
shockQuad = 0;
exp = 0;
manaBallTarget = 0;
wantManaBall = 0;
canBeTargetedByAvatar = false;
canTalkWhileMoving = false;
activationRange = 0;
activationType = ACT_NONE;
currentColor = Vector(1,1,1);
isStuckIn = false;
canStickInStream = false;
pushDamage = 0;
//debugLog("dsq->addEntity()");
@ -498,11 +483,6 @@ void Entity::setName(const std::string &name)
this->name = name;
}
Path *Entity::getNode()
{
return &node;
}
void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd)
{
//Path *p = dsq->game->getPathByName(name);
@ -561,7 +541,6 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim)
position.data->path.clear();
position.stop();
ondulateTimer = 0;
swimPath = swim;
debugLog("Generating path to: " + path->name);
dsq->pathFinding.generatePath(this, TileVector(start), TileVector(dest));
@ -724,22 +703,6 @@ void Entity::warpToPathStart()
position = followingPath->nodes[0].position;
}
void Entity::itemUsedOnMe(Entity *user, int item)
{
onItemUsedOnMe(user, item);
}
Vector Entity::getAvatarDiff()
{
return dsq->game->avatar->position - this->position;
}
/*
void Entity::onCollide(Entity *e)
{
}
*/
void Entity::watchEntity(Entity *e)
{
watchingEntity = e;
@ -997,36 +960,12 @@ void Entity::revive(int a)
//health += a;
}
void Entity::doMovementPattern(Entity *target, MovementPatternType type, int minDist, int maxDist, int spd1, int spd2, float dt)
{
Vector v = target->position - position;
int dist = v.getSquaredLength2D();
if (dist < sqr(minDist))
{
Vector sub = v;
sub.setLength2D(spd1);
Vector mov = v;
Vector para(mov.y, -mov.x);
vel -= (mov+para)*dt;
}
else if (dist > sqr(minDist) && dist < sqr(maxDist))
{
v.setLength2D(spd2 * dt);
vel += v;
}
else
{
vel -= vel*dt*0.5f;
}
}
bool Entity::isGoingToBeEaten()
{
return (eatType != EAT_NONE && (lastDamage.damageType == DT_AVATAR_BITE || lastDamage.damageType == DT_AVATAR_PETBITE));
}
void Entity::doDeathEffects(int manaBallEnergy, int money, bool die)
void Entity::doDeathEffects(int manaBallEnergy, bool die)
{
if (deathScene || !isGoingToBeEaten())
{
@ -1784,7 +1723,10 @@ void Entity::clearDamageTargets()
void Entity::setDamageTarget(DamageType dt, bool v)
{
disabledDamageTypes[dt] = !v;
if (v)
disabledDamageTypes.erase(dt);
else
disabledDamageTypes.insert(dt);
}
void Entity::setEatType(EatType et, const std::string &file)
@ -1800,23 +1742,22 @@ void Entity::setEatType(EatType et, const std::string &file)
void Entity::setAllDamageTargets(bool v)
{
for (int i = DT_ENEMY; i < DT_ENEMY_REALMAX; i++)
{
disabledDamageTypes[(DamageType)i] = !v;
}
for (int i = DT_AVATAR; i < DT_AVATAR_REALMAX; i++)
{
disabledDamageTypes[(DamageType)i] = !v;
}
for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++)
{
disabledDamageTypes[(DamageType)i] = !v;
}
if (v)
clearDamageTargets(); // clear all disabled -> all allowed now
if (v)
{
for (int i = DT_ENEMY; i < DT_ENEMY_REALMAX; i++)
setDamageTarget(DamageType(i), v);
for (int i = DT_AVATAR; i < DT_AVATAR_REALMAX; i++)
setDamageTarget(DamageType(i), v);
for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++)
setDamageTarget(DamageType(i), v);
}
}
bool Entity::isDamageTarget(DamageType dt)
{
return !disabledDamageTypes[dt];
return disabledDamageTypes.find(dt) == disabledDamageTypes.end();
}
float Entity::getHealthPerc()
@ -1969,20 +1910,12 @@ void Entity::onUpdate(float dt)
}
}
if (node.nodes.empty())
{
node.addNode(0);
}
node.nodes[0].position = position;
DFSprite::onUpdate(dt);
Vector v = position - lastPos;
lastMove = v;
if (position.isFollowingPath() && swimPath)
{
ondulateTimer += dt;
movementDetails(v);
}
else
@ -2011,8 +1944,6 @@ void Entity::onUpdate(float dt)
if (bubble)
bubble->position = this->position;
if (shockQuad)
shockQuad->position = this->position;
/*
if (frozenTimer > 0)
@ -2025,15 +1956,6 @@ void Entity::onUpdate(float dt)
}
}
*/
if (shockTimer > 0)
{
shockTimer -= dt;
if (shockTimer <= 0)
{
shockTimer = 0;
endShock();
}
}
if (followingPath && currentPathNode != -1 && life == 1)
{
@ -2475,7 +2397,6 @@ void Entity::push(const Vector &vec, float time, int maxSpeed, float dmg)
{
if (!this->isEntityDead())
{
isStuckIn = false;
pushDamage = dmg;
if (maxSpeed == 0)
{
@ -2518,35 +2439,6 @@ int Entity::getMaxSpeed()
return maxSpeed;
}
void Entity::shock()
{
shockTimer = 0.33;
if (shockQuad)
{
//shockQuad->setLife(1);
}
else
{
/*
shockQuad = new Quad;
shockQuad->setTexture("shock-hit");
shockQuad->alpha = 0;
shockQuad->position = this->position;
*/
/*
//shockQuad->setLife(1);
//shockQuad->setDecayRate(1);
//shockQuad->fadeAlphaWithLife = 0.5;
*/
/*
shockQuad->setBlendType(BLEND_ADDITIVE);
shockQuad->alpha.interpolateTo(1, 0.5);
shockQuad->rotation.interpolateTo(Vector(0,0,360*5), 0.5, -1);
core->getTopStateData()->addRenderObject(shockQuad, LR_PARTICLES);
*/
}
}
void Entity::songNote(int note)
{
}
@ -2566,19 +2458,6 @@ void Entity::sound(const std::string &sound, float freq, float fadeOut)
dsq->playPositionalSfx(sound, position, 1, fadeOut);
}
void Entity::endShock()
{
offset.x = 0;
if (shockQuad)
{
shockQuad->setLife(1);
shockQuad->setDecayRate(4);
shockQuad->fadeAlphaWithLife = 1;
shockQuad = 0;
}
}
Vector Entity::getEnergyShotTargetPosition()
{
if (!energyShotTargetPosition.isZero())
@ -2610,21 +2489,11 @@ void Entity::setEntityType(EntityType et)
entityType = et;
}
void Entity::setBehaviorType(BehaviorType bt)
{
behaviorType = bt;
}
EntityType Entity::getEntityType()
{
return entityType;
}
BehaviorType Entity::getBehaviorType()
{
return behaviorType;
}
/* types:
*/
@ -2764,7 +2633,6 @@ void Entity::onEnterState(int action)
{
sound("Gulp");
}
endShock();
popBubble();
//dsq->game->avatar->entityDied(this);
Shot::targetDied(this);
@ -2909,11 +2777,6 @@ bool Entity::onDamage(int amount, Spell *spell, Entity *attacker)
}
*/
void Entity::getEXP(unsigned int exp)
{
onGetEXP(exp);
}
bool Entity::isHit()
{
return (damageTimer.isActive());
@ -3104,14 +2967,9 @@ bool Entity::damage(const DamageData &dmgData)
this->multColor.interpolateTo(Vector(1, 0.1, 0.1), 0.1, 4, 1);
}
if (d.mult != 0)
health -= d.damage * d.mult;
else
health -= d.damage;
health -= d.damage;
if (health <= 0)
{
if (d.attacker)
d.attacker->getEXP(exp);
health = 0;
entityDead = true;
if (deathScene)
@ -3135,11 +2993,6 @@ void Entity::clampToHit()
//setCrawling(true);
}
bool Entity::hitEntity(Entity *e, const CollideData &c)
{
return true;
}
/*
void Entity::damage(int amount, Spell *spell, Entity *attacker)
{

View file

@ -150,14 +150,12 @@ struct DamageData
attacker = 0;
bone = 0;
damageType = DT_TOUCH;
mult = 0;
form = (FormType)0;
shot = 0;
effectTime = 0;
useTimer = true;
}
FormType form;
float mult;
DamageType damageType;
Entity *attacker;
Bone *bone;
@ -168,33 +166,6 @@ struct DamageData
bool useTimer;
};
struct CollideData
{
public:
CollideData()
{
collision = false;
entity = 0;
bone = 0;
pushTime = 0;
damage = 0;
}
int damage;
Vector pushVector;
float pushTime;
bool collision;
Vector edgePoint;
Entity *entity;
Bone *bone;
};
enum MovementPatternType
{
MOVEMENT_NONE = -1,
MOVEMENT_CIRCLE = 0,
};
enum EntityType
{
ET_NOTYPE =-1,
@ -215,13 +186,6 @@ enum EntityProperty
EP_MAX =4
};
enum BehaviorType
{
BT_NORMAL =0,
BT_MOTHER =1,
BT_ACTIVEPET =2
};
enum BounceType
{
BOUNCE_NONE = -1,
@ -265,8 +229,6 @@ public:
void heal(float a, int type=0);
void push(const Vector &vec, float time, int maxSpeed, float dmg);
bool canStickInStream;
bool isStuckIn;
bool canSetState(int state);
@ -279,7 +241,6 @@ public:
virtual bool damage(const DamageData &d);
virtual bool hitEntity(Entity *e, const CollideData &c);
virtual void songNote(int note);
virtual void songNoteDone(int note, float len);
virtual void lightFlare(){}
@ -299,17 +260,13 @@ public:
ActivationType activationType;
int activationRange;
bool canTalkWhileMoving;
Entity *followEntity;
Entity *ridingOnEntity;
bool canBeTargetedByAvatar;
virtual void saveExtraData(TiXmlElement *xml){}
virtual void loadExtraData(TiXmlElement *xml){}
Vector startPos;
int wantManaBall;
ManaBall *manaBallTarget;
virtual void onMessage(const std::string &msg){}
unsigned int exp;
void getEXP(unsigned int exp);
void rotateToVec(Vector addVec, float time, int offsetAngle=0);
virtual void applyVariation(int variation){}
@ -317,15 +274,11 @@ public:
void popBubble();
void sound(const std::string &sound, float freq=1, float fadeOut=0);
void soundFreq(const std::string &sound, float freq=1, float fadeOut=0);
void shock();
void endShock();
void freeze(float time);
int leaches;
bool collideWithEntity;
virtual void onSceneFlipped() {}
bool flipScene;
bool isNearObstruction(int sz, int type=0, TileVector *hitTile=0);
@ -352,9 +305,6 @@ public:
STATE_FOLLOW =23,
STATE_TITLE =24
};
int itemUseRange;
void itemUsedOnMe(Entity *user, int item);
Entity *notify;
virtual void onNotify(Entity *notify){}
//void followPath(Path *p, int spd, int loop, bool deleteOnEnd = false);
void followPath(Path *p, int speedType, int dir, bool deleteOnEnd = false);
@ -394,9 +344,7 @@ public:
SkeletalSprite skeletalSprite;
void setEntityType(EntityType et);
void setBehaviorType(BehaviorType bt);
EntityType getEntityType();
BehaviorType getBehaviorType();
bool isOpposedTo(Entity *e);
bool isCollideAgainst(Entity *e);
void flipToTarget(Vector pos);
@ -411,7 +359,6 @@ public:
Timer burstTimer;
void revive(int a);
void setName(const std::string &name);
Path *getNode();
void doFriction(float dt);
void doFriction(float dt, int len);
@ -465,13 +412,11 @@ public:
void setDamageTarget(DamageType dt, bool v);
bool isDamageTarget(DamageType dt);
typedef std::map<DamageType, bool> DisabledDamageTypes;
typedef std::set<DamageType> DisabledDamageTypes;
int targetRange;
int getTargetRange() { return targetRange; }
Vector getEnergyShotTargetPosition();
int getRandomTargetPoint();
@ -616,16 +561,13 @@ protected:
float slowingToStopPathTimer, slowingToStopPath;
void movementDetails(Vector v);
float ondulateTimer;
Entity *watchingEntity;
Path node;
virtual void onPathEnd();
bool swimPath;
bool deleteOnPathEnd;
int overideMaxSpeedValue;
float overideMaxSpeedTime;
InterpolatedVector multColor;
BehaviorType behaviorType;
EntityType entityType;
std::vector<Entity*> attachedEntities;
std::vector<Vector> attachedEntitiesOffsets;
@ -635,24 +577,17 @@ protected:
int followingPathLoop;
virtual void onItemUsedOnMe(Entity *user, int item){}
virtual void onFreeze(){}
void doMovementPattern(Entity *target, MovementPatternType type, int minDist, int maxDist, int spd1, int spd2, float dt);
//Entity *target;
std::vector<Entity*>targets;
virtual void onAlwaysUpdate(float dt){}
virtual void onUpdateFrozen(float dt){}
float frozenTimer;
float shockTimer;
Quad *shockQuad;
Quad *bubble;
virtual void onGetEXP(unsigned int exp){}
void doDeathEffects(int manaBallEnergy=0, int money=0, bool die=true);
void doDeathEffects(int manaBallEnergy=0, bool die=true);
Vector getAvatarDiff();
Vector currentColor;
bool takeDamage;
void onEnterState(int action);

View file

@ -1075,10 +1075,7 @@ void Game::flipSceneVertical(int flipY)
FOR_ENTITIES(itr)
{
Entity *e = *itr;
if (e->flipScene)
{
flipRenderObjectVertical(e, flipY);
}
flipRenderObjectVertical(e, flipY);
}
int i = 0;
int flipTY = (flipY/TILE_SIZE)-1;
@ -2610,7 +2607,7 @@ int Game::getIdxForEntityType(std::string type)
return -1;
}
Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, BehaviorType bt, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit)
Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit)
{
std::string type;
for (int i = 0; i < dsq->game->entityTypeList.size(); i++)
@ -2619,7 +2616,7 @@ Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool creat
if (ec->idx == idx)
{
type = ec->name;
return createEntity(type, id, position, rot, createSaveData, name, et, bt, nodeGroups, gid, doPostInit);
return createEntity(type, id, position, rot, createSaveData, name, et, nodeGroups, gid, doPostInit);
}
}
return 0;
@ -2658,7 +2655,7 @@ void Game::ensureLimit(Entity *e, int num, int state)
}
}
Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, BehaviorType bt, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit)
Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit)
{
// e->layer must be set BEFORE calling this function!
@ -2731,17 +2728,17 @@ Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool
return e;
}
Entity *Game::createEntity(const std::string &t, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, BehaviorType bt, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit)
Entity *Game::createEntity(const std::string &t, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit)
{
std::string type = t;
stringToLower(type);
ScriptedEntity *e;
e = new ScriptedEntity(type, position, et, bt);
e = new ScriptedEntity(type, position, et);
return establishEntity(e, id, position, rot, createSaveData, name, et, bt, nodeGroups, gid, doPostInit);
return establishEntity(e, id, position, rot, createSaveData, name, et, nodeGroups, gid, doPostInit);
}
void Game::initEntities()
@ -3072,7 +3069,7 @@ Path *Game::getNearestPath(const Vector &pos, const std::string &s, const Path *
for (int i = 0; i < dsq->game->paths.size(); i++)
{
Path *cp = dsq->game->paths[i];
if (cp != ignore && !cp->nodes.empty() && (st.empty() || st == cp->name))
if (cp != ignore && !cp->nodes.empty() && (st.empty() || st == cp->label))
{
const Vector v = cp->nodes[0].position - pos;
const float dist = v.getSquaredLength2D();
@ -3118,7 +3115,7 @@ Path *Game::getPathByName(std::string name)
stringToLowerUserData(name);
for (int i = 0; i < paths.size(); i++)
{
if (paths[i]->name == name)
if (paths[i]->label == name)
return paths[i];
}
return 0;
@ -5289,7 +5286,7 @@ bool Game::loadSceneXML(std::string scene)
}
}
dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, BT_NORMAL, ng, groupID);
dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, ng, groupID);
// setting group ID
}
}
@ -5302,7 +5299,7 @@ bool Game::loadSceneXML(std::string scene)
{
is >> x >> y >> rot >> groupID >> id;
dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, BT_NORMAL, 0, groupID);
dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, 0, groupID);
// setting group ID
}
}
@ -5320,9 +5317,9 @@ bool Game::loadSceneXML(std::string scene)
is >> x >> y >> rot >> groupID >> id;
if (!name.empty())
dsq->game->createEntity(name, id, Vector(x,y), rot, true, "", ET_ENEMY, BT_NORMAL, 0, groupID);
dsq->game->createEntity(name, id, Vector(x,y), rot, true, "", ET_ENEMY, 0, groupID);
else
dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, BT_NORMAL, 0, groupID);
dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, 0, groupID);
// setting group ID
}
}
@ -6987,7 +6984,7 @@ void Game::applyState()
core->sort();
dsq->runScript("scripts/maps/premap_"+sceneName+".lua", "init");
dsq->runScript("scripts/maps/premap_"+sceneName+".lua", "init", true);
std::string musicToPlay = this->musicToPlay;
if (!overrideMusic.empty())
@ -7079,7 +7076,7 @@ void Game::applyState()
dsq->subtitlePlayer.show(0.25);
if (verbose) debugLog("loading map init script");
dsq->runScript("scripts/maps/map_"+sceneName+".lua", "init");
dsq->runScript("scripts/maps/map_"+sceneName+".lua", "init", true);
if (!dsq->doScreenTrans && (dsq->overlay->alpha != 0 && !dsq->overlay->alpha.isInterpolating()))
{
@ -8742,120 +8739,6 @@ void Game::handleShotCollisionsHair(Entity *e, int num)
}
}
CollideData Game::collideCircleWithAllEntities(Vector pos, float r, Entity *me, int spellType, bool checkAvatarFlag)
{
CollideData c;
//if (me && (checkHitEntitiesFlag && !me->hitEntity)) return 0;
//Avatar *a = dynamic_cast<Avatar*>(me);
FOR_ENTITIES(i)
{
Entity *e = *i;
if (me != e)
{
bool okay = true;
if (okay)
{
if (spellType == 0)
{
Bone *closest = 0;
float smallestDist = HUGE_VALF;
for (int i = 0; i < e->skeletalSprite.bones.size(); i++)
{
Bone *b = e->skeletalSprite.bones[i];
Vector bonePos = b->getWorldCollidePosition();
float dist = (bonePos - pos).getSquaredLength2D();
if (!b->collisionMask.empty() && b->alpha.x == 1)
{
if (dist < sqr(r + b->collisionMaskRadius))
{
for (int i = 0; i < b->transformedCollisionMask.size(); i++)
{
//Vector collide = b->transformedCollisionMask[i];
// only do this work once per frame
//Vector bitPos = b->getWorldCollidePosition(collide);
Vector bitPos = b->transformedCollisionMask[i];
dist = (bitPos - pos).getSquaredLength2D();
if (dist < sqr(r+b->collideRadius))
{
closest = b;
smallestDist = dist;
break;
}
}
}
}
else if (b->collideRadius && b->alpha.x == 1)
{
//Vector bonePos = b->getWorldCollidePosition();
//float dist = (bonePos - pos).getSquaredLength2D();
if (dist < sqr(r+b->collideRadius))
{
if (dist < smallestDist)
{
closest = b;
smallestDist = dist;
}
}
}
}
if (!closest)
{
if ((e->position - pos).getSquaredLength2D() < sqr(r+e->collideRadius))
{
c.entity = e;
if (e->pushAvatar)
{
c.pushVector = pos - e->position;
c.pushVector.normalize2D();
}
if (e->touchDamage)
{
c.damage = e->touchDamage;
}
///c.pushVector |= 500;
c.collision = true;
return c;
}
}
else
{
//debugLog("boneCollision!");
c.entity = e;
if (e->pushAvatar)
{
c.pushVector = pos - e->position;
c.pushVector.normalize2D();
}
//c.pushVector |= 500;
c.bone = closest;
if (c.bone->touchDamage!=0)
{
c.damage = c.bone->touchDamage;
}
else if (e->touchDamage!=0)
{
/*
std::ostringstream os;
os << "entity touch damage: " << e->touchDamage;
debugLog(os.str());
*/
c.damage = e->touchDamage;
}
c.collision = true;
return c;
}
}
}
}
}
return c;
}
#ifdef AQUARIA_BUILD_SCENEEDITOR
void Game::toggleSceneEditor()
{
@ -10596,7 +10479,7 @@ void Game::update(float dt)
if (sqrLen < sqr(e->activationRadius)
&& (avatar->position-e->position).getSquaredLength2D() < sqr(e->activationRange)
&& e->activationType == Entity::ACT_CLICK
&& (e->canTalkWhileMoving || !e->position.isInterpolating())
&& !e->position.isInterpolating()
)
{
//if (trace(avatar->position, e->position))

View file

@ -152,7 +152,7 @@ public:
ParticleEffect healEmitter;
protected:
float lifeSpan;
bool used, gone;
bool used;
float amount;
void onUpdate(float dt);
};
@ -679,7 +679,6 @@ public:
bool collideCircleVsLine(Entity *ent, Vector start, Vector end, float radius);
bool collideCircleVsLineAngle(Entity *ent, float angle, float startLen, float endLen, float radius, Vector basePos);
Bone *collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius);
CollideData collideCircleWithAllEntities(Vector pos, float r, Entity *me=0, int spellType=0, bool checkAvatarFlag=false);//, bool checkSpellFlag=0, bool checkHitEntitiesFlag=1);
void handleShotCollisions(Entity *e, bool hasShield=false);
void handleShotCollisionsSkeletal(Entity *e);
void handleShotCollisionsHair(Entity *e, int num = 0);
@ -741,9 +740,9 @@ public:
MiniMapHint miniMapHint;
void updateMiniMapHintPosition();
EntitySaveData *getEntitySaveDataForEntity(Entity *e, Vector pos);
Entity *createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, BehaviorType = BT_NORMAL, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false);
Entity *createEntity(const std::string &type, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, BehaviorType = BT_NORMAL, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false);
Entity *establishEntity(Entity *e, int id=0, Vector position=Vector(0,0), int rot=0, bool createSaveData=false, std::string name="", EntityType = ET_ENEMY, BehaviorType = BT_NORMAL, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false);
Entity *createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false);
Entity *createEntity(const std::string &type, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false);
Entity *establishEntity(Entity *e, int id=0, Vector position=Vector(0,0), int rot=0, bool createSaveData=false, std::string name="", EntityType = ET_ENEMY, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false);
void setCameraFollow(RenderObject *r);
void setCameraFollowEntity(Entity *e);
void setMenuDescriptionText(const std::string &text);

View file

@ -40,7 +40,6 @@ ManaBall::ManaBall(Vector pos, float amount) : Quad()
lifeSpan = 15;
setBlendType(BLEND_ADD);
used = false;
gone = false;
addChild(&healEmitter, PM_STATIC);
if (dsq->difficulty == DSQ::DIFF_EASY)
@ -52,15 +51,6 @@ ManaBall::ManaBall(Vector pos, float amount) : Quad()
void ManaBall::destroy()
{
Quad::destroy();
FOR_ENTITIES(i)
{
Entity *e = *i;
if (e)
{
if (e->manaBallTarget == this)
e->manaBallTarget = 0;
}
}
}
bool ManaBall::isUsed()
@ -79,15 +69,6 @@ void ManaBall::use(Entity *entity)
scale.startPath(1);
setLife(1.1);
used = true;
FOR_ENTITIES(i)
{
Entity *e = *i;
if (e)
{
if (e->manaBallTarget == this)
e->manaBallTarget = 0;
}
}
}
void ManaBall::onUpdate(float dt)
@ -102,7 +83,6 @@ void ManaBall::onUpdate(float dt)
if (lifeSpan <= 0)
{
lifeSpan = 0;
gone = true;
this->scale.interpolateTo(Vector(0,0),1);
setLife(1);
setDecayRate(1);
@ -111,23 +91,6 @@ void ManaBall::onUpdate(float dt)
}
}
if (!gone && !used)
{
FOR_ENTITIES(i)
{
Entity *e = *i;
if (e)
{
if (e->wantManaBall)
{
if ((e->position - this->position).getSquaredLength2D() < sqr(e->wantManaBall))
{
e->manaBallTarget = this;
}
}
}
}
}
if (dsq->game->avatar)
{
if (!used)

View file

@ -288,6 +288,7 @@ void Path::refreshScript()
{
amount = 0;
content.clear();
label.clear();
// HACK: clean up
/*+ dsq->game->sceneName + "_"*/
@ -297,9 +298,8 @@ void Path::refreshScript()
stringToLower(name);
std::string label;
{
SimpleIStringStream is(name);
SimpleIStringStream is(name.c_str(), SimpleIStringStream::REUSE);
is >> label >> content >> amount;
}

View file

@ -79,7 +79,8 @@ public:
void songNote(int note);
void songNoteDone(int note, float len);
bool hasScript();
std::string name;
std::string name; // full node string
std::string label; // first part only (the actual node name)
std::vector<PathNode>nodes;
void removeNode(int idx);
void addNode(int idx);

View file

@ -3126,9 +3126,9 @@ void SceneEditor::placeElement()
else if (editType == ET_ENTITIES)
{
if (!selectedEntity.nameBased)
dsq->game->createEntity(selectedEntity.index, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, BT_NORMAL, 0, 0, true);
dsq->game->createEntity(selectedEntity.index, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, 0, 0, true);
else
dsq->game->createEntity(selectedEntity.name, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, BT_NORMAL, 0, 0, true);
dsq->game->createEntity(selectedEntity.name, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, 0, 0, true);
}
else if (editType == ET_PATHS)
{

View file

@ -117,7 +117,7 @@ void SchoolFish::onEnterState(int action)
oldFlockID = flock ? flock->flockID : -1;
removeFromFlock();
doDeathEffects(0,0,0);
doDeathEffects(0, false);
/*
alpha = 0;

View file

@ -36,11 +36,18 @@ extern "C"
#include "../BBGE/MathFunctions.h"
// If true, send all sort of script errors to errorLog instead of debugLog.
// On win32, this pops up message boxes which help to locate errors easily,
// but can be annoying for regular gameplay.
const bool loudScriptErrors = false;
const bool throwLuaErrors = false;
// Set this to true to complain (via errorLog()) whenever a script tries to
// get or set a global variable.
const bool complainOnGlobalVar = false;
// Set this to true to complain whenever a script tries to get an undefined
// thread-local variable.
const bool complainOnUndefLocal = false;
@ -271,6 +278,14 @@ static const char * const interfaceFunctions[] = {
// S C R I P T C O M M A N D S
//============================================================================================
static void scriptError(const std::string& msg)
{
if(loudScriptErrors)
errorLog(msg);
else
debugLog(msg);
}
static void luaErrorMsg(lua_State *L, const char *msg)
{
debugLog(msg);
@ -472,6 +487,14 @@ static SkeletalSprite *getSkeletalSprite(Entity *e)
return skel;
}
static bool looksLikeGlobal(const char *s)
{
for( ; *s; ++s)
if( !((*s >= 'A' && *s <= 'Z') || *s == '_' || (*s >= '0' && *s <= '9')) ) // accept any uppercase, number, and _ char
return false;
return true;
}
//----------------------------------//
#define luaFunc(func) static int l_##func(lua_State *L)
@ -529,8 +552,8 @@ luaFunc(indexWarnGlobal)
std::ostringstream os;
os << "WARNING: " << ar.short_src << ":" << ar.currentline
<< ": script tried to get/call undefined global variable "
<< lua_tostring(L, -2);
errorLog(os.str());
<< varname;
scriptError(os.str());
}
lua_pop(L, 1);
@ -546,7 +569,7 @@ luaFunc(newindexWarnGlobal)
// Don't warn on "v" or known interface functions.
lua_pushvalue(L, -2);
const char *varname = lua_tostring(L, -1);
bool doWarn = (strcmp(varname, "v") != 0);
bool doWarn = (strcmp(varname, "v") != 0) && !looksLikeGlobal(varname);
for (unsigned int i = 0; doWarn && interfaceFunctions[i] != NULL; i++)
{
doWarn = (strcmp(varname, interfaceFunctions[i]) != 0);
@ -570,7 +593,7 @@ luaFunc(newindexWarnGlobal)
<< ": script set global "
<< (lua_type(L, -2) == LUA_TFUNCTION ? "function" : "variable")
<< " " << lua_tostring(L, -1);
errorLog(os.str());
scriptError(os.str());
}
lua_pop(L, 1);
@ -609,14 +632,33 @@ luaFunc(indexWarnInstance)
return 1;
}
static int dofile_helper(lua_State *L, const char *fname)
{
int n = lua_gettop(L);
if (luaL_loadfile(L, fname) != 0) lua_error(L);
lua_call(L, 0, LUA_MULTRET);
return lua_gettop(L) - n;
}
luaFunc(dofile_caseinsensitive)
{
// This is Lua's dofile(), with some tweaks. --ryan.
std::string fname(core->adjustFilenameCase(luaL_checkstring(L, 1)));
int n = lua_gettop(L);
if (luaL_loadfile(L, fname.c_str()) != 0) lua_error(L);
lua_call(L, 0, LUA_MULTRET);
return lua_gettop(L) - n;
const char *rawname = luaL_checkstring(L, 1);
std::string fname;
if (dsq->mod.isActive())
{
fname += dsq->mod.getPath();
fname += '/';
fname += rawname;
fname = core->adjustFilenameCase(fname);
if (exists(fname))
return dofile_helper(L, fname.c_str());
}
// try absolute path
fname = core->adjustFilenameCase(rawname);
return dofile_helper(L, fname.c_str());
}
luaFunc(randRange)
@ -996,7 +1038,9 @@ luaFunc(entity_setBoneLock)
{
Entity *e = entity(L);
Entity *e2 = entity(L, 2);
Bone *b = bone(L, 3);
Bone *b = 0;
if (lua_isuserdata(L, 3))
b = bone(L, 3);
bool ret = false;
if (e)
{
@ -1994,7 +2038,7 @@ luaFunc(entity_createEntity)
{
Entity *e = entity(L);
if (e)
dsq->game->createEntity(dsq->getEntityTypeIndexByName(lua_tostring(L, 2)), 0, e->position, 0, false, "", ET_ENEMY, BT_NORMAL, 0, 0, true);
dsq->game->createEntity(dsq->getEntityTypeIndexByName(lua_tostring(L, 2)), 0, e->position, 0, false, "", ET_ENEMY, 0, 0, true);
luaReturnInt(0);
}
@ -2253,8 +2297,9 @@ luaFunc(entity_setColor)
if (e)
{
//e->color = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4));
e->color.interpolateTo(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4)), lua_tonumber(L, 5));
}
e->color.interpolateTo(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4)),
lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8));
}
luaReturnInt(0);
}
@ -2749,20 +2794,8 @@ luaFunc(createEntity)
int y = lua_tointeger(L, 4);
Entity *e = 0;
e = dsq->game->createEntity(type, 0, Vector(x, y), 0, false, name, ET_ENEMY, BT_NORMAL, 0, 0, true);
e = dsq->game->createEntity(type, 0, Vector(x, y), 0, false, name, ET_ENEMY, 0, 0, true);
/*
int idx = dsq->game->getIdxForEntityType(type);
Entity *e = 0;
if (idx == -1)
{
errorLog("Unknown entity type [" + type + "]");
}
else
{
e = dsq->game->createEntity(idx, 0, Vector(x,y), 0, false, name, ET_ENEMY, BT_NORMAL, 0, 0, true);
}
*/
luaReturnPtr(e);
}
@ -2899,23 +2932,16 @@ luaFunc(entity_setRenderPass)
luaFunc(entity_setHealth)
{
Entity *e = entity(L, 1);
int h = lua_tonumber(L, 2);
if (e)
{
e->health = e->maxHealth = h;
}
e->health = e->maxHealth = lua_tonumber(L, 2);
luaReturnNum(0);
}
// intended to be used for setting max health and refilling it all
luaFunc(entity_changeHealth)
{
Entity *e = entity(L, 1);
int h = lua_tonumber(L, 2);
if (e)
{
e->health += h;
}
e->health += lua_tonumber(L, 2);
luaReturnNum(0);
}
@ -3261,6 +3287,17 @@ luaFunc(node_getName)
luaReturnStr(s);
}
luaFunc(node_getLabel)
{
Path *p = path(L);
const char *s = "";
if (p)
{
s = p->label.c_str();
}
luaReturnStr(s);
}
luaFunc(node_getPathPosition)
{
Path *p = path(L);
@ -3529,20 +3566,16 @@ luaFunc(entity_warpSegments)
luaReturnNum(0);
}
//entity_incrTargetLeaches
luaFunc(entity_incrTargetLeaches)
luaFunc(avatar_incrLeaches)
{
Entity *e = entity(L);
if (e && e->getTargetEntity())
e->getTargetEntity()->leaches++;
dsq->game->avatar->leaches++;
luaReturnNum(0);
}
luaFunc(entity_decrTargetLeaches)
luaFunc(avatar_decrLeaches)
{
Entity *e = entity(L);
if (e && e->getTargetEntity())
e->getTargetEntity()->leaches--;
if(dsq->game->avatar->leaches)
dsq->game->avatar->leaches--;
luaReturnNum(0);
}
@ -3705,7 +3738,7 @@ luaFunc(setNaijaHeadTexture)
Avatar *a = dsq->game->avatar;
if (a)
{
a->setHeadTexture(lua_tostring(L, 1));
a->setHeadTexture(lua_tostring(L, 1), lua_tonumber(L, 2));
}
luaReturnNum(0);
}
@ -5045,7 +5078,8 @@ luaFunc(updateMusic)
luaFunc(entity_grabTarget)
{
Entity *e = entity(L);
e->attachEntity(e->getTargetEntity(), Vector(lua_tointeger(L, 2), lua_tointeger(L, 3)));
if (e)
e->attachEntity(e->getTargetEntity(), Vector(lua_tointeger(L, 2), lua_tointeger(L, 3)));
luaReturnNum(0);
}
@ -5060,7 +5094,7 @@ luaFunc(entity_clampToHit)
luaFunc(entity_clampToSurface)
{
Entity *e = entity(L);
bool ret = e->clampToSurface(lua_tonumber(L, 2));
bool ret = e && e->clampToSurface(lua_tonumber(L, 2));
luaReturnBool(ret);
}
@ -5081,6 +5115,9 @@ luaFunc(entity_checkSurface)
luaFunc(entity_switchSurfaceDirection)
{
ScriptedEntity *e = scriptedEntity(L);
if (!e)
luaReturnNum(0);
int n = -1;
if (lua_isnumber(L, 2))
{
@ -5125,7 +5162,7 @@ luaFunc(entity_switchSurfaceDirection)
luaFunc(entity_adjustPositionBySurfaceNormal)
{
ScriptedEntity *e = scriptedEntity(L);
if (!e->ridingOnEntity)
if (e && !e->ridingOnEntity)
{
Vector v = dsq->game->getWallNormal(e->position);
if (v.x != 0 || v.y != 0)
@ -5144,7 +5181,7 @@ luaFunc(entity_moveAlongSurface)
{
ScriptedEntity *e = scriptedEntity(L);
if (e->isv(EV_CLAMPING,0))
if (e && e->isv(EV_CLAMPING,0))
{
e->lastPosition = e->position;
@ -5299,7 +5336,8 @@ luaFunc(entity_rotateToSurfaceNormal)
luaFunc(entity_releaseTarget)
{
Entity *e = entity(L);
e->detachEntity(e->getTargetEntity());
if (e)
e->detachEntity(e->getTargetEntity());
luaReturnNum(0);
}
@ -5317,7 +5355,10 @@ luaFunc(egetv)
{
Entity *e = entity(L);
EV ev = (EV)lua_tointeger(L, 2);
luaReturnNum(e->getv(ev));
int v = 0;
if (e)
v = e->getv(ev);
luaReturnNum(v);
}
luaFunc(esetvf)
@ -5333,8 +5374,13 @@ luaFunc(esetvf)
luaFunc(egetvf)
{
Entity *e = entity(L);
EV ev = (EV)lua_tointeger(L, 2);
luaReturnNum(e->getvf(ev));
float vf = 0;
if (e)
{
EV ev = (EV)lua_tointeger(L, 2);
vf = e->getvf(ev);
}
luaReturnNum(vf);
}
luaFunc(eisv)
@ -5348,12 +5394,6 @@ luaFunc(eisv)
luaReturnBool(b);
}
luaFunc(entity_setClampOnSwitchDir)
{
debugLog("_setClampOnSwitchDir is old");
luaReturnNum(0);
}
luaFunc(entity_setWidth)
{
Entity *e = entity(L);
@ -5616,14 +5656,16 @@ luaFunc(entity_setProperty)
luaFunc(entity_setActivation)
{
ScriptedEntity *e = scriptedEntity(L);
//if (!e) return;
int type = lua_tonumber(L, 2);
// cursor radius
int activationRadius = lua_tonumber(L, 3);
int range = lua_tonumber(L, 4);
e->activationType = (Entity::ActivationType)type;
e->activationRange = range;
e->activationRadius = activationRadius;
if (e)
{
int type = lua_tonumber(L, 2);
// cursor radius
int activationRadius = lua_tonumber(L, 3);
int range = lua_tonumber(L, 4);
e->activationType = (Entity::ActivationType)type;
e->activationRange = range;
e->activationRadius = activationRadius;
}
luaReturnNum(0);
}
@ -5641,8 +5683,8 @@ luaFunc(entity_setCullRadius)
luaFunc(entity_setActivationType)
{
Entity *e = entity(L);
int type = lua_tonumber(L, 2);
e->activationType = (Entity::ActivationType)type;
if (e)
e->activationType = (Entity::ActivationType)lua_tointeger(L, 2);
luaReturnInt(0);
}
@ -5784,7 +5826,7 @@ luaFunc(entity_moveTowardsTarget)
luaFunc(entity_setVelLen)
{
Entity *e = entity(L);
int len = lua_tonumber(L, 2);
float len = lua_tonumber(L, 2);
if (e)
{
e->vel.setLength2D(len);
@ -5792,6 +5834,15 @@ luaFunc(entity_setVelLen)
luaReturnNum(0);
}
luaFunc(entity_getVel)
{
Entity *e = entity(L);
Vector v;
if (e)
v = e->vel;
luaReturnVec2(v.x, v.y);
}
// entity dt speed dir
luaFunc(entity_moveAroundTarget)
{
@ -5921,7 +5972,8 @@ luaFunc(getEntityByID)
luaFunc(node_setEffectOn)
{
Path *p = path(L, 1);
p->setEffectOn(getBool(L, 2));
if (p)
p->setEffectOn(getBool(L, 2));
luaReturnNum(0);
}
@ -5941,16 +5993,19 @@ luaFunc(node_activate)
luaFunc(node_setElementsInLayerActive)
{
Path *p = path(L);
int l = lua_tonumber(L, 2);
bool v = getBool(L, 3);
for (Element *e = dsq->getFirstElementOnLayer(l); e; e = e->bgLayerNext)
{
if (e && p->isCoordinateInside(e->position))
{
debugLog("setting an element to the value");
e->setElementActive(v);
}
}
if (p)
{
int l = lua_tonumber(L, 2);
bool v = getBool(L, 3);
for (Element *e = dsq->getFirstElementOnLayer(l); e; e = e->bgLayerNext)
{
if (e && p->isCoordinateInside(e->position))
{
debugLog("setting an element to the value");
e->setElementActive(v);
}
}
}
luaReturnNum(0);
}
@ -5991,7 +6046,6 @@ luaFunc(node_getNumEntitiesIn)
luaFunc(node_getNearestEntity)
{
//Entity *me = entity(L);
Path *p = path(L);
Entity *closest=0;
@ -6000,14 +6054,17 @@ luaFunc(node_getNearestEntity)
Vector pos = p->nodes[0].position;
std::string name;
Entity *ignore = 0;
if (lua_isstring(L, 2))
name = lua_tostring(L, 2);
if (lua_isuserdata(L, 3))
ignore = entity(L, 3);
float smallestDist = HUGE_VALF;
FOR_ENTITIES(i)
{
Entity *e = *i;
if (e->isPresent() && e->isNormalLayer())
if (e != ignore && e->isPresent() && e->isNormalLayer())
{
if (name.empty() || (nocasecmp(e->name, name)==0))
{
@ -6026,7 +6083,6 @@ luaFunc(node_getNearestEntity)
luaFunc(node_getNearestNode)
{
//Entity *me = entity(L);
Path *p = path(L);
Path *closest = 0;
if (p && !p->nodes.empty())
@ -6034,7 +6090,8 @@ luaFunc(node_getNearestNode)
std::string name;
if (lua_isstring(L, 2))
name = lua_tostring(L, 2);
closest = dsq->game->getNearestPath(p->nodes[0].position, name);
Path *ignore = path(L, 3);
closest = dsq->game->getNearestPath(p->nodes[0].position, name, ignore);
}
luaReturnPtr(closest);
}
@ -6064,25 +6121,31 @@ luaFunc(entity_getNearestBoneToPosition)
luaFunc(entity_getNearestNode)
{
Entity *me = entity(L);
std::string name;
if (lua_isstring(L, 2))
name = lua_tostring(L, 2);
Path *ignore = path(L, 3);
Path *closest = dsq->game->getNearestPath(me->position, name, ignore);
Path *closest = 0;
if (me)
{
std::string name;
if (lua_isstring(L, 2))
name = lua_tostring(L, 2);
Path *ignore = path(L, 3);
closest = dsq->game->getNearestPath(me->position, name, ignore);
}
luaReturnPtr(closest);
}
luaFunc(ing_hasIET)
{
Ingredient *i = getIng(L, 1);
bool has = i->hasIET((IngredientEffectType)lua_tointeger(L, 2));
bool has = i && i->hasIET((IngredientEffectType)lua_tointeger(L, 2));
luaReturnBool(has);
}
luaFunc(entity_getNearestEntity)
{
Entity *me = entity(L);
if (!me)
luaReturnPtr(0);
const char *name = 0;
if (lua_isstring(L, 2))
{
@ -6098,21 +6161,25 @@ luaFunc(entity_getNearestEntity)
nameCheck = false;
}
int range = lua_tointeger(L, 3);
float range = lua_tointeger(L, 3);
int type = lua_tointeger(L, 4);
int damageTarget = lua_tointeger(L, 5);
Entity *closest = 0;
Entity *ignore = 0;
if (lua_isuserdata(L, 6))
ignore = entity(L, 6);
float smallestDist = range ? sqr(range) : HUGE_VALF;
FOR_ENTITIES(i)
{
Entity *e = *i;
if (e != me && e->isPresent() && e->isNormalLayer())
if (e != me && e != ignore && e->isPresent() && e->isNormalLayer())
{
if (!name || ((nocasecmp(e->name, name)==0) == nameCheck))
if (type == 0 || e->getEntityType() == type)
{
if (type == 0 || e->getEntityType() == type)
if (damageTarget == 0 || e->isDamageTarget((DamageType)damageTarget))
{
if (damageTarget == 0 || e->isDamageTarget((DamageType)damageTarget))
if (!name || ((nocasecmp(e->name, name)==0) == nameCheck))
{
float dist = (me->position - e->position).getSquaredLength2D();
if (dist < smallestDist)
@ -6235,15 +6302,17 @@ luaFunc(entity_alpha)
luaFunc(entity_partAlpha)
{
ScriptedEntity *e = scriptedEntity(L);
RenderObject *r = e->partMap[lua_tostring(L, 2)];
if (r)
{
float start = lua_tonumber(L, 3);
if (start != -1)
r->alpha = start;
r->alpha.interpolateTo(lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8));
}
if (e)
{
RenderObject *r = e->partMap[lua_tostring(L, 2)];
if (r)
{
float start = lua_tonumber(L, 3);
if (start != -1)
r->alpha = start;
r->alpha.interpolateTo(lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8));
}
}
luaReturnNum(0);
}
@ -6251,18 +6320,22 @@ luaFunc(entity_partAlpha)
luaFunc(entity_partBlendType)
{
ScriptedEntity *e = scriptedEntity(L);
e->partMap[lua_tostring(L, 2)]->setBlendType(lua_tointeger(L, 3));
if (e)
e->partMap[lua_tostring(L, 2)]->setBlendType(lua_tointeger(L, 3));
luaReturnInt(0);
}
luaFunc(entity_partRotate)
{
ScriptedEntity *e = scriptedEntity(L);
RenderObject *r = e->partMap[lua_tostring(L, 2)];
if (r)
{
r->rotation.interpolateTo(Vector(0,0,lua_tointeger(L, 3)), lua_tonumber(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7));
}
if (e)
{
RenderObject *r = e->partMap[lua_tostring(L, 2)];
if (r)
{
r->rotation.interpolateTo(Vector(0,0,lua_tointeger(L, 3)), lua_tonumber(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7));
}
}
luaReturnNum(0);
}
@ -6302,24 +6375,30 @@ luaFunc(entity_offsetUpdate)
luaFunc(entity_scale)
{
Entity *e = entity(L);
float time = lua_tonumber(L, 4);
//e->scale = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3));
e->scale.interpolateTo(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3), 0), time, lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7));
luaReturnNum(0);
if (e)
{
float time = lua_tonumber(L, 4);
//e->scale = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3));
e->scale.interpolateTo(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3), 0), time, lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7));
}
luaReturnNum(0);
}
luaFunc(entity_switchLayer)
{
Entity *e = entity(L);
int lcode = lua_tonumber(L, 2);
int toLayer = LR_ENTITIES;
if (e)
{
int lcode = lua_tonumber(L, 2);
int toLayer = LR_ENTITIES;
toLayer = dsq->getEntityLayerToLayer(lcode);
toLayer = dsq->getEntityLayerToLayer(lcode);
if (e->getEntityType() == ET_AVATAR)
toLayer = LR_ENTITIES;
if (e->getEntityType() == ET_AVATAR)
toLayer = LR_ENTITIES;
core->switchRenderObjectLayer(e, toLayer);
core->switchRenderObjectLayer(e, toLayer);
}
luaReturnNum(0);
}
@ -6428,22 +6507,24 @@ luaFunc(entity_initPart)
ScriptedEntity *e = scriptedEntity(L);
Quad *q = new Quad;
q->setTexture(partTex);
q->renderBeforeParent = !renderAfter;
if (e)
{
Quad *q = new Quad;
q->setTexture(partTex);
q->renderBeforeParent = !renderAfter;
q->position = partPosition;
if (offsetInterpolateTo.x != 0 || offsetInterpolateTo.y != 0)
q->offset.interpolateTo(offsetInterpolateTo, offsetInterpolateTime, -1, 1, 1);
if (partFlipH)
q->flipHorizontal();
if (partFlipV)
q->flipVertical();
q->position = partPosition;
if (offsetInterpolateTo.x != 0 || offsetInterpolateTo.y != 0)
q->offset.interpolateTo(offsetInterpolateTo, offsetInterpolateTime, -1, 1, 1);
if (partFlipH)
q->flipHorizontal();
if (partFlipV)
q->flipVertical();
e->addChild(q, PM_POINTER);
e->registerNewPart(q, partName);
e->addChild(q, PM_POINTER);
e->registerNewPart(q, partName);
}
luaReturnNum(0);
}
@ -7021,6 +7102,18 @@ luaFunc(entity_setFlag)
luaReturnNum(0);
}
luaFunc(entity_getFlag)
{
Entity *e = entity(L);
int v = lua_tonumber(L, 2);
int ret = 0;
if (e)
{
ret = dsq->continuity.getEntityFlag(dsq->game->sceneName, e->getID());
}
luaReturnNum(ret);
}
luaFunc(isFlag)
{
int v = 0;
@ -7211,9 +7304,6 @@ static const struct {
luaRegister(entity_setIngredient),
luaRegister(entity_setDeathScene),
luaRegister(entity_setClampOnSwitchDir),
luaRegister(entity_setBeautyFlip),
luaRegister(entity_setInvincible),
@ -7477,8 +7567,8 @@ static const struct {
luaRegister(entity_getTargetPositionX),
luaRegister(entity_getTargetPositionY),
luaRegister(entity_incrTargetLeaches),
luaRegister(entity_decrTargetLeaches),
luaRegister(avatar_incrLeaches),
luaRegister(avatar_decrLeaches),
luaRegister(entity_rotateToVel),
luaRegister(entity_rotateToVec),
@ -7548,6 +7638,7 @@ static const struct {
luaRegister(entity_moveAround),
luaRegister(entity_setVelLen),
luaRegister(entity_getVel),
luaRegister(entity_setMaxSpeed),
luaRegister(entity_getMaxSpeed),
@ -7736,6 +7827,7 @@ static const struct {
luaRegister(entity_isFlag),
luaRegister(entity_setFlag),
luaRegister(entity_getFlag),
luaRegister(node_isFlag),
luaRegister(node_setFlag),
@ -7909,6 +8001,7 @@ static const struct {
luaRegister(node_activate),
luaRegister(node_getName),
luaRegister(node_getLabel),
luaRegister(node_getPathPosition),
luaRegister(node_getPosition),
luaRegister(node_setPosition),
@ -8079,6 +8172,12 @@ static const struct {
luaRegister(getWallNormal),
luaRegister(getLastCollidePosition),
// -- deprecated/compatibility related functions below here --
{"entity_incrTargetLeaches", l_avatar_incrLeaches},
{"entity_decrTargetLeaches", l_avatar_decrLeaches},
};
//============================================================================================
@ -8341,11 +8440,6 @@ static const struct {
luaConstant(EP_BATTERY),
luaConstant(EP_BLOCKER),
// Entity Behaviors
luaConstant(BT_NORMAL),
luaConstant(BT_MOTHER),
luaConstant(BT_ACTIVEPET),
// ACTIVATION TYPES
{"AT_NONE", -1},
{"AT_NORMAL", 0},
@ -8905,7 +8999,7 @@ void ScriptInterface::shutdown()
{
}
Script *ScriptInterface::openScript(const std::string &file)
Script *ScriptInterface::openScript(const std::string &file, bool ignoremissing /* = false */)
{
std::string realFile = core->adjustFilenameCase(file);
bool loadedScript = false;
@ -8944,8 +9038,9 @@ Script *ScriptInterface::openScript(const std::string &file)
int result = luaL_loadfile(baseState, realFile.c_str());
if (result != 0)
{
debugLog("Error loading script [" + realFile + "]: " + lua_tostring(baseState, -1));
lua_pop(baseState, 2);
if(result != LUA_ERRFILE || (result == LUA_ERRFILE && !ignoremissing))
scriptError("Error loading script [" + realFile + "]: " + lua_tostring(baseState, -1));
lua_pop(baseState, 2);
return NULL;
}
@ -8964,7 +9059,7 @@ Script *ScriptInterface::openScript(const std::string &file)
lua_pop(baseState, 1);
if (result != 0)
{
debugLog("Error doing initial run of script [" + realFile + "]: " + lua_tostring(baseState, -1));
scriptError("Error doing initial run of script [" + realFile + "]: " + lua_tostring(baseState, -1));
lua_pop(baseState, 2);
return NULL;
}
@ -9006,7 +9101,7 @@ Script *ScriptInterface::openScript(const std::string &file)
lua_State *thread = createLuaThread(realFile.c_str());
if (!thread)
{
debugLog("Unable to create new thread for script [" + realFile + "]");
scriptError("Unable to create new thread for script [" + realFile + "]");
if (loadedScript)
{
lua_getglobal(baseState, "_scriptfuncs");
@ -9066,12 +9161,12 @@ bool ScriptInterface::runScriptNum(const std::string &file, const std::string &f
return true;
}
bool ScriptInterface::runScript(const std::string &file, const std::string &func)
bool ScriptInterface::runScript(const std::string &file, const std::string &func, bool ignoremissing /* = false */)
{
std::string realFile = file;
if (file.find('/')==std::string::npos)
realFile = "scripts/" + file + ".lua";
Script *script = openScript(realFile);
Script *script = openScript(realFile, ignoremissing);
if (!script)
return false;

View file

@ -81,10 +81,10 @@ public:
void collectGarbage();
void shutdown();
Script *openScript(const std::string &file);
Script *openScript(const std::string &file, bool ignoremissing = false);
void closeScript(Script *script);
bool runScript(const std::string &file, const std::string &func);
bool runScript(const std::string &file, const std::string &func, bool ignoremissing = false);
bool runScriptNum(const std::string &file, const std::string &func, int num);
protected:

View file

@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
bool ScriptedEntity::runningActivation = false;
ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, EntityType et, BehaviorType bt) : CollideEntity(), Segmented(2, 26)
ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, EntityType et) : CollideEntity(), Segmented(2, 26)
{
crushDelay = 0;
autoSkeletalSpriteUpdate = true;
@ -41,21 +41,14 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E
preUpdateFunc = true;
//runningActivation = false;
expType = -1;
eggSpawnRate = 10;
motherDelay = 0;
setEntityType(et);
setBehaviorType(bt);
eggDataIdx = -1;
//behavior = BT_NORMAL;
myTimer = 0;
layer = LR_ENTITIES;
surfaceMoveDir = 1;
this->position = position;
numSegments = 0;
reverseSegments = false;
manaBallAmount = moneyAmount = 1;
manaBallAmount = 1;
this->name = scriptName;
std::string file;
@ -83,7 +76,7 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E
script = dsq->scriptInterface.openScript(file);
if (!script)
{
errorLog("Could not load script [" + file + "]");
debugLog("Could not load script [" + file + "]");
}
}
@ -250,8 +243,7 @@ void ScriptedEntity::setupEntity(const std::string &tex, int lcode)
setTexture(tex);
updateCull = -1;
manaBallAmount = moneyAmount = 0;
expType = -1;
manaBallAmount = 0;
setState(STATE_IDLE);
this->layer = dsq->getEntityLayerToLayer(lcode);
@ -261,7 +253,6 @@ void ScriptedEntity::setupBasicEntity(std::string texture, int health, int manaB
{
//this->updateCull = updateCull;
updateCull = -1;
this->collideWithEntity = hitEntity;
if (texture.empty())
renderQuad = false;
@ -271,11 +262,8 @@ void ScriptedEntity::setupBasicEntity(std::string texture, int health, int manaB
this->collideRadius = collideRadius;
setState(state);
this->manaBallAmount = manaBall;
this->exp = exp;
this->moneyAmount = money;
width = w;
height = h;
this->expType = expType;
setEntityLayer(layer);
}
@ -782,16 +770,6 @@ bool ScriptedEntity::damage(const DamageData &d)
return false;
}
void ScriptedEntity::onHitEntity(const CollideData &c)
{
CollideEntity::onHitEntity(c);
if (script)
{
script->call("hitEntity", this, c.entity, c.bone);
}
}
void ScriptedEntity::songNote(int note)
{
Entity::songNote(note);
@ -996,14 +974,14 @@ void ScriptedEntity::onEnterState(int action)
case STATE_DEAD:
if (!isGoingToBeEaten())
{
doDeathEffects(manaBallAmount, moneyAmount);
doDeathEffects(manaBallAmount);
dsq->spawnParticleEffect(deathParticleEffect, position);
onDieNormal();
}
else
{
// eaten
doDeathEffects(0, 0);
doDeathEffects(0);
onDieEaten();
}
destroySegments(1);

View file

@ -27,7 +27,7 @@ struct lua_State;
class ScriptedEntity : public CollideEntity, public Segmented
{
public:
ScriptedEntity(const std::string &scriptName, Vector position, EntityType et = ET_ENEMY, BehaviorType bt = BT_NORMAL);
ScriptedEntity(const std::string &scriptName, Vector position, EntityType et = ET_ENEMY);
void init();
void postInit();
void destroy();
@ -42,7 +42,6 @@ public:
typedef std::map<std::string, RenderObject*> PartMap;
PartMap partMap;
bool surfaceMoveDir;
Vector lastWallOffset;
void activate();
void warpSegments();
void lightFlare();
@ -103,16 +102,10 @@ protected:
bool animKeyFunc;
//void onPathEnd();
float motherDelay;
float eggSpawnRate;
int eggDataIdx;
void onExitTimer();
void onHitEntity(const CollideData &c);
float myTimer;
void onHitWall();
bool reverseSegments;
int moneyAmount, expType;
Script *script;
void onUpdate(float dt);
void onEnterState(int action);

View file

@ -512,7 +512,7 @@ void Shot::onHitWall()
{
if (!shotData->spawnEntity.empty())
{
dsq->game->createEntity(shotData->spawnEntity, 0, position, 0, false, "", ET_ENEMY, BT_NORMAL, 0, 0, true);
dsq->game->createEntity(shotData->spawnEntity, 0, position, 0, false, "", ET_ENEMY, 0, 0, true);
//(shotData->spawnEntity, 0, position, 0, false, "");
if (shotData->spawnEntity == "NatureFormFlowers")
{

View file

@ -35,7 +35,7 @@ v.spawnTimes = 1
v.sfxVol = 1
function v.commonInit(me, fle, cr, h, num, snd, ignoreSets, stimes, svol)
if svol ~= 0 then
if svol and svol ~= 0 then
v.sfxVol = svol
end

View file

@ -114,7 +114,7 @@ function enterState(me)
elseif entity_getState(me)==STATE_ATTACHED then
entity_setEntityType(me, ET_NEUTRAL)
entity_setMaxSpeed(me, 0)
entity_incrTargetLeaches(me)
avatar_incrLeaches()
entity_sound(me, "Leach")
v.attachBone = entity_getNearestBoneToPosition(entity_getTarget(me), entity_getPosition(me))
--[[
@ -132,7 +132,7 @@ end
function exitState(me)
if entity_getState(me)==STATE_ATTACHED then
-- entity_setState(STATE_IDLE)
entity_decrTargetLeaches(me)
avatar_decrLeaches()
elseif entity_isState(me, STATE_FLYOFF) then
entity_setState(me, STATE_IDLE)
end

View file

@ -1213,7 +1213,7 @@ function enterState(me, state)
entity_setNaijaReaction(me, "")
-- FIXME: There's no "shock" expression; what was intended? --achurch
expression(me, shock, 1)
--expression(me, shock, 1) -- removed for now to prevent warnings in strict mode --fg
entity_clearVel(me)
entity_clearVel(v.n)