mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-04 02:24:00 +00:00
Make maxSpeed float, little cleanup, minor Lua API stuff
Plus additional functions that don't use speed types: + entity_followPathSpeed() + entity_moveToNodeSpeed() + entity_swimToNodeSpeed() + entity_swimToPositionSpeed() The following old functions (plus all of the above) return float now (how long moving will take): * entity_followPath() * entity_moveToNode() * entity_swimToNode) * entity_swimToPosition()
This commit is contained in:
parent
8bd40be8aa
commit
209964034d
6 changed files with 116 additions and 129 deletions
|
@ -3661,7 +3661,8 @@ void Continuity::reset()
|
|||
|
||||
speedTypes.clear();
|
||||
InStream inFile("data/speedtypes.txt");
|
||||
int n, spd;
|
||||
int n;
|
||||
float spd;
|
||||
while (inFile >> n)
|
||||
{
|
||||
inFile >> spd;
|
||||
|
@ -3679,7 +3680,7 @@ void Continuity::reset()
|
|||
core->resetTimer();
|
||||
}
|
||||
|
||||
int Continuity::getSpeedType(int speedType)
|
||||
float Continuity::getSpeedType(int speedType)
|
||||
{
|
||||
if (speedType >= speedTypes.size() || speedType < 0)
|
||||
{
|
||||
|
|
|
@ -3869,58 +3869,6 @@ void DSQ::jumpToSection(InStream &inFile, const std::string §ion)
|
|||
debugLog("could not find section [" + section + "]");
|
||||
}
|
||||
|
||||
|
||||
void DSQ::runGesture(const std::string &line)
|
||||
{
|
||||
std::istringstream is(line);
|
||||
std::string target;
|
||||
is >> target;
|
||||
debugLog("Gesture: " + line);
|
||||
if (target == "entity")
|
||||
{
|
||||
std::string entName;
|
||||
is >> entName;
|
||||
Entity *e = getEntityByName(entName);
|
||||
if (e)
|
||||
{
|
||||
std::string cmd;
|
||||
is >> cmd;
|
||||
if (cmd=="anim" || cmd=="animate")
|
||||
{
|
||||
std::string anim;
|
||||
is >> anim;
|
||||
int loop = 0;
|
||||
int group = 0;
|
||||
if (anim == "idle")
|
||||
{
|
||||
e->skeletalSprite.stopAllAnimations();
|
||||
loop = -1;
|
||||
}
|
||||
if (line.find("upperBody")!=std::string::npos)
|
||||
{
|
||||
group = 1;
|
||||
}
|
||||
if (line.find("loop")!=std::string::npos)
|
||||
{
|
||||
loop = -1;
|
||||
}
|
||||
if (line.find("stopAll")!=std::string::npos)
|
||||
{
|
||||
e->skeletalSprite.stopAllAnimations();
|
||||
}
|
||||
e->skeletalSprite.transitionAnimate(anim, 0.2, loop, group);
|
||||
}
|
||||
else if (cmd == "moveToNode")
|
||||
{
|
||||
std::string node;
|
||||
is >> node;
|
||||
Path *p = dsq->game->getPathByName(node);
|
||||
e->moveToNode(p, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DSQ::runScript(const std::string &name, const std::string &function, bool ignoremissing /* = false */)
|
||||
{
|
||||
if (!scriptInterface.runScript(name, function, ignoremissing))
|
||||
|
|
|
@ -992,7 +992,7 @@ public:
|
|||
float getStory();
|
||||
void setStory(float v);
|
||||
|
||||
int getSpeedType(int speedType);
|
||||
float getSpeedType(int speedType);
|
||||
void setNaijaModel(std::string model);
|
||||
|
||||
|
||||
|
@ -1159,7 +1159,7 @@ public:
|
|||
|
||||
protected:
|
||||
std::vector<EatData> eats;
|
||||
std::vector<int> speedTypes;
|
||||
std::vector<float> speedTypes;
|
||||
float story;
|
||||
WorldType worldType;
|
||||
|
||||
|
@ -1395,7 +1395,6 @@ public:
|
|||
|
||||
void jumpToSection(InStream &inFile, const std::string §ion);
|
||||
|
||||
void runGesture(const std::string &line);
|
||||
void generateCollisionMask(RenderObject *r);
|
||||
void toggleRenderCollisionShapes();
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ Entity::Entity()
|
|||
//debugLog("dsq->addEntity()");
|
||||
|
||||
dsq->addEntity(this);
|
||||
maxSpeed = oldMaxSpeed = 300;
|
||||
maxSpeed = 300;
|
||||
entityDead = false;
|
||||
health = maxHealth = 5;
|
||||
invincibleBreak = false;
|
||||
|
@ -440,10 +440,10 @@ void Entity::setName(const std::string &name)
|
|||
this->name = name;
|
||||
}
|
||||
|
||||
void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd)
|
||||
float Entity::followPath(Path *p, float speed, int dir, bool deleteOnEnd)
|
||||
{
|
||||
if (p)
|
||||
{
|
||||
if(!speed)
|
||||
speed = getMaxSpeed();
|
||||
deleteOnPathEnd = deleteOnEnd;
|
||||
|
||||
position.stopPath();
|
||||
|
@ -466,17 +466,19 @@ void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd)
|
|||
}
|
||||
}
|
||||
//debugLog("Calculating Time");
|
||||
float time = position.data->path.getLength()/(float)dsq->continuity.getSpeedType(speedType);
|
||||
float time = position.data->path.getLength()/speed;
|
||||
//debugLog("Starting");
|
||||
position.data->path.getPathNode(0)->value = position;
|
||||
position.startPath(time);//, 1.0f/2.0f);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim)
|
||||
float Entity::moveToPos(Vector dest, float speed, int dieOnPathEnd, bool swim)
|
||||
{
|
||||
if(!speed)
|
||||
speed = getMaxSpeed();
|
||||
|
||||
Vector start = position;
|
||||
Vector dest = path->nodes[0].position;
|
||||
followEntity = 0;
|
||||
//watchingEntity = 0;
|
||||
|
||||
|
@ -519,7 +521,7 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim)
|
|||
//debugLog("Done");
|
||||
|
||||
//debugLog("Calculating Time");
|
||||
float time = position.data->path.getLength()/(float)dsq->continuity.getSpeedType(speedType);
|
||||
float time = position.data->path.getLength()/speed;
|
||||
//debugLog("Starting");
|
||||
position.data->path.getPathNode(0)->value = position;
|
||||
position.startPath(time);//, 1.0f/2.0f);
|
||||
|
@ -536,6 +538,8 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim)
|
|||
|
||||
//position.startSpeedPath(dsq->continuity.getSpeedType(speedType));
|
||||
//position.startPath(((position.data->path.getNumPathNodes()*TILE_SIZE*4)-2)/dsq->continuity.getSpeedType(speedType));
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
void Entity::stopFollowingPath()
|
||||
|
@ -1010,7 +1014,7 @@ bool Entity::isNearObstruction(int sz, int type, TileVector *hitTile)
|
|||
return v;
|
||||
}
|
||||
|
||||
bool Entity::touchAvatarDamage(int radius, float dmg, const Vector &override, int speed, float pushTime, Vector collidePos)
|
||||
bool Entity::touchAvatarDamage(int radius, float dmg, const Vector &override, float speed, float pushTime, Vector collidePos)
|
||||
{
|
||||
if (isv(EV_BEASTBURST, 1) && isDamageTarget(DT_AVATAR_BITE) && dsq->continuity.form == FORM_BEAST && dsq->game->avatar->bursting)
|
||||
{
|
||||
|
@ -2213,7 +2217,7 @@ bool Entity::isUnderWater(const Vector &override)
|
|||
return false;
|
||||
}
|
||||
|
||||
void Entity::push(const Vector &vec, float time, int maxSpeed, float dmg)
|
||||
void Entity::push(const Vector &vec, float time, float maxSpeed, float dmg)
|
||||
{
|
||||
if (!this->isEntityDead())
|
||||
{
|
||||
|
@ -2234,9 +2238,9 @@ void Entity::push(const Vector &vec, float time, int maxSpeed, float dmg)
|
|||
//vel += pushVec;
|
||||
}
|
||||
|
||||
void Entity::setMaxSpeed(int ms)
|
||||
void Entity::setMaxSpeed(float ms)
|
||||
{
|
||||
maxSpeed = oldMaxSpeed = ms;
|
||||
maxSpeed = ms;
|
||||
}
|
||||
|
||||
int Entity::getMaxSpeed()
|
||||
|
@ -2395,11 +2399,6 @@ void Entity::onEnterState(int action)
|
|||
{
|
||||
switch (action)
|
||||
{
|
||||
case STATE_IDLE:
|
||||
{
|
||||
maxSpeed = oldMaxSpeed;
|
||||
}
|
||||
break;
|
||||
case STATE_DEAD:
|
||||
{
|
||||
if (!isGoingToBeEaten())
|
||||
|
@ -3020,7 +3019,7 @@ void Entity::shotHitEntity(Entity *hit, Shot *shot, Bone *b)
|
|||
{
|
||||
}
|
||||
|
||||
bool Entity::doCollisionAvoidance(float dt, int search, float mod, Vector *vp, int overrideMaxSpeed, int ignoreObs, bool onlyVP)
|
||||
bool Entity::doCollisionAvoidance(float dt, int search, float mod, Vector *vp, float overrideMaxSpeed, int ignoreObs, bool onlyVP)
|
||||
{
|
||||
Vector accum;
|
||||
int c = 0;
|
||||
|
|
|
@ -233,7 +233,7 @@ public:
|
|||
|
||||
void heal(float a, int type=0);
|
||||
|
||||
void push(const Vector &vec, float time, int maxSpeed, float dmg);
|
||||
void push(const Vector &vec, float time, float maxSpeed, float dmg);
|
||||
|
||||
bool canSetState(int state);
|
||||
|
||||
|
@ -312,9 +312,9 @@ public:
|
|||
};
|
||||
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);
|
||||
float followPath(Path *p, float speed, int dir, bool deleteOnEnd = false);
|
||||
Entity *attachedTo;
|
||||
bool touchAvatarDamage(int radius, float dmg, const Vector &override=Vector(-1,-1,-1), int speed=0, float pushTime = 0, Vector collidePos = Vector(0,0,0));
|
||||
bool touchAvatarDamage(int radius, float dmg, const Vector &override=Vector(-1,-1,-1), float speed=0, float pushTime = 0, Vector collidePos = Vector(0,0,0));
|
||||
|
||||
void moveTowards(Vector p, float dt, int spd);
|
||||
void moveAround(Vector p, float dt, int spd, int d);
|
||||
|
@ -327,10 +327,10 @@ public:
|
|||
void moveAroundEntity(float dt, int spd, int d, Entity *e);
|
||||
void moveTowardsGroupCenter(float dt, int spd);
|
||||
void moveTowardsGroupHeading(float dt, int spd);
|
||||
bool doCollisionAvoidance(float dt, int search, float mod, Vector *v = 0, int overrideMaxSpeed=0, int ignoreObs=0, bool onlyVP=false);
|
||||
bool doCollisionAvoidance(float dt, int search, float mod, Vector *v = 0, float overrideMaxSpeed=0, int ignoreObs=0, bool onlyVP=false);
|
||||
void doSpellAvoidance(float dt, int range, float mod);
|
||||
void doEntityAvoidance(float dt, int range, float mod, Entity *ignore =0);
|
||||
void setMaxSpeed(int ms);
|
||||
void setMaxSpeed(float ms);
|
||||
Entity *findTarget(int dist, int type, int t=0);
|
||||
//bool hasTarget() { return target != 0; }
|
||||
bool hasTarget(int t=0);
|
||||
|
@ -353,7 +353,7 @@ public:
|
|||
void overideMaxSpeed(int ms, float time);
|
||||
void disableOverideMaxSpeed();
|
||||
int currentEntityTarget;
|
||||
void moveToNode(Path *path, int speedType, int dieOnPathEnd=0, bool swim = false);
|
||||
float moveToPos(Vector pos, float speed, int dieOnPathEnd=0, bool swim = false);
|
||||
bool isHit();
|
||||
bool pathBurst(bool wallJump = false);
|
||||
Timer burstTimer;
|
||||
|
@ -599,7 +599,7 @@ protected:
|
|||
|
||||
void updateBoneLock();
|
||||
|
||||
int pushMaxSpeed;
|
||||
float pushMaxSpeed;
|
||||
std::string currentAnim;
|
||||
|
||||
|
||||
|
@ -610,8 +610,7 @@ protected:
|
|||
private:
|
||||
|
||||
|
||||
int maxSpeed;
|
||||
int oldMaxSpeed;
|
||||
float maxSpeed;
|
||||
|
||||
bool stopSoundsOnDeath;
|
||||
|
||||
|
|
|
@ -3326,45 +3326,67 @@ luaFunc(entity_moveToNode)
|
|||
{
|
||||
Entity *e = entity(L);
|
||||
Path *p = path(L, 2);
|
||||
float time = 0;
|
||||
if (e && p)
|
||||
{
|
||||
e->moveToNode(p, lua_tointeger(L, 3), lua_tointeger(L, 4), 0);
|
||||
float speed = dsq->continuity.getSpeedType(lua_tointeger(L, 3));
|
||||
time = e->moveToPos(p->nodes[0].position, speed, lua_tointeger(L, 4), 0);
|
||||
}
|
||||
luaReturnNil();
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(entity_swimToNode)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
Path *p = path(L, 2);
|
||||
float time = 0;
|
||||
if (e && p)
|
||||
{
|
||||
e->moveToNode(p, lua_tointeger(L, 3), lua_tointeger(L, 4), 1);
|
||||
/*
|
||||
ScriptedEntity *se = dynamic_cast<ScriptedEntity*>(e);
|
||||
se->swimPath = true;
|
||||
*/
|
||||
float speed = dsq->continuity.getSpeedType(lua_tointeger(L, 3));
|
||||
time = e->moveToPos(p->nodes[0].position, speed, lua_tointeger(L, 4), 1);
|
||||
}
|
||||
luaReturnNil();
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(entity_swimToPosition)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
//Path *p = path(L, 2);
|
||||
Path p;
|
||||
PathNode n;
|
||||
n.position = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3));
|
||||
p.nodes.push_back(n);
|
||||
float time = 0;
|
||||
if (e)
|
||||
{
|
||||
e->moveToNode(&p, lua_tointeger(L, 4), lua_tointeger(L, 5), 1);
|
||||
/*
|
||||
ScriptedEntity *se = dynamic_cast<ScriptedEntity*>(e);
|
||||
se->swimPath = true;
|
||||
*/
|
||||
float speed = dsq->continuity.getSpeedType(lua_tointeger(L, 4));
|
||||
time = e->moveToPos(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), speed, lua_tointeger(L, 5), 1);
|
||||
}
|
||||
luaReturnNil();
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(entity_moveToNodeSpeed)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
Path *p = path(L, 2);
|
||||
float time = 0;
|
||||
if (e && p)
|
||||
time = e->moveToPos(p->nodes[0].position, lua_tonumber(L, 3), lua_tointeger(L, 4), 0);
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(entity_swimToNodeSpeed)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
Path *p = path(L, 2);
|
||||
float time = 0;
|
||||
if (e && p)
|
||||
time = e->moveToPos(p->nodes[0].position, lua_tonumber(L, 3), lua_tointeger(L, 4), 1);
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(entity_swimToPositionSpeed)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
float time = 0;
|
||||
if (e)
|
||||
time = e->moveToPos(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), lua_tonumber(L, 4), lua_tointeger(L, 5), 1);
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3650,15 +3672,30 @@ luaFunc(loadMap)
|
|||
luaFunc(entity_followPath)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
float time = 0;
|
||||
if (e)
|
||||
{
|
||||
Path *p = path(L, 2);
|
||||
int speedType = lua_tointeger(L, 3);
|
||||
int dir = lua_tointeger(L, 4);
|
||||
|
||||
e->followPath(p, speedType, dir);
|
||||
float speed = dsq->continuity.getSpeedType(speedType);
|
||||
time = e->followPath(p, speed, dir);
|
||||
}
|
||||
luaReturnNil();
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(entity_followPathSpeed)
|
||||
{
|
||||
Entity *e = entity(L);
|
||||
float time = 0;
|
||||
if (e)
|
||||
{
|
||||
Path *p = path(L, 2);
|
||||
float speed = lua_tonumber(L, 3);
|
||||
int dir = lua_tointeger(L, 4);
|
||||
time = e->followPath(p, speed, dir);
|
||||
}
|
||||
luaReturnNum(time);
|
||||
}
|
||||
|
||||
luaFunc(spawnIngredient)
|
||||
|
@ -6058,7 +6095,7 @@ luaFunc(entity_setMaxSpeed)
|
|||
{
|
||||
Entity *e = entity(L);
|
||||
if (e)
|
||||
e->setMaxSpeed(lua_tointeger(L, 2));
|
||||
e->setMaxSpeed(lua_tonumber(L, 2));
|
||||
|
||||
luaReturnNil();
|
||||
}
|
||||
|
@ -9599,6 +9636,7 @@ static const struct {
|
|||
luaRegister(entity_stopInterpolating),
|
||||
|
||||
luaRegister(entity_followPath),
|
||||
luaRegister(entity_followPathSpeed),
|
||||
luaRegister(entity_isFollowingPath),
|
||||
luaRegister(entity_followEntity),
|
||||
luaRegister(entity_sound),
|
||||
|
@ -9852,6 +9890,7 @@ static const struct {
|
|||
|
||||
luaRegister(entity_warpToNode),
|
||||
luaRegister(entity_moveToNode),
|
||||
luaRegister(entity_moveToNodeSpeed),
|
||||
|
||||
luaRegister(cam_toNode),
|
||||
luaRegister(cam_snap),
|
||||
|
@ -9866,7 +9905,9 @@ static const struct {
|
|||
luaRegister(entity_flipToVel),
|
||||
|
||||
luaRegister(entity_swimToNode),
|
||||
luaRegister(entity_swimToNodeSpeed),
|
||||
luaRegister(entity_swimToPosition),
|
||||
luaRegister(entity_swimToPositionSpeed),
|
||||
|
||||
|
||||
luaRegister(createShot),
|
||||
|
|
Loading…
Add table
Reference in a new issue