1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-03 18:14:01 +00:00
Aquaria/Aquaria/ScriptedEntity.h
fgenesis aa067be1f7 Rework and fix entity spawning and ID handling.
Bugfix: Actually call postInit() for entities spawned via "se" node.
Bugfix: Don't call postInit() twice for the active pet

Previously, f55a70b459 changed entity ID handling so that
script-spawned entities have negative IDs and entities placed
on the map have positive IDs.
Turns out that positive IDs were still flaky due to frequent renumbering
upon map load. Typically entity IDs are assigned sequentially, and if,
upon loading, an entity with an already existing ID was to be spawned,
that new entity would be assigned a new unique ID (often its ID+1).
That in turn would often cascade into a long string of IDs falsely
considered conflicting because one bad entity started the entire thing.

During lots of map editing I've noticed that sometimes after adding an
entity to an older map, saving, and loading, many entities could be shuffled
around on the map. I'm not 100% sure this bug is related (and it may or
may not be fixed, i don't know yet, time will tell)
but at least entity numbering should be fine now.

This change properly and permanently renumbers entities so that upon map save,
the problem will no longer occur on subsequent loads and entity IDs
will be stable from then on.
Duplicate entity IDs should also no longer happen.

Also kill Entity::entityTypeIdx because there's no need to store it.

And yes i do feel bad for nuking that funny comment block :<
2023-05-09 04:49:06 +02:00

118 lines
3.6 KiB
C++

/*
Copyright (C) 2007, 2010 - Bit-Blot
This file is part of Aquaria.
Aquaria is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef SCRIPTEDENTITY_H
#define SCRIPTEDENTITY_H
#include "CollideEntity.h"
#include "Segmented.h"
#include "Particles.h"
#include "Scriptable.h"
struct lua_State;
class Script;
class ScriptedEntity : public CollideEntity, public Segmented, public Scriptable
{
public:
ScriptedEntity(const std::string &scriptName, Vector position, EntityType et = ET_ENEMY);
virtual ~ScriptedEntity();
void init();
void postInit();
void destroy();
void setEntityLayer(int layer);
void setupEntity(const std::string &tex, int layer=0);
void setupBasicEntity(const std::string& texture, int health, int manaBall, int exp, int money, float collideRadius, int state, int w, int h, int expType, bool hitEntity, int updateCull, int layer);
void initSegments(int numSegments, int minDist, int maxDist, std::string bodyTex, std::string tailTex, int w, int h, float taper, bool reverseSegments);
void registerNewPart(RenderObject *r, const std::string &name);
typedef std::map<std::string, RenderObject*> PartMap;
PartMap partMap;
bool surfaceMoveDir;
void activate(Entity *by, int source); // override
void warpSegments();
void lightFlare();
void entityDied(Entity *e);
void message(const std::string &msg, int v);
int callVariadic(const char *func, lua_State *L, int nparams);
int messageVariadic(lua_State *L, int nparams);
int activateVariadic(lua_State *L, int nparams);
static bool runningActivation;
void sporesDropped(const Vector &pos, int type);
bool damage(const DamageData &d);
bool canShotHit(const DamageData &d);
void song(SongType songType);
void startPull();
void stopPull();
void songNote(int note);
void songNoteDone(int note, float len);
void onAnimationKeyPassed(int key);
void initStrands(int num, int segs, int dist, int spacing, Vector color);
typedef std::vector<Strand*> Strands;
Strands strands;
int strandSpacing;
void becomeSolid();
std::string deathParticleEffect;
ParticleEffect pullEmitter;
float manaBallAmount;
void initEmitter(size_t emit, const std::string &file);
void startEmitter(size_t emit);
void stopEmitter(size_t emit);
ParticleEffect *getEmitter(size_t emit);
size_t getNumEmitters() const;
void shiftWorlds(WorldType lastWorld, WorldType worldType);
void setAutoSkeletalUpdate(bool v);
void shotHitEntity(Entity *hit, Shot *shot, Bone *b);
protected:
void onDieNormal();
void onDieEaten();
void luaDebugMsg(const std::string &func, const std::string &msg);
float crushDelay;
int beforePullMaxSpeed;
bool songNoteFunction;
bool songNoteDoneFunction;
std::vector<ParticleEffect*> emitters;
bool becomeSolidDelay;
void onAlwaysUpdate(float dt);
void updateStrands(float dt);
bool animKeyFunc;
void onHitWall();
bool reverseSegments;
void onUpdate(float dt);
void onEnterState(int action);
void onExitState(int action);
virtual void deathNotify(RenderObject *r);
bool canShotHitFunc;
bool postInitDone;
};
#endif